-
Notifications
You must be signed in to change notification settings - Fork 9
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 unit tests and new functional tests #64
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By moving application creation into the create_app() method, we are able to isolate application instantiation from the import of the wsgi module. This is going to be necessary for writing unit tests, because we will often want to mock out some top-level objects that can only be modified after the module has been imported. The pattern used in this PR is called an "application factory", and is explained in more detail in [1]. [1]: https://flask.palletsprojects.com/en/2.0.x/patterns/appfactories/
Instead of creating a new MocOpenShfit4x instance in each handler function, just create one when we start up the app. This allows us to drop the MocOpenShiftSingleton wrapper. x-branch: feature/application-factory
Moves all the logic for communicating with the Kubernetes API into the kubeclient module. This replaces the get_request, del_request, put_request, and post_request methods of MocOpenShift with calls to the session object, which takes care of things like setting the appropriate headers. This also enables SSL certificate validation by default when run in Kubernetes.
As we add additional files to the project it becomes inconvenient to constantly modify the Dockerfile to include them. This updates the Dockerfile to copy everything in the current directory, and adds a .dockerignore file to prevent things that change regularly (like the .git directory) from invalidating the cache. NB: when building locally this will pick up anything in the current working directory. This isn't an issue when building in CI or via the automatic build features of quay.io or docker hub.
Use the config attribute of the flask app to aggregate configuration from defaults, explicitly provided parameters, and the environment. This provides a consistent mechanism for accessing values, and makes it easier to pass in explicit config information when writing tests.
This adds an AUTH_DISABLED configuration item to the flask app which allows us to disable authentication. We can use this during development to make it easier to test the service, and we can use it during testing to create a test client that doesn't require authentication with every call.
By using a configmapGenerator [1] to generate the quota ConfigMap, we can store the example data itself as a plain JSON file, which makes it available to the code when running things locally. [1]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/#configmapgenerator
Using `sleep` as a synchronization mechanism is problematic -- it can both introduce unnecessary delays and result in unexpected problems if an operation takes longer than expected. This commit replaces the use of `sleep` with explicit polling.
Move all the account management code into the acct_mgt package. Putting the code into a single namespace like this makes it easier to write modular code, keeps the top-level directory organized, and makes testing simpler. x-branch: feature/prepare-for-tests
This introduces a new suite of functional tests. The tests are moved into the `tests/functional` directory, which will allow us in subsequent commits to place unit tests in `tests/unit`.
This adds a suite of unit tests for the flask application and modifies the CI workflow to run unit tests in addition to the pre-commit checks.
Several tests are marked with @pytest.mark.xfail() to indicate places where the existing API may be problematic. For each of these tests, we need to determine if the existing behavior is correct, and if it is, modify the test so that it tests the current behavior and passes.
Add a GitHub workflow to run unit tests for each push and pull-request.
- Add pytest-coverage to test-requirements.txt, which allows us to produce coverage reports. - Update the CI workflow to include coverage reporting, which looks like this: Name Stmts Miss Cover ----------------------------------------------- acct_mgt/__init__.py 0 0 100% acct_mgt/app.py 141 10 93% acct_mgt/defaults.py 2 0 100% acct_mgt/kubeclient.py 33 19 42% acct_mgt/moc_openshift.py 299 133 56% acct_mgt/wsgi.py 7 7 0% ----------------------------------------------- TOTAL 482 169 65% - Add a note to the README about running unit tests. x-branch: feature/tests
You can see the output of running the unit tests here. |
There are currently several unit tests that are marked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the third in a series of pull requests (of which #62 is the first and #63 is the second).
This PR is all about tests: