Add package and repository#43
Conversation
|
This is missing unit tests, which I will add soon. |
| } | ||
| if version is not None: | ||
| params['packageVersion'] = version | ||
| if options and type(options) == dict: |
There was a problem hiding this comment.
Would it be better to raise a TypeError on these instead of silently skipping the param if it's not the expected type?
| 'uri': uri, | ||
| 'name': name, | ||
| } | ||
| if index is not None and type(index) == int: |
There was a problem hiding this comment.
Raise a TypeError if it's not an int instead?
| if app_id: | ||
| params['appId'] = app_id | ||
| return self._make_request('install', params, | ||
| {'response_version': '2', }) |
There was a problem hiding this comment.
Trailing comma is valid, although I am not using it well. I will remove it 👍
3e59ebc to
b491970
Compare
|
Rebased. |
falseperfection
left a comment
There was a problem hiding this comment.
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.
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.
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.
+1 abstracting these utilities out
| :return: JSON response | ||
| :rtype: dict | ||
| """ | ||
| params = {} |
There was a problem hiding this comment.
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.
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.
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.
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
mellenburg
left a comment
There was a problem hiding this comment.
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
| return self._post('/list', {}) | ||
|
|
||
|
|
||
| class Repository(Cosmos): |
There was a problem hiding this comment.
You've went and gone full-python now 👍
| monkeypatch.setattr(requests, 'Session', | ||
| lambda *args, **kwargs: mock_session) | ||
|
|
||
| yield mock_session |
There was a problem hiding this comment.
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
packageproperty to DCOS API Session. This returns a newPackageobject that maps directly to the "/package" context.A
repositoryproperty is available on Package that maps to "/package/repository" and provides methods to interact with the repository context.