aboutsummaryrefslogtreecommitdiff
path: root/tests/test_pandora/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pandora/test_models.py')
-rw-r--r--tests/test_pandora/test_models.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index 1310d71..808efa4 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -35,6 +35,23 @@ class TestModelMetaClass(TestCase):
35 self.assertFalse("__field__" in self.TestModel._fields) 35 self.assertFalse("__field__" in self.TestModel._fields)
36 36
37 37
38class TestDateField(TestCase):
39
40 class SampleModel(m.PandoraModel):
41
42 date_field = m.DateField("foo")
43
44 def test_json_to_date(self):
45 expected = datetime(2015, 7, 18, 3, 8, 17)
46 data = {"foo": {"time": 1437188897616}}
47
48 model = self.SampleModel.from_json(None, data)
49
50 # Python2.7 doesn't restore microseconds and we don't care about
51 # it anyhow so just remove it for this test
52 self.assertEqual(expected, model.date_field.replace(microsecond=0))
53
54
38class TestPandoraModel(TestCase): 55class TestPandoraModel(TestCase):
39 56
40 JSON_DATA = { 57 JSON_DATA = {
@@ -66,13 +83,6 @@ class TestPandoraModel(TestCase):
66 def __repr__(self): 83 def __repr__(self):
67 return self._base_repr("Foo") 84 return self._base_repr("Foo")
68 85
69 def test_json_to_date(self):
70 expected = datetime(2015, 7, 18, 3, 8, 17)
71 result = m.PandoraModel.json_to_date(None, {"time": 1437188897616})
72 # Python2.7 doesn't restore microseconds and we don't care about
73 # it anyhow so just remove it for this test
74 self.assertEqual(expected, result.replace(microsecond=0))
75
76 def test_init_sets_defaults(self): 86 def test_init_sets_defaults(self):
77 model = self.TestModel(None) 87 model = self.TestModel(None)
78 self.assertEqual(model.field1, "a string") 88 self.assertEqual(model.field1, "a string")