|
| 1 | +import unittest |
| 2 | +import os |
| 3 | +import httpx |
| 4 | +from mauth_client.httpx_mauth import MAuthHttpx |
| 5 | + |
| 6 | +APP_UUID = "5ff4257e-9c16-11e0-b048-0026bbfffe5e" |
| 7 | +URL = "https://innovate.imedidata.com/api/v2/users/10ac3b0e-9fe2-11df-a531-12313900d531/studies.json" |
| 8 | + |
| 9 | + |
| 10 | +def handler(request): |
| 11 | + return httpx.Response(200, json={"text": "Hello, world!"}) |
| 12 | + |
| 13 | + |
| 14 | +class MAuthHttpxBaseTest(unittest.TestCase): |
| 15 | + def setUp(self): |
| 16 | + with open(os.path.join(os.path.dirname(__file__), "..", "keys", "fake_mauth.priv.key"), "r") as key_file: |
| 17 | + self.example_private_key = key_file.read() |
| 18 | + |
| 19 | + def test_call(self): |
| 20 | + auth = MAuthHttpx(APP_UUID, self.example_private_key, sign_versions="v1,v2") |
| 21 | + with httpx.Client(transport=httpx.MockTransport(handler), auth=auth) as client: |
| 22 | + response = client.get(URL) |
| 23 | + |
| 24 | + for header in ["mcc-authentication", "mcc-time", "x-mws-authentication", "x-mws-time"]: |
| 25 | + self.assertIn(header, response.request.headers) |
| 26 | + |
| 27 | + def test_call_v1_only(self): |
| 28 | + auth = MAuthHttpx(APP_UUID, self.example_private_key) |
| 29 | + with httpx.Client(transport=httpx.MockTransport(handler), auth=auth) as client: |
| 30 | + response = client.get(URL) |
| 31 | + |
| 32 | + for header in ["x-mws-authentication", "x-mws-time"]: |
| 33 | + self.assertIn(header, response.request.headers) |
| 34 | + |
| 35 | + def test_call_v2_only(self): |
| 36 | + auth = MAuthHttpx(APP_UUID, self.example_private_key, sign_versions="v2") |
| 37 | + with httpx.Client(transport=httpx.MockTransport(handler), auth=auth) as client: |
| 38 | + response = client.get(URL) |
| 39 | + |
| 40 | + for header in ["mcc-authentication", "mcc-time"]: |
| 41 | + self.assertIn(header, response.request.headers) |
0 commit comments