-
Notifications
You must be signed in to change notification settings - Fork 14
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
10 changed files
with
327 additions
and
204 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
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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
class IIBException(Exception): | ||
""" General IIB exception""" | ||
|
||
pass | ||
|
||
|
||
|
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,86 @@ | ||
from mock import patch, MagicMock, call | ||
|
||
from iiblib.iib_authentication import IIBAuth, IIBBasicAuth, IIBKrbAuth | ||
from iiblib.iib_client import IIBClient | ||
|
||
|
||
def test_client_auth(): | ||
auth = IIBBasicAuth("foo", "bar") | ||
iibc = IIBClient("fake-host", auth=auth) | ||
assert iibc.iib_session.session.headers["auth"] == ("foo", "bar") | ||
|
||
|
||
def test_iib_basic_auth(): | ||
session = MagicMock() | ||
session.session.headers = {} | ||
auth = IIBBasicAuth("foo", "bar") | ||
auth.make_auth(session) | ||
assert session.session.headers["auth"] == ("foo", "bar") | ||
|
||
|
||
@patch("subprocess.Popen") | ||
@patch("kerberos.authGSSClientStep") | ||
@patch("kerberos.authGSSClientResponse") | ||
@patch("kerberos.authGSSClientInit") | ||
def test_iib_krb_auth( | ||
mocked_auth_gss_client_init, | ||
mocked_auth_gss_client_response, | ||
mocked_auth_gss_client_step, | ||
mocked_popen, | ||
): | ||
mocked_auth_gss_client_init.return_value = ("", None) | ||
mocked_auth_gss_client_response.return_value = "" | ||
session = MagicMock() | ||
session.session.headers = {} | ||
auth = IIBKrbAuth("test_principal", "someservice") | ||
auth.make_auth(session) | ||
mocked_auth_gss_client_init.assert_called_with("HTTP@someservice") | ||
mocked_popen.assert_has_calls([call(["klist"], stderr=-1, stdout=-1)]) | ||
|
||
auth = IIBKrbAuth("test_principal", "someservice", ktfile="/some/kt/file") | ||
auth.make_auth(session) | ||
mocked_auth_gss_client_init.assert_called_with("HTTP@someservice") | ||
|
||
|
||
@patch("os.unlink") | ||
@patch("tempfile.mkstemp") | ||
@patch("subprocess.Popen.wait") | ||
@patch("subprocess.Popen") | ||
@patch("kerberos.authGSSClientStep") | ||
@patch("kerberos.authGSSClientResponse") | ||
@patch("kerberos.authGSSClientInit") | ||
def test_iib_krb_auth_no_keytab( | ||
mocked_auth_gss_client_init, | ||
mocked_auth_gss_client_response, | ||
mocked_auth_gss_client_step, | ||
mocked_popen, | ||
mocked_popen_wait, | ||
mocked_mkstemp, | ||
mocked_os_unlink, | ||
): | ||
mocked_mkstemp.return_value = (None, "/tmp/krb5ccomuHss") | ||
mocked_popen_wait.side_effect = [1, 0] | ||
mocked_auth_gss_client_init.return_value = ("", None) | ||
mocked_auth_gss_client_response.return_value = "" | ||
session = MagicMock() | ||
session.session.headers = {} | ||
auth = IIBKrbAuth("test_principal", "someservice") | ||
auth.make_auth(session) | ||
mocked_auth_gss_client_init.assert_called_with("HTTP@someservice") | ||
mocked_popen.assert_has_calls( | ||
[ | ||
call( | ||
["kinit", "test_principal", "-k", "-c", "/tmp/krb5ccomuHss"], | ||
stderr=-1, | ||
stdout=-1, | ||
) | ||
] | ||
) | ||
|
||
|
||
def test_iibauth_abstract(): | ||
try: | ||
IIBAuth() | ||
raise AssertionError("Should raise NotImplementedError") | ||
except NotImplementedError: | ||
pass |
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,72 @@ | ||
import pytest | ||
|
||
from iiblib.iib_build_details_model import IIBBuildDetailsModel | ||
|
||
|
||
@pytest.fixture | ||
def fixture_build_details_json(): | ||
json = { | ||
"id": 1, | ||
"state": "in_progress", | ||
"state_reason": "state_reason", | ||
"state_history": [], | ||
"from_index": "from_index", | ||
"from_index_resolved": "from_index_resolved", | ||
"bundles": ["bundles1"], | ||
"removed_operators": ["operator1"], | ||
"organization": "organization", | ||
"binary_image": "binary_image", | ||
"binary_image_resolved": "binary_image_resolved", | ||
"index_image": "index_image", | ||
"request_type": "request_type", | ||
"arches": ["x86_64"], | ||
"bundle_mapping": {"bundle_mapping": "map"}, | ||
"omps_operator_version": {"operator": "1.0"}, | ||
} | ||
return json | ||
|
||
|
||
def test_iibbuilddetailsmodel(fixture_build_details_json): | ||
unexpected_model = IIBBuildDetailsModel( | ||
1, | ||
"finished", | ||
"state_reason", | ||
[], | ||
"from_index", | ||
"from_index_resolved", | ||
["bundles1"], | ||
["operator1"], | ||
"organization", | ||
"binary_image", | ||
"binary_image_resolved", | ||
"index_image", | ||
"request_type", | ||
["x86_64"], | ||
{"bundle_mapping": "map"}, | ||
{"operator": "1.0"}, | ||
) | ||
expected_model = IIBBuildDetailsModel( | ||
1, | ||
"in_progress", | ||
"state_reason", | ||
[], | ||
"from_index", | ||
"from_index_resolved", | ||
["bundles1"], | ||
["operator1"], | ||
"organization", | ||
"binary_image", | ||
"binary_image_resolved", | ||
"index_image", | ||
"request_type", | ||
["x86_64"], | ||
{"bundle_mapping": "map"}, | ||
{"operator": "1.0"}, | ||
) | ||
model = IIBBuildDetailsModel.from_dict(fixture_build_details_json) | ||
assert model == expected_model | ||
assert model != unexpected_model | ||
|
||
model = IIBBuildDetailsModel.from_dict(fixture_build_details_json).to_dict() | ||
assert model == expected_model.to_dict() | ||
assert model != unexpected_model.to_dict() |
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,126 @@ | ||
import pytest | ||
import requests_mock | ||
|
||
|
||
from iiblib.iib_build_details_model import IIBBuildDetailsModel | ||
from iiblib.iib_client import IIBClient | ||
|
||
|
||
@pytest.fixture | ||
def fixture_build_details_json(): | ||
json = { | ||
"id": 1, | ||
"state": "in_progress", | ||
"state_reason": "state_reason", | ||
"state_history": [], | ||
"from_index": "from_index", | ||
"from_index_resolved": "from_index_resolved", | ||
"bundles": ["bundles1"], | ||
"removed_operators": ["operator1"], | ||
"organization": "organization", | ||
"binary_image": "binary_image", | ||
"binary_image_resolved": "binary_image_resolved", | ||
"index_image": "index_image", | ||
"request_type": "request_type", | ||
"arches": ["x86_64"], | ||
"bundle_mapping": {"bundle_mapping": "map"}, | ||
"omps_operator_version": {"operator": "1.0"}, | ||
} | ||
return json | ||
|
||
|
||
@pytest.fixture | ||
def fixture_build_details_json2(): | ||
json = { | ||
"id": 2, | ||
"state": "in_progress", | ||
"state_reason": "state_reason", | ||
"state_history": [], | ||
"from_index": "from_index", | ||
"from_index_resolved": "from_index_resolved", | ||
"bundles": ["bundles1"], | ||
"removed_operators": ["operator1"], | ||
"organization": "organization", | ||
"binary_image": "binary_image", | ||
"binary_image_resolved": "binary_image_resolved", | ||
"index_image": "index_image", | ||
"request_type": "request_type", | ||
"arches": ["x86_64"], | ||
"bundle_mapping": {"bundle_mapping": "map"}, | ||
"omps_operator_version": {"operator": "1.0"}, | ||
} | ||
return json | ||
|
||
|
||
@pytest.fixture | ||
def fixture_builds_page1_json(fixture_build_details_json): | ||
json = { | ||
"items": [fixture_build_details_json], | ||
"meta": { | ||
"first": "", | ||
"last": "", | ||
"next": "", | ||
"page": 1, | ||
"pages": 2, | ||
"per_page": 1, | ||
"previous": "", | ||
"total": 2, | ||
}, | ||
} | ||
return json | ||
|
||
|
||
@pytest.fixture | ||
def fixture_builds_page2_json(fixture_build_details_json2): | ||
json = { | ||
"items": [fixture_build_details_json2], | ||
"meta": { | ||
"first": "", | ||
"last": "", | ||
"next": "", | ||
"page": 2, | ||
"pages": 2, | ||
"per_page": 1, | ||
"previous": "", | ||
"total": 2, | ||
}, | ||
} | ||
return json | ||
|
||
|
||
def test_iibbuilddetails_pager( | ||
fixture_builds_page1_json, | ||
fixture_builds_page2_json, | ||
fixture_build_details_json, | ||
fixture_build_details_json2, | ||
): | ||
with requests_mock.Mocker() as m: | ||
m.register_uri( | ||
"GET", "/api/v1/builds", status_code=200, json=fixture_builds_page1_json | ||
) | ||
m.register_uri( | ||
"GET", | ||
"/api/v1/builds?page=2", | ||
status_code=200, | ||
json=fixture_builds_page2_json, | ||
) | ||
m.register_uri( | ||
"GET", | ||
"/api/v1/builds?page=1", | ||
status_code=200, | ||
json=fixture_builds_page1_json, | ||
) | ||
|
||
iibc = IIBClient("fake-host") | ||
pager = iibc.get_builds() | ||
assert pager.items() == [ | ||
IIBBuildDetailsModel.from_dict(fixture_builds_page1_json["items"][0]) | ||
] | ||
pager.next() | ||
assert pager.items() == [ | ||
IIBBuildDetailsModel.from_dict(fixture_builds_page2_json["items"][0]) | ||
] | ||
pager.prev() | ||
assert pager.items() == [ | ||
IIBBuildDetailsModel.from_dict(fixture_builds_page1_json["items"][0]) | ||
] |
Oops, something went wrong.