-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add package and repository #43
base: master
Are you sure you want to change the base?
Conversation
This is missing unit tests, which I will add soon. |
dcos_test_utils/package.py
Outdated
} | ||
if version is not None: | ||
params['packageVersion'] = version | ||
if options and type(options) == dict: |
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.
Would it be better to raise a TypeError
on these instead of silently skipping the param if it's not the expected type?
dcos_test_utils/package.py
Outdated
'uri': uri, | ||
'name': name, | ||
} | ||
if index is not None and type(index) == int: |
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.
Raise a TypeError
if it's not an int
instead?
dcos_test_utils/package.py
Outdated
if app_id: | ||
params['appId'] = app_id | ||
return self._make_request('install', params, | ||
{'response_version': '2', }) |
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.
extra ,
?
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.
Trailing comma is valid, although I am not using it well. I will remove it 👍
3e59ebc
to
b491970
Compare
Rebased. |
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.
So repetitive! Looks good. I had two questions but nothing big.
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 comment
The 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 _make_request
couldn't just return empty when you expected output.
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.
These methods will raise an HTTPError
when a response is not "OK"-like. Because this is talking to an actual cosmos instance, I did not want to assert on content, as that may change or the server under test may have a custom universe installed (package repo).
A lack of raise
is a decent check to ensure the request is valid.
@@ -0,0 +1,69 @@ | |||
from requests import HTTPError |
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.
+1 abstracting these utilities out
dcos_test_utils/package.py
Outdated
:return: JSON response | ||
:rtype: dict | ||
""" | ||
params = {} |
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.
Is a param required? Or can someone do r.delete()
with no params? If required, I'd raise an exception if neither is set like you do above with the int type check.
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.
Not sure - thanks for the question. I need to run some tests.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Verify the delete? Is this a possibility:
- repo.delete(old_name) does nothing because of some error
- repo.add(old_name, old_uri, 0) adds the repo a second time (or it silently skips, IDK the behavior)
- assert says everything went fine because old_name is still there
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.
I will add this.
|
Errors in the latest run of integration tests (on dcos-launch wait) are https://jira.mesosphere.com/browse/QUALITY-2025 which also appeared in #44 which only slowed down a retrying rate, so I think it's a previously introduced bug. |
50f0e91
to
2fff72d
Compare
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.
Great use of python and beautiful docs+testing.
Only change I would make is ensure that debug data is actually dumped in the unit tests
@@ -93,3 +93,222 @@ def list_packages(self): | |||
""" | |||
self._update_headers('list') | |||
return self._post('/list', {}) | |||
|
|||
|
|||
class Repository(Cosmos): |
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 👍
tests/test_package.py
Outdated
monkeypatch.setattr(requests, 'Session', | ||
lambda *args, **kwargs: mock_session) | ||
|
||
yield mock_session |
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.
This should probably be wrapped in a try: finally
block so that we always get the debug cache after an exception is raised
Errors are related to cluster cleanup which is done by dcos-launch, which is outside of this repo |
Add a `package` property to DCOS API Session. This returns a new `Package` object that maps directly to the "/package" context. A `repository` property is available on Package that maps to "/package/repository" and provides methods to interact with the repository context.
Repository was using the wrong "post" method. Integration test for repository was using copy/pasted code that called a nonexistant method on `marathon`.
Move mocks to a helpers file so that both Jobs and Repository tests can use them.
Add more unit tests to verify URL and params. All package requests go through a single method instead of repeating the same code again and again. The default versions for endpoints is now 'v1' instead of 'v2'. The `install` path sets it to 'v2'.
06eb9ee
to
2868438
Compare
Add a
package
property to DCOS API Session. This returns a newPackage
object that maps directly to the "/package" context.A
repository
property is available on Package that maps to "/package/repository" and provides methods to interact with the repository context.