def testget_hash_no_data(self, stringify_mock): data = "some data" stringified_data = None stringify_mock.return_value = stringified_data generator = LogicalIdGenerator(self.prefix, data_obj=data) self.assertEqual("", generator.get_hash()) stringify_mock.assert_called_once_with(data)
def testget_hash_no_data(self, stringify_mock): data = "some data" stringified_data = None stringify_mock.return_value = stringified_data generator = LogicalIdGenerator(self.prefix, data_obj=data) self.assertEqual("", generator.get_hash()) stringify_mock.assert_called_once_with(data)
def testget_hash(self, stringify_mock): data = "some data" stringified_data = "some stringified data" stringify_mock.return_value = stringified_data generator = LogicalIdGenerator(self.prefix, data_obj=data) # We are essentially duplicating the implementation here. This is done on purpose to prevent # accidental change of the algorithm. Any changes to the hash generation must be backwards compatible. # This test will help catch such issues before hand. expected = hashlib.sha1(bytes(stringified_data)).hexdigest()[:10] self.assertEqual(expected, generator.get_hash()) stringify_mock.assert_called_once_with(data)
def testget_hash(self, stringify_mock): data = "some data" stringified_data = "some stringified data" stringify_mock.return_value = stringified_data generator = LogicalIdGenerator(self.prefix, data_obj=data) # We are essentially duplicating the implementation here. This is done on purpose to prevent # accidental change of the algorithm. Any changes to the hash generation must be backwards compatible. # This test will help catch such issues before hand. utf_data = str(stringified_data).encode("utf8") expected = hashlib.sha1(bytes(utf_data)).hexdigest()[:10] self.assertEqual(expected, generator.get_hash()) stringify_mock.assert_called_once_with(data)