def test_save_same_record_twice(self): start = HasherDataModel('hasher1', mother_kennel=self.kennel, hash_name=self.name) start.save() start.save() self.assertTrue(HasherDataModel.record_exists(start))
def test_matching_record_filtering_self(self): hasher = HasherDataModel(self.hasher_id, mother_kennel=self.kennel, hash_name=self.name, user=self.user) hasher.save() self.assertListEqual(HasherDataModel.matching_records(hasher), list())
def test_record_exists(self): hasher = HasherDataModel(self.hasher_id, mother_kennel=self.kennel, hash_name=self.name, user=self.user) hasher.save() self.assertTrue(HasherDataModel.record_exists(hasher))
def test_nullable_fields(self): hasher = HasherDataModel(self.hasher_id, hash_name=self.name, mother_kennel=self.kennel) hasher.save() self.assertIsNone(hasher.contact_info) self.assertIsNone(hasher.real_name) self.assertIsNone(hasher.user)
def test_hash_name_update(self): hasher = HasherDataModel(self.hasher_id, hash_name=self.name, mother_kennel=self.kennel) hasher.save() hasher.add_update_action('hash_name', 'set', 'Different Hash Name') hasher.update() self.assertEqual(hasher.searchable_hash_name, 'differenthashname'.lower())
def test_timestamps(self): time = datetime.now(timezone.utc) with freeze_time(time): hasher = HasherDataModel(self.hasher_id, mother_kennel=self.kennel, hash_name=self.name, user=self.user) hasher.save() self.assertEqual(hasher.modified_at, time) self.assertEqual(hasher.created_at, time)
def test_save_with_no_user_existing_record(self): start = HasherDataModel('hasher1', mother_kennel=self.kennel, hash_name=self.name) start.save() hasher = HasherDataModel('hasher1', mother_kennel=self.kennel, hash_name=self.name, user='******') hasher.save() self.assertTrue(HasherDataModel.record_exists(start)) self.assertTrue(HasherDataModel.record_exists(hasher))
def test_mother_kennel_update(self): kennel2 = { 'kennel_id': 'test_kennel_2', 'name': 'Test Kennel 2', 'acronym': 'TK2H3' } hasher = HasherDataModel(self.hasher_id, hash_name=self.name, mother_kennel=self.kennel) hasher.save() hasher.add_update_action('mother_kennel', 'set', kennel2) hasher.update() self.assertEqual(hasher.searchable_mother_kennel_name, 'testkennel2')
def test_timestamps_on_update(self): new_kennel_name = 'New Kennel 1' start_time = datetime.now(timezone.utc) with freeze_time(start_time): hasher = HasherDataModel(self.hasher_id, mother_kennel=self.kennel, hash_name=self.name, user=self.user) hasher.save() mid_time = datetime.now(timezone.utc) with freeze_time(mid_time): hasher.add_update_action('mother_kennel.name', 'set', new_kennel_name) hasher.update() self.assertEqual(hasher.modified_at, mid_time) self.assertEqual(hasher.created_at, start_time) self.assertEqual(hasher.mother_kennel.name, new_kennel_name)
def test_matching_records_multiple_close_matches(self): HasherDataModel( 'hasher1', mother_kennel=self.kennel, hash_name=self.name, user=self.user, ).save() two = HasherDataModel('hasher2', mother_kennel=self.kennel, hash_name=self.name, user='******') two.save() HasherDataModel('hasher3', mother_kennel=self.kennel, hash_name=self.name, user='******').save() hasher = HasherDataModel('hasher4', mother_kennel=self.kennel, hash_name=self.name, user='******') self.assertListEqual(HasherDataModel.matching_records(hasher), [two])