Conversation
| from runbook import config | ||
|
|
||
|
|
||
| def check_regions(func): |
There was a problem hiding this comment.
I think that we should move this over time to oss-lib
runbook/api/v1/runbook_.py
Outdated
| # should not really be here | ||
| return flask.jsonify({"error": "Was unable to save document"}), 500 | ||
| else: | ||
| result = es.search(index="ms_runbooks_region_one", doc_type="runbook") |
There was a problem hiding this comment.
so I don't understand why index is hardcoded here
runbook/api/v1/runbook_.py
Outdated
| elif flask.request.method == "DELETE": | ||
| try: | ||
| es.delete( | ||
| index="ms_runbooks_region_one", |
| except elasticsearch.NotFoundError: | ||
| flask.abort(404) | ||
|
|
||
| elif flask.request.method == "PUT": |
There was a problem hiding this comment.
probably it makes sense to move code related PUT, POST, GET to helpers so it will be way simpler to write unittests
There was a problem hiding this comment.
we can use smth like flask-restfull if this becomes a problem. However since we're splitting API into ro/wo the functions would get simpler.
tests/unit/api/v1/base.py
Outdated
| "regions": [ | ||
| "region_one", | ||
| "region_two" | ||
| ], |
| self.addCleanup(mock.patch.stopall) | ||
|
|
||
| # NOTE(kzaitsev): mock all get_config for a ll the tests | ||
| self.patcher = mock.patch('runbook.config.get_config') |
There was a problem hiding this comment.
can we mock config in place othewise it's really hard for newbies to understand where it is mocked?
| self.get_config = self.patcher.start() | ||
| self.get_config.return_value = TEST_CONFIG | ||
|
|
||
| # NOTE(kzaitsev): importing this module calls get_config, so I'm |
There was a problem hiding this comment.
Module should not import config.
We should not have any long running operations (like reading files) during the module imports
There was a problem hiding this comment.
this is not the case for all our projects currently — main.py calls get_config at module level. should be trivial to change that though
It is now possible to create, update and delete runbooks in elasticsearch. Input validation is done with jsonschema.
Also fix result conversion, from always returning the same runbook
No description provided.