Skip to content

Commit f4f55b0

Browse files
committed
tests: use matchers to mock responses
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 754dcc2 commit f4f55b0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

tests/satosa/micro_services/test_account_linking.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
import pytest
55
import requests
6+
67
import responses
8+
from responses import matchers
9+
710
from jwkest.jwk import rsa_load, RSAKey
811
from jwkest.jws import JWS
912

@@ -46,13 +49,15 @@ def test_existing_account_linking_with_known_known_uuid(self, account_linking_co
4649
}
4750
key = RSAKey(key=rsa_load(account_linking_config["sign_key"]), use="sig", alg="RS256")
4851
jws = JWS(json.dumps(data), alg=key.alg).sign_compact([key])
52+
url = "%s/get_id" % account_linking_config["api_url"]
53+
params = {"jwt": jws}
4954
responses.add(
5055
responses.GET,
51-
"%s/get_id?jwt=%s" % (account_linking_config["api_url"], jws),
52-
status=200,
56+
url=url,
5357
body=uuid,
58+
match=[matchers.query_param_matcher(params)],
5459
content_type="text/html",
55-
match_querystring=True
60+
status=200,
5661
)
5762

5863
self.account_linking.process(context, internal_response)
@@ -82,13 +87,15 @@ def test_full_flow(self, account_linking_config, internal_response, context):
8287
uuid = "uuid"
8388
with responses.RequestsMock() as rsps:
8489
# account is linked, 200 OK
90+
url = "%s/get_id" % account_linking_config["api_url"]
91+
params = {"jwt": jws}
8592
rsps.add(
8693
responses.GET,
87-
"%s/get_id?jwt=%s" % (account_linking_config["api_url"], jws),
88-
status=200,
94+
url=url,
8995
body=uuid,
96+
match=[matchers.query_param_matcher(params)],
9097
content_type="text/html",
91-
match_querystring=True
98+
status=200,
9299
)
93100
internal_response = self.account_linking._handle_al_response(context)
94101
assert internal_response.subject_id == uuid

tests/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pytest
2-
responses
2+
responses >= 0.14
33
beautifulsoup4
44
ldap3
55
mongomock

0 commit comments

Comments
 (0)