-
Notifications
You must be signed in to change notification settings - Fork 13
Add package and repository #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
cbbbaf0
61cc847
c723819
b97f3aa
015da59
8c961ff
873492f
173a7fa
ca4c8aa
01dd786
f146e2b
0f4e3ff
d86341f
7601663
e1e3dfb
4eac218
e11a0ee
9b5a5ee
bbeb2b6
016771b
9e57929
374892d
c29cf76
2868438
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,3 +93,36 @@ def test_jobs(dcos_api_session): | |
| assert False | ||
| except HTTPError as http_e: | ||
| assert http_e.response.status_code == 404 | ||
|
|
||
|
|
||
| def test_packages(dcos_api_session): | ||
| pack_api = dcos_api_session.package | ||
| install_resp = pack_api.install('hello-world', | ||
| version='2.1.0-0.31.2') | ||
| installed_id = install_resp['appId'] | ||
| dcos_api_session.marathon.wait_for_app_deployment( | ||
| installed_id, 1, True, False, 300) | ||
| packs = pack_api.list() | ||
| found = [p for p in packs['packages'] | ||
| if p['appId'] == installed_id] | ||
| assert found | ||
| pack_api.uninstall('hello-world', app_id=installed_id) | ||
|
|
||
| pack_api.describe('jenkins') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no assert because these methods raise exceptions on failure? Looking through the implementation above it wasn't 100% obvious that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods will raise an A lack of |
||
| pack_api.search('jenk*') | ||
| pack_api.list_versions('jenkins') | ||
|
|
||
|
|
||
| def test_repository(dcos_api_session): | ||
| repo = dcos_api_session.package.repository | ||
|
|
||
| listings = repo.list()['repositories'] | ||
| assert len(listings) > 0 | ||
| old_name, old_uri = listings[0]['name'], listings[0]['uri'] | ||
|
|
||
| repo.delete(old_name) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify the delete? Is this a possibility:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add this. |
||
| listings = repo.list()['repositories'] | ||
| assert [x for x in listings if x['name'] == old_name] == [] | ||
| repo.add(old_name, old_uri, 0) | ||
| listings = repo.list()['repositories'] | ||
| assert [x for x in listings if x['name'] == old_name] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from requests import HTTPError | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 abstracting these utilities out |
||
|
|
||
|
|
||
| class MockResponse: | ||
| def __init__(self, json: dict, status_code: int): | ||
| self._json = json | ||
| self._status_code = status_code | ||
|
|
||
| def json(self): | ||
| return self._json | ||
|
|
||
| def raise_for_status(self): | ||
| """Throw an HTTPErrer based on status code.""" | ||
| if self._status_code >= 400: | ||
| raise HTTPError('Throwing test error', response=self) | ||
|
|
||
| @property | ||
| def status_code(self): | ||
| return self._status_code | ||
|
|
||
| @property | ||
| def text(self): | ||
| return str(self._json) | ||
|
|
||
|
|
||
| class MockEmitter: | ||
| """Emulates a Session and responds with a queued response for each | ||
| request made. If no responses are queued, the request will raise | ||
| an error. | ||
|
|
||
| A history of requests are held in a request cache and can be | ||
| reviewed. | ||
| """ | ||
|
|
||
| def __init__(self, mock_responses: list): | ||
| self._mock_responses = mock_responses | ||
| self._request_cache = list() | ||
|
|
||
| def request(self, *args, **kwargs): | ||
| self._request_cache.append((args, kwargs)) | ||
| return self._mock_responses.pop(0) | ||
|
|
||
| def queue(self, response: list): | ||
| """Add responses to the response queue. | ||
|
|
||
| :param response: A list of responses | ||
| :type response: list | ||
| """ | ||
| self._mock_responses.extend(response) | ||
|
|
||
| @property | ||
| def headers(self): | ||
| return dict() | ||
|
|
||
| @property | ||
| def cookies(self): | ||
| return dict() | ||
|
|
||
| @property | ||
| def debug_cache(self): | ||
| """Return the list of requests made during this session. | ||
|
|
||
| Items in the cache are formatted: | ||
| ((Method, URL), params) | ||
|
|
||
| :return: a list of requests made to this session | ||
| :rtype: list | ||
| """ | ||
| return self._request_cache | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've went and gone full-python now 👍