Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bachmann1234/b195594041b296b44d32 to your computer and use it in GitHub Desktop.
Save Bachmann1234/b195594041b296b44d32 to your computer and use it in GitHub Desktop.
Historical Event Unit Test
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