-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = dist | ||
exclude = dist, tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.tar.gz | ||
.idea | ||
.idea | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[pytest] | ||
minversion = 6.0 | ||
addopts = -ra -q | ||
testpaths = | ||
tests | ||
pythonpath = . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ oauthlib | |
requests-oauthlib | ||
urllib3 | ||
validators | ||
requests | ||
requests | ||
pytest | ||
requests-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
|
||
import pytest | ||
from requests import Response | ||
|
||
from check_b2access import getAccessToken, getLdapName, getInfoCert, getTokenInfo, getUserInfo, getInfoUsernamePassword | ||
import requests_mock | ||
|
||
|
||
class TestProbe: | ||
def test_get_ldap_name(self): | ||
name = getLdapName("Apple/Pineapple/Banana ") | ||
assert name == "Banana,Pineapple" | ||
name = getLdapName("Apple/Pineapple/Banana/Oranges ") | ||
assert name == "Oranges,Banana,Pineapple" | ||
|
||
def test_get_user_info(self): | ||
url = "https://some_url" | ||
token = "token" | ||
|
||
body = json.loads( | ||
"""{ | ||
"sub": "subject", | ||
"unity:persistent": "PersistentID" | ||
} | ||
""" | ||
) | ||
|
||
with requests_mock.Mocker() as m: | ||
m.get(url, json=body, status_code=200) | ||
getUserInfo(url, token, True) | ||
|
||
@pytest.mark.parametrize("status_code, body", [ | ||
[200, '{"sub": "subject"}'], # missing persistent ID | ||
[200, '{"unity:persistent": "PersistentID"}'], # missing subject | ||
[500, '{"sub": "subject", "unity:persistent": "PersistentID"}'] # Server Error | ||
]) | ||
def test_get_user_info_exception(self, status_code, body): | ||
body = json.loads(body) | ||
url = "https://some_url" | ||
token = "token" | ||
|
||
with pytest.raises(SystemExit) as e: | ||
with requests_mock.Mocker() as m: | ||
m.get(url, json=body, status_code=status_code) | ||
getUserInfo(url, token, True) |