-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_401_errors.py
More file actions
34 lines (28 loc) · 1.17 KB
/
test_401_errors.py
File metadata and controls
34 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import pytest
from lib.constants import METHODS, VALID_ENDPOINT_LETTERS
from lib.fixtures import *
from lib.errorhandler import ErrorHandler
@pytest.mark.test
@pytest.mark.devtest
@pytest.mark.inttest
@pytest.mark.prodtest
@pytest.mark.parametrize("method", METHODS)
@pytest.mark.parametrize("endpoints", VALID_ENDPOINT_LETTERS)
def test_401_invalid(url, method, endpoints):
resp = getattr(requests, method)(f"{url}{endpoints}", headers={
"Authorization": "invalid",
})
ErrorHandler.handle_retry(resp)
assert resp.status_code == 401, f"Response: {resp.status_code}: {resp.text}"
@pytest.mark.test
@pytest.mark.nhsd_apim_authorization({"access": "application", "level": "level0"})
@pytest.mark.parametrize("method", METHODS)
@pytest.mark.parametrize("endpoints", VALID_ENDPOINT_LETTERS)
def test_401_invalid_level(nhsd_apim_proxy_url, nhsd_apim_auth_headers, method, endpoints):
print(nhsd_apim_proxy_url)
resp = getattr(requests, method)(f"{nhsd_apim_proxy_url}{endpoints}", headers={
**nhsd_apim_auth_headers
})
ErrorHandler.handle_retry(resp)
assert resp.status_code == 401, f"Response: {resp.status_code}: {resp.text}"