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

Mc add endpoint tests #14

Merged
merged 4 commits into from
May 27, 2024
Merged

Mc add endpoint tests #14

merged 4 commits into from
May 27, 2024

Conversation

maxachis
Copy link

Fixes

  • None. Quality of life update.

Description

Refactor create_app Function in app.py

  • Moved initialization of the psycopg2 connection out of the create_app function and into its parameter list.
  • Enhanced flexibility and reusability of the function, allowing it to accept different database connections.
  • Simplified testing and opened the possibility for using different database management systems in the future.
  • Remove Unused Methods from PsycopgResource Class

Cleaned up the PsycopgResource class by removing methods that were not being used.

Add Thorough Tests for All Application Endpoints

  • Created a new file, test_endpoints.py, dedicated to comprehensive testing of all application endpoints.
  • Utilized Pytest to ensure each endpoint correctly calls (or doesn’t call) the appropriate methods in their supporting classes.
  • Included tests for both allowed and not allowed methods for each endpoint.

Testing

  • Run test_endpoints.py

Performance

  • Minimal additional test overhead.

Docs

  • Not applicable

maxachis added 3 commits May 25, 2024 18:30
The refactoring involved moving the initialization of the psycopg2 connection out of the create_app function and into its parameter list. This allows the function to be more flexible and reusable, capable of accepting different database connections. It allows for easier testing and potential use with different database management systems in the future.
This commit includes the creation of a new file, test_endpoints.py, specifically dedicated to thoroughly testing the functionality of all application endpoints. It utilizes Pytest to ensure that each endpoint correctly calls (or doesn’t call) the appropriate methods in their supporting classes, as per the original design. The test checks both allowed and not allowed methods for each endpoint.
The test_app_with_mock fixture in app_test.py has been simplified. The mocker from pytest-mock has been utilized to replace the previously used patch and MagicMock. Node assertions for database interaction have been removed from the endpoint test function.
@maxachis maxachis merged commit bd86884 into dev May 27, 2024
9 checks passed
@maxachis maxachis deleted the mc_add_endpoint_tests branch May 27, 2024 12:33
@josh-chamberlain
Copy link

@maxachis nice. outside of API endpoints, what are the ways that the database can change, currently?

@maxachis
Copy link
Author

@josh-chamberlain If you're talking about how the schema can change, at the moment we're looking mostly at the removal of a view columns or the normalization of tables. However, all of this would be on pause until I finish setting up a suite of integration tests which will give us confidence that any changes I make aren't breaking things substantially.

I think that answers your question, but if you meant something else, let me know!

@josh-chamberlain
Copy link

@maxachis I meant data in the database—are we programmatically making changes to the data without using the API anywhere?

@maxachis
Copy link
Author

maxachis commented May 29, 2024

@maxachis I meant data in the database—are we programmatically making changes to the data without using the API anywhere?

@josh-chamberlain A few places. Things such as the Google Agency searcher, as designed, would be inserting data directly into the database. And then there are some things, such as user roles, which don't appear to be governed by an API endpoint and so must be modified through direct SQL queries. As a heuristic (for my own sake rather than yours), any SQL string located in a file that isn't in the data-sources-app repository (and isn't a test) would strongly suggest someplace that's modifying the database outside of an endpoint.

@josh-chamberlain
Copy link

@maxachis thanks. plus, probably only a few python files should contain endpoints...I made a new issue: Police-Data-Accessibility-Project#315

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.

2 participants