Skip to content

Commit 39cb1c7

Browse files
committed
Renamint generic assignment test to auto coercion, #98
1 parent ca10e5a commit 39cb1c7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import unittest
2+
import io
3+
from os.path import join, exists
4+
5+
from sqlalchemy import Column, Integer
6+
7+
from sqlalchemy_media.attachments import File
8+
from sqlalchemy_media.stores import StoreManager
9+
from sqlalchemy_media.tests.helpers import Json, TempStoreTestCase
10+
11+
12+
class AutoCoerceFile(File):
13+
__auto_coercion__ = True
14+
15+
16+
class AutoCoercionTestCase(TempStoreTestCase):
17+
18+
def test_file_assignment(self):
19+
20+
class Person(self.Base):
21+
__tablename__ = 'person'
22+
id = Column(Integer, primary_key=True)
23+
cv = Column(AutoCoerceFile.as_mutable(Json))
24+
25+
session = self.create_all_and_get_session()
26+
person1 = Person()
27+
resume = io.BytesIO(b'This is my resume')
28+
with StoreManager(session):
29+
person1.cv = resume
30+
self.assertIsNone(person1.cv.content_type)
31+
self.assertIsNone(person1.cv.extension)
32+
self.assertTrue(exists(join(self.temp_path, person1.cv.path)))
33+
34+
person1.cv = resume, 'text/plain'
35+
self.assertEqual(person1.cv.content_type, 'text/plain')
36+
self.assertEqual(person1.cv.extension, '.txt')
37+
self.assertTrue(exists(join(self.temp_path, person1.cv.path)))
38+
39+
person1.cv = resume, 'text/plain', 'myfile.note'
40+
self.assertEqual(person1.cv.content_type, 'text/plain')
41+
self.assertEqual(person1.cv.extension, '.note')
42+
self.assertTrue(exists(join(self.temp_path, person1.cv.path)))
43+
44+
45+
46+
if __name__ == '__main__': # pragma: no cover
47+
unittest.main()
48+

0 commit comments

Comments
 (0)