Beispiel #1
0
class TestEntify(unittest.TestCase):

    def setUp(self):
        self.db = setup_test()
        self.db.autocommit(1)
        self.people = EntityStore(self.db, Person)
        self.joe_id = self.people.put(Person(name='Joe', age=50))
        self.sam_id = self.people.put(Person(name='Sam', age=25))
        self.people.put(Person(name='Ann', age=30))
        self.id_name = '_id'

    def tearDown(self):
        self.people.zap()
        self.db.close()

    def test_attribute(self, value='text'):
        joe = self.people.first(name='Joe')
        assert joe
        joe.entify_test_attribute = value
        joe.save()
        joe = self.people.first(name='Joe')
        self.assertEqual(joe.entify_test_attribute, value)

    def test_text(self):
        self.test_attribute('text value')

    def test_int(self):
        self.test_attribute(10)

    def test_float(self):
        self.test_attribute(1.2)

    def test_decimal(self):
        self.test_attribute(Decimal("1.20"))

    def test_date(self):
        self.test_attribute(date(2017, 12, 1))

    def test_datetime(self):
        self.test_attribute(datetime(2017, 12, 1, 1, 25, 3))

    def test_bool(self):
        self.test_attribute(True)

    def test_bool_false(self):
        self.test_attribute(False)

    def test_none(self):
        self.test_attribute(None)

    def test_list(self):
        self.test_attribute([1, 2, 3, 4])

    def test_tuple(self):
        self.test_attribute((1, 2, 3, 4))

    def test_bytes(self):
        self.test_attribute(b'this is binary')