From 8409b9cf6d14773a95c403acea28555235d39cf6 Mon Sep 17 00:00:00 2001 From: Yurii Rabeshko Date: Sat, 13 Jan 2018 06:26:58 +0200 Subject: [PATCH] Make some tests that cover the model class --- tests/unit/row2dict.py | 0 tests/unit/test_model.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) delete mode 100644 tests/unit/row2dict.py create mode 100644 tests/unit/test_model.py diff --git a/tests/unit/row2dict.py b/tests/unit/row2dict.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py new file mode 100644 index 0000000..0e0d20c --- /dev/null +++ b/tests/unit/test_model.py @@ -0,0 +1,28 @@ +import types +from tests.schema import User +from tests.test import TestCase + + +class ModelTest(TestCase): + def test_as_dict(self): + user_dict = self.user.as_dict() + self.assertIsInstance(user_dict, dict) + self.assertDictEqual(user_dict, { + 'id': 1, + 'username': 'yarbshk', + 'password': 'x', + '_secret': 'x', + 'role': None, + 'role_id': 1 + }) + + def test_from_dict(self): + user_dict = self.user.as_dict() + user_row = User.from_dict(user_dict) + self.assertIsInstance(user_row, User) + self.assertEqual(user_row.username, self.user.username) + self.assertEqual(user_row.password, self.user.password) + + def test_iter(self): + iterator = getattr(self.user, '__iter__')() + self.assertIsInstance(iterator, types.GeneratorType)