Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine identical test functions using pytest.mark.parametrize() #574

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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