Last active
August 29, 2015 14:23
-
-
Save Bachmann1234/b195594041b296b44d32 to your computer and use it in GitHub Desktop.
Historical Event Unit Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestEvent(unittest.TestCase): | |
name = "Invention of the telegraph" | |
event_id = 1 | |
description = "Samuel Morse patents his telegraph" | |
event_time = datetime(1840, month=6, day=20) | |
event_object = HistoricalEvent( | |
event_id, | |
name, | |
description, | |
event_time | |
) | |
event_json = ( | |
'{{"description": "{}",' | |
' "event_id": {}, ' | |
'"event_time": "{}", ' | |
'"name": "{}"}}'.format( | |
description, | |
event_id, | |
event_time.isoformat(), | |
name | |
) | |
) | |
def test_user_serialization(self): | |
self.assertEquals( | |
json.dumps(self.event_object, cls=EventEncoder, sort_keys=True), | |
self.event_json | |
) | |
def test_user_deserialization(self): | |
self.assertEquals( | |
self.event_object, | |
json.loads(self.event_json, object_hook=HistoricalEvent.fromJson) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment