def test_all_supported(self): for algo_name, (enabled, (fun_name, fun_args, fun_kwargs)) in hashes._HASH_ALGO_MAPPING: if not enabled: self.assertFalse(hashes.is_algo_supported(algo_name)) else: with unittest.mock.patch("hashlib.{}".format(fun_name), create=True) as hash_impl: self.assertTrue(hashes.is_algo_supported(algo_name)) hash_impl.assert_not_called()
def test_return_false_if_function_not_implemented(self): try: _sha3_256 = hashlib.sha3_256 except AttributeError: self.assertFalse(hashes.is_algo_supported("sha3-256")) return self.assertTrue(hashes.is_algo_supported("sha3-256")) del hashlib.sha3_256 try: self.assertFalse(hashes.is_algo_supported("sha3-256")) finally: hashlib.sha3_256 = _sha3_256
def test_all_supported(self): for algo_name, (enabled, (fun_name, fun_args, fun_kwargs)) in hashes._HASH_ALGO_MAPPING: if not enabled: self.assertFalse( hashes.is_algo_supported(algo_name) ) else: with unittest.mock.patch( "hashlib.{}".format(fun_name), create=True) as hash_impl: self.assertTrue(hashes.is_algo_supported(algo_name)) hash_impl.assert_not_called()
def test_return_false_if_function_not_defined(self): self.assertFalse(hashes.is_algo_supported("foobar"))
def test_return_false_for_MUST_NOT_hashes(self): self.assertFalse(hashes.is_algo_supported("md2")) self.assertFalse(hashes.is_algo_supported("md4")) self.assertFalse(hashes.is_algo_supported("md5"))