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
Use mongo for CI #196
Use mongo for CI #196
Conversation
087683a
to
65f8fc7
Compare
Codecov Report
@@ Coverage Diff @@
## master #196 +/- ##
==========================================
+ Coverage 86.29% 86.43% +0.14%
==========================================
Files 39 39
Lines 1846 1851 +5
==========================================
+ Hits 1593 1600 +7
+ Misses 253 251 -2
Continue to review full report at Codecov.
|
I'm probably not up to date here - why do we need a real mongo DB on CI? |
This is related to the issue found in #173 for |
I should have linked above, the discussion was here: The alternative is skipping the tests that involve |
I think I've convinced myself we should be using a real mongo for the CI anyway, as currently pymongo is not tested at any point in our workflow so we wouldn't catch other potential disagreements between mongomock and pymongo. (you could argue we're now not testing mongomock...) |
Yeah, I think this means we should also consider deploying our index meta-database at Materials Cloud using a real MongoDB, maybe, @ltalirz? But before, we should double-check if a |
The only comment from my side is that we need to be testing the default setup that users of the package will use. |
For the regular server, I would say that it's |
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.
Nice and elegant.
This way we can do both pymongo
and mongomock
tests from the workflow yml
file as I understand it, right?
Also, I have a comment that I would like a response to before approving :)
I agree that the default should be tested, the I don't think mongomock was ever intended to be the "default backend", its meant to be used as a convenience package for, well, testing... see e.g. the description of mongomock:
|
Sure thing. But since the index meta-database should be able to be "hosted" even by static files, I think we can allow the use of |
Absolutely fine, provided we test both, which we are! EDIT: or will be, after this PR ;) |
This is ready to go as far as I'm concerned, feel free to add extra tests with the env var turned off (I'm sure |
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'll just add some testing with mongomock
in the backend as well - probably add in my suggested change below as well, unless you have issues with it or another reason why it should be a broad Exception
?
After all this, my mongomock PR was merged :) I think it still makes sense to test both here, though. |
Great! And yeah, this was a good catch to make sure we test things properly here. |
0b5c353
to
73b51ba
Compare
While we're in the mood for merging, would be good to get a few of these done... |
I just want to add a printing of whether it is using a real mongo or mock mongo db, so that it's clear in the output and for the testing. Edit: Done - all is good. |
854c8bf
to
07bc83d
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.
Thanks for the work on this @ml-evs !
Feel free to merge if you're happy with my final addition and the current state.
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.
@CasperWA: unfortunately if you turn turn on io from py.test, you also get e.g. the tracebacks for tests that test for failure (see latest runs!) which mangle the output. Can we disable this please?
I know - Hmm, how would you otherwise like to confirm that we are indeed using the chosen backend? |
Could potentially emit a warning? Though that will confuse our warnings... Could write to a file at the start of the tests and then cat the file at the end? A bit convoluted... |
Found this stackoverflow page for inspiration. |
Fine by me, do you want to have a go or shall I? |
I can try - since it's my beef :) |
Thinking about it, just writing out to a file could be quite useful, as you can then write a little script that tests that e.g. mongo was used when we expected it to be, that can run just after pytest? Just a thought! |
I am simply importing the client from |
I've also updated our |
Not that I'm aware of.
This seems suitably meta, nice job! |
c7101d8
to
c796fc6
Compare
Expose Mongo ports and pin version
Print what mongo package is being used. Co-Authored-By: Matthew Evans <me388@cam.ac.uk>
4a5e2ae
to
c78cc41
Compare
Test the ci_force_mongo fallback (reverted) Probably due to import caching (or similar) this cannot be properly tested. It is now instead left out of coverage.
c78cc41
to
31fa810
Compare
@ml-evs I cleaned up the commits a bit. Squashed you initial commits, left the combined commit, and squashed my commits into meaningful separate "feature" additions/corrections. I hope this is okay? |
Up to v0.6.0. **New features**: - GitHub Action validator that runs `optimade_validator` for a locally running OPTiMaDe server (#191, @CasperWA, tested by @ml-evs) - Support filter queries for `HAS ALL`, `HAS ANY` and `HAS ONLY` and value lists on MongoDB backends (#173, @ml-evs) Note: `OPERATOR` use in value lists are still _not_ supported. - Debug mode. Start the server in debug mode to enable `debug` log-level in `uvicorn` and get a full Python traceback in the JSON response (#190, @CasperWA) - Add testing of mandatory `filter` queries to `optimade_validator` (#205, @ml-evs) **Updates**: - Allow Cross-Origin requests from anywhere (`*`), i.e., enable CORS for both servers (#194, @CasperWA) - Updates to models (correct misspelling, more transparent model class naming, streamline models with respect to python class inheritance, update field descriptions) (#195, @CasperWA) - API change: Rename `optimade.models.toplevel.py` to `optimade.models.responses.py` (#195, @CasperWA) - Update dependencies to newest versions (as of 02.03.2020) (#202, #196, @CasperWA) - Move imports from `starlette` to `fastapi`, where possible (#202, @ml-evs) - Remove custom middleware to redirect slashed URLs in favor of `starlette` implementation (#202, @ml-evs) - CI tests are now performed with a real MongoDB in the backend. CI tests are also performed with a `mongomock` backend for the tests in `server/test_middleware.py`, `server/test_server_validation.py`, and `server/test_config.py` (#196, @ml-evs, additional testing by @CasperWA ) - Remove `/optimade` from base URLs. This was especially important for the OpenAPI schema (#201, #216, @CasperWA, @ml-evs) - Check integrity of query part of the raw URL using a custom middleware (#209, @CasperWA) - New `optimade/server/exceptions.py` to contain custom `HttpException`s, moved `BadRequest` here (#209, @CasperWA) - Pattern and regex testing for `data.available_api_versions` parts in `/info` endpoint and fix tests for the same (#211, @CasperWA) - Restructure import of test data for regular server (#212, @shyamd) **Bug fixes**: - New retrieval URL for Materials-Consortia's list of providers (#187, @CasperWA) - Skip local `HAS ONLY` tests with a `mongomock` backend, since v3.19.0 does not support these (#206, @ml-evs) - Resource ID's can now contain slashes (`/`) (#183, @ml-evs, @CasperWA) - Remove _valid_ version part of base URL in `meta.query.representation` (#201, @CasperWA)
This PR adds an environment variable that we can use in the CI to force the use of a real mongo with the default settings. It's a bit of a hack, but I think this is the least intrusive way of doing it, otherwise, the way we handle passing the
MongoCollection
s to the routers would have to be changed.Since the tests assume that the mongo is ephemeral, we don't ever want a user running the tests locally with mongo turned on, as it would either a) fail, b) require them to delete any existing "optimade" database.
I have run into this problem a couple of times when trying to reuse as much of the test server as possible, in a perfect world I think we would decouple the structures collection from the router (which only needs to be passed general
EntryCollection
) but I don't think it's worth doing that here.