class EventReferenceModelTests(unittest.TestCase): def setUp(self): self.event_id = 'test_id' self.hares = [HasherReferenceModel(hasher_id='hare_1', hash_name='Harry One'), HasherReferenceModel(hasher_id='hare_2', hash_name='Harry Two')] self.name = 'test event' self.description = 'An event to test dynamodb persistence' self.kennels = [KennelReferenceModel(kennel_id='kennel_1', name='One HHH', acronym='1H3')] self.type = 'basic' self.start_time = datetime.now(tz=timezone.utc) self.end_time = self.start_time self.start_location = 'location1' self.trails = ['trail1'] self.event = EventDataModel(self.event_id, hares=self.hares, name=self.name, description=self.description, kennels=self.kennels, type=self.type, start_time=self.start_time, end_time=self.end_time, start_location=self.start_location, trails=self.trails) self.event.save() @classmethod def setUpClass(cls): EventDataModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True) @classmethod def tearDownClass(cls): if EventDataModel.exists(): EventDataModel.delete_table() def tearDown(self): if self.event.exists(): self.event.delete() def test_create_event_ref(self): ref = self.event.to_ref() self.assertTrue(hasattr(ref, 'event_id')) self.assertTrue(hasattr(ref, 'hares')) self.assertTrue(hasattr(ref, 'name')) self.assertTrue(hasattr(ref, 'description')) self.assertTrue(hasattr(ref, 'kennels')) self.assertTrue(hasattr(ref, 'start_time')) self.assertTrue(hasattr(ref, 'start_location')) def test_is_ref_of(self): ref = self.event.to_ref() self.assertTrue(ref.is_ref_of(self.event))
class EventTests(unittest.TestCase): def setUp(self): self.event_id = 'test_id' self.hares = [HasherReferenceModel(hasher_id='hare_1', hash_name='Harry One'), HasherReferenceModel(hasher_id='hare_2', hash_name='Harry Two')] self.name = 'test event' self.description = 'An event to test dynamodb persistence' self.kennels = [KennelReferenceModel(kennel_id='kennel_1', name='One HHH', acronym='1H3')] self.type = 'basic' self.start_time = datetime.now(tz=timezone.utc) self.end_time = self.start_time self.start_location = 'location1' self.trails = ['trail1'] self.event = EventDataModel(self.event_id, hares=self.hares, name=self.name, description=self.description, kennels=self.kennels, type=self.type, start_time=self.start_time, end_time=self.end_time, start_location=self.start_location, trails=self.trails) self.event.save() @classmethod def setUpClass(cls): EventDataModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True) @classmethod def tearDownClass(cls): if EventDataModel.exists(): EventDataModel.delete_table() def tearDown(self): if self.event.exists(): self.event.delete() def test_create_and_retrieve(self): self.assertTrue(self.event.exists()) retrieved_obj = EventDataModel.get(self.event_id, self.start_time) self.event.refresh() self.assertEqual(retrieved_obj, self.event) def test_update(self): new_type = 'different type' self.event.add_update_action('type', 'set', new_type) self.event.update() self.event.refresh() retrieved_obj = EventDataModel.get(self.event_id, self.start_time) self.assertEqual(retrieved_obj, self.event) self.assertEqual(retrieved_obj.type, new_type) def test_delete(self): self.assertTrue(self.event.exists()) self.event.delete() with self.assertRaises(EventDataModel.DoesNotExist): EventDataModel.get(self.event_id, self.start_time) def test_timestamps(self): time = datetime.now(timezone.utc) with freeze_time(time): event = EventDataModel(self.event_id, hares=self.hares, name=self.name, description=self.description, kennels=self.kennels, type=self.type, start_time=self.start_time, end_time=self.end_time, start_location=self.start_location, trails=self.trails) event.save() self.assertEqual(event.modified_at, time) self.assertEqual(event.created_at, time) def test_to_ref(self): time = datetime.now(timezone.utc) with freeze_time(time): event = EventDataModel(self.event_id, hares=self.hares, name=self.name, description=self.description, kennels=self.kennels, type=self.type, start_time=self.start_time, end_time=self.end_time, start_location=self.start_location, trails=self.trails) event.save() ref = event.to_ref() self.assertEqual(ref.event_id, self.event_id) self.assertListEqual(ref.hares, self.hares) self.assertEqual(ref.description, self.description) self.assertListEqual(ref.kennels, self.kennels) self.assertEqual(ref.start_time, self.start_time) self.assertEqual(ref.start_location, self.start_location)