Skip to content

Commit

Permalink
Combine identical test functions using pytest.mark.parametrize() (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdufresne committed Dec 21, 2020
1 parent f490a60 commit 06523a0
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,21 @@ def test_hmac_should_accept_unicode_key(self):

algo.prepare_key("awesome")

def test_hmac_should_throw_exception_if_key_is_pem_public_key(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path("testkey2_rsa.pub.pem")) as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_should_throw_exception_if_key_is_x509_certificate(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path("testkey_rsa.cer")) as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_should_throw_exception_if_key_is_ssh_public_key(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path("testkey_rsa.pub")) as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_should_throw_exception_if_key_is_x509_cert(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path("testkey2_rsa.pub.pem")) as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_should_throw_exception_if_key_is_pkcs1_pem_public(self):
@pytest.mark.parametrize(
"key",
[
"testkey2_rsa.pub.pem",
"testkey2_rsa.pub.pem",
"testkey_pkcs1.pub.pem",
"testkey_rsa.cer",
"testkey_rsa.pub",
],
)
def test_hmac_should_throw_exception(self, key):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path("testkey_pkcs1.pub.pem")) as keyfile:
with open(key_path(key)) as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_jwk_should_parse_and_verify(self):
Expand Down

0 comments on commit 06523a0

Please sign in to comment.