Skip to content
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 more tests (based on optimade-python-tools) #74

Merged
merged 6 commits into from
Jun 2, 2020

Conversation

CasperWA
Copy link
Collaborator

@CasperWA CasperWA commented May 4, 2020

Implement more tests, based on the tests in optimade-python-tools.

Convert from unittest to using pytest instead.

There are still some optimizations that can be done in this new code:

  • Collect similar test functions (and possibly classes) in a smaller number of test functions (and classes) using pytest's parameterization features.
  • Consider in which cases it's best to use utility functions or pytest fixtures.
  • Update middleware tests when Redirect special OpenAPI endpoints for custom base URLs #72 has been merged.
    Done.

@CasperWA CasperWA marked this pull request as draft May 4, 2020 16:56
@codecov
Copy link

codecov bot commented May 4, 2020

Codecov Report

Merging #74 into develop will increase coverage by 3.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #74      +/-   ##
===========================================
+ Coverage    69.75%   72.89%   +3.13%     
===========================================
  Files           16       16              
  Lines          830      819      -11     
===========================================
+ Hits           579      597      +18     
+ Misses         251      222      -29     
Flag Coverage Δ
#pytest 72.89% <100.00%> (?)
#unittests ?
Impacted Files Coverage Δ
aiida_optimade/main.py 100.00% <100.00%> (ø)
aiida_optimade/transformers/aiida.py 96.80% <100.00%> (+11.90%) ⬆️
aiida_optimade/entry_collections.py 88.39% <0.00%> (+7.18%) ⬆️
aiida_optimade/middleware.py 100.00% <0.00%> (+17.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aba30d9...0f987dc. Read the comment docs.

These are all based on the tests in optimade-python-tools.

Removed several test files that are not relevant for aiida-optimade.
Updated transformer tests to be applicable with AiidaTransformer.
Added an update of package version to invoke task for
/tests/test_config.json.
Rename test classes to be discoverable

Fix some structures tests.
@CasperWA CasperWA marked this pull request as ready for review June 2, 2020 16:23
Subclass FastAPI/Starlette's `TestClient` in order to prepend path
requests with the version path.
This is done, since the `TestClient` otherwise uses
`urllib.parse.urljoin` to combine the custom `base_url` attribute with
the requested path URI. In doing this, any paths included in the
`base_url` will be removed and only the requested path URI will remaing,
using the scheme and netloc of `base_url`.
So this is a way of injecting the OPTIMADE versioned base URL into the
requests.

A precaution is taken to not override requested complete URLs by
checking for a scheme after using `urllib.parse.urlparse` on the
requested URL.

Furthermore, the client is wrapped in a factory function in order to
create a client with a specific versioned base URL.
If no version is passed to the factory function, the current OPTIMADE
API version's major part it used (the mandatory versioned base URL).
Run through the differently versioned base URL servers and make sure all
Open API endpoints are redirected to the major versioned base URL.
@CasperWA CasperWA changed the title [WIP] Add more tests (based on optimade-python-tools) Add more tests (based on optimade-python-tools) Jun 2, 2020
@CasperWA CasperWA merged commit 51cb36b into aiidateam:develop Jun 2, 2020
@CasperWA CasperWA deleted the add_more_tests branch June 2, 2020 22:33
This was referenced Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant