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

Merge Dev into Main July 10 2024 #50

Merged
merged 360 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
360 commits
Select commit Hold shift + click to select a range
006cec2
Removed cat command from Bandit run in GitHub Actions
maxachis May 26, 2024
b931fc1
Adjustment
maxachis May 26, 2024
12a9ba9
Adjustment
maxachis May 26, 2024
e05fbc1
Update Bandit Security Linting trigger event
maxachis May 26, 2024
2f3a61d
Expand targets for Bandit Security Linting
maxachis May 26, 2024
07318bb
Merge pull request #17 from Police-Data-Accessibility-Project/mc_issu…
maxachis May 26, 2024
f9e4852
Refactor SQL queries for enhanced security
maxachis May 26, 2024
299975d
Merge pull request #18 from Police-Data-Accessibility-Project/mc_issu…
maxachis May 26, 2024
2672d5e
Merge pull request #16 from Police-Data-Accessibility-Project/mc_add_…
maxachis May 26, 2024
bd86884
Merge pull request #14 from Police-Data-Accessibility-Project/mc_add_…
maxachis May 27, 2024
daf1608
Remove test parameters from query functions
maxachis May 27, 2024
6cb12c9
Refactor fixture import paths in test files
maxachis May 27, 2024
926798c
Move helper functions and refactor tests
maxachis May 27, 2024
845dd33
Merge pull request #19 from Police-Data-Accessibility-Project/mc_issu…
maxachis May 29, 2024
86e6cd3
Refactor test suite by relocating helper functions and updating clien…
maxachis May 30, 2024
087e6a3
Add integration tests for various endpoints
maxachis May 30, 2024
3a264db
Improve readability of code via tweaks and docstrings
maxachis May 30, 2024
34cbec2
Update headers in integration tests
maxachis May 30, 2024
f5f66e7
shuffle results messaging
josh-chamberlain May 30, 2024
581f519
simpler language
josh-chamberlain May 30, 2024
a02273b
whitespace
josh-chamberlain May 30, 2024
c3abf39
update test
josh-chamberlain May 30, 2024
c26ced8
fix test?
josh-chamberlain May 30, 2024
c761c53
Revert "fix test?"
josh-chamberlain May 30, 2024
5e8c9c3
Revert "update test"
josh-chamberlain May 30, 2024
fb049c5
update test
josh-chamberlain May 30, 2024
89343d0
Merge pull request #20 from Police-Data-Accessibility-Project/mc_issu…
maxachis May 30, 2024
95c610d
Merge pull request #314 from Police-Data-Accessibility-Project/result…
josh-chamberlain May 30, 2024
b3ac9e7
Fixed response status code for data source not found to return 200 in…
maxachis May 31, 2024
2cee3cd
Fix typo in assertion for data source URL in integration test.
maxachis May 31, 2024
42b4f0d
Add unit tests for getting and updating data sources by ID in test_Da…
maxachis May 31, 2024
cc1f61a
Merge pull request #21 from Police-Data-Accessibility-Project/mc_issu…
maxachis May 31, 2024
4008157
Refactor helper_functions.py to generate a random email for test user…
maxachis Jun 1, 2024
988a3b4
Implemented various test cases to check the validity and expiration s…
maxachis Jun 1, 2024
e05622b
Refactor security middleware to improve readability and efficiency in…
maxachis Jun 1, 2024
3e610c5
Add function to delete session token from database
maxachis Jun 1, 2024
a4b6ef9
Refactored RefreshSession.py to include delete_session_token function…
maxachis Jun 1, 2024
192088f
Fixed create_test_user so that email is set to a random email if not …
maxachis Jun 1, 2024
759c957
Merge pull request #22 from Police-Data-Accessibility-Project/mc_fix_…
maxachis Jun 1, 2024
2efa94d
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_issue_…
maxachis Jun 1, 2024
07f5969
✨ Add ClientWithMockDB namedtuple in fixtures.py and update test_Data…
maxachis Jun 2, 2024
583e855
✨ Add bypass for api_required decorator in tests/resources/__init__.py
maxachis Jun 2, 2024
cf8be37
✅ Add check_response_status function in tests/helper_functions.py to …
maxachis Jun 2, 2024
b5cee84
🛠️ refactor: Refactor token retrieval and deletion functions in login…
maxachis Jun 2, 2024
a92d61c
Refactor RefreshSession.py to handle custom exceptions and improve co…
maxachis Jun 2, 2024
2af5634
Refactor endpoint test fixture import in test_endpoints.py"
maxachis Jun 2, 2024
d84cbab
refactor token_results to get_session_token_user_data & update tests.
maxachis Jun 2, 2024
5f00c5a
✨ Add test_RefreshSession.py with refresh session test cases
maxachis Jun 2, 2024
d9dd825
Merge pull request #23 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 2, 2024
04de044
🐛 fix(middleware): Update INSERT_LOG_QUERY to remove redundant dateti…
maxachis Jun 2, 2024
6a8a2cf
Update timestamp field name in query
maxachis Jun 2, 2024
1c0a8a0
Refactor code in resources/QuickSearch.py
maxachis Jun 2, 2024
24a9a57
Fix bug in test_search_tokens.py
maxachis Jun 2, 2024
dcacd66
Add tests for quick search functionality in test_QuickSearch.py"
maxachis Jun 2, 2024
3cfa69b
Merge pull request #24 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 2, 2024
c4cfa66
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_issue_…
maxachis Jun 2, 2024
8f2aa2d
✨🔍 Refactor test functions to use helper function for checking respon…
maxachis Jun 2, 2024
01454af
Merge branch 'dev' into mc_issue_285_refactor_search_tokens
maxachis Jun 2, 2024
adfe6b4
Merge pull request #13 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 2, 2024
7450935
refactor(api): Update quick_search_query.py function signatures
maxachis Jun 2, 2024
be682c7
✨ Add Response return type to data_source_by_id_wrapper function
maxachis Jun 2, 2024
ba6c4ca
✨ Add test for data_source_by_id_wrapper function
maxachis Jun 2, 2024
43d80ac
⚡️ refactor: refactor quick search endpoint response handling in inte…
maxachis Jun 2, 2024
f888606
💻 Add test cases for quick search query middleware and eliminate now…
maxachis Jun 2, 2024
d4b365d
⚙️: remove now-redundant Resource tests in test_DataSources.py
maxachis Jun 2, 2024
f1e47c6
Merge pull request #25 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 2, 2024
4e85a2b
⚙️ Adjust status code for data source not found response
maxachis Jun 2, 2024
144d4ac
Merge pull request #26 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 2, 2024
ec08327
⚡️ feat(middleware): Add functionality to cache homepage search results
maxachis Jun 2, 2024
4b40a16
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_issue_…
maxachis Jun 2, 2024
6ca9cf8
⚡️ Refactor and update security middleware and tests for API key vali…
maxachis Jun 3, 2024
12fbb30
Remove redundant NoAPIKeyError handling
maxachis Jun 3, 2024
76e782e
Merge pull request #27 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 6, 2024
72dc015
Refactor Agencies.py to use get_agencies function from middleware.age…
maxachis Jun 8, 2024
08fb4ea
Fixed formatting issues and added new test for agencies endpoint.
maxachis Jun 8, 2024
5d50f92
Refactor tests/resources/app_test.py to remove commented out code and…
maxachis Jun 8, 2024
84feef5
Migrate functionality in Login Resource to backend. Add relevant tests.
maxachis Jun 8, 2024
a4f1f89
Updated convert_dates_to_strings function to specify data_dict parame…
maxachis Jun 8, 2024
c524ae6
Migrate logic from ApiKey resource. Add relevant tests.
maxachis Jun 8, 2024
089067a
Updated test_common.py to include test cases for converting dates to …
maxachis Jun 8, 2024
8f4de7b
Updated webhook_logic.py to include a function for sending password r…
maxachis Jun 8, 2024
44446b3
Migrate search tokens logic to middleware from Resource and add enum …
maxachis Jun 8, 2024
392bf88
Migrate archives logic to middleware from Resource.
maxachis Jun 8, 2024
797f82b
Migrate DataSources logic to middleware from Resource.
maxachis Jun 8, 2024
e48093a
Migrate Token and password reset logic to middleware from Resource.
maxachis Jun 8, 2024
abcc31a
Migrate password change logic to middleware from Resource
maxachis Jun 8, 2024
852421c
Add additional tests at middleware and resources level.
maxachis Jun 8, 2024
2f577e6
Modify patch addresses in integration test due to changes in underlyi…
maxachis Jun 8, 2024
8182dc6
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_fix_qu…
maxachis Jun 10, 2024
49fa540
Fix bugs following merge
maxachis Jun 10, 2024
69bf937
Reformat with black
maxachis Jun 10, 2024
2bdd9dc
Merge pull request #3 from Police-Data-Accessibility-Project/mc_fix_q…
maxachis Jun 10, 2024
3a29120
Merge branch 'dev' into mc_replace_with_abort
maxachis Jun 12, 2024
6a7467a
Fixed response assertion in test_RefreshSession.py to compare the mes…
maxachis Jun 12, 2024
efffcf7
Refactored test fixtures to use monkeypatch for mocking psycopg2 conn…
maxachis Jun 15, 2024
7a6e392
Refactored test fixtures to use monkeypatch for mocking psycopg2 conn…
maxachis Jun 15, 2024
3c08851
Updated README.md to include information about setting the `MAILGUN_K…
maxachis Jun 15, 2024
46abf7a
Merge pull request #317 from Police-Data-Accessibility-Project/mc_v1_…
maxachis Jun 15, 2024
9c40067
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_replac…
maxachis Jun 16, 2024
36bff2c
Merge pull request #29 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 16, 2024
92c6f91
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_replac…
maxachis Jun 16, 2024
0a7d355
Remove old code comments from app_test.py
EvilDrPurple Jun 16, 2024
1138de7
Delete regular_api_checks.py
EvilDrPurple Jun 16, 2024
e85614d
Update README
EvilDrPurple Jun 16, 2024
daa04d5
Delete tests.yml
EvilDrPurple Jun 16, 2024
91e0c2f
re-insert comment
EvilDrPurple Jun 16, 2024
2fae1ef
Merge pull request #15 from Police-Data-Accessibility-Project/mc_repl…
maxachis Jun 17, 2024
c9e47c3
Resolve merge conflict
EvilDrPurple Jun 17, 2024
00115da
Resolve merge conflict
EvilDrPurple Jun 17, 2024
9e210a9
Merge branch 'dev' into 323-deprecate-regular_api_checkspy
EvilDrPurple Jun 17, 2024
670eefe
Resolve merge conflicts
EvilDrPurple Jun 17, 2024
22a1af9
Merge pull request #30 from Police-Data-Accessibility-Project/323-dep…
maxachis Jun 17, 2024
9a1af2a
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_issue_…
maxachis Jun 17, 2024
9e60621
Replace status codes with HTTPStatus
EvilDrPurple Jun 18, 2024
2627c32
Create runtime.txt
maxachis Jun 19, 2024
00c1061
Update runtime.txt
maxachis Jun 19, 2024
b599abf
Reformat with Black
maxachis Jun 19, 2024
c809d32
Merge pull request #28 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 19, 2024
75e7ab7
Add utility function for handling environment variables and add/updat…
maxachis Jun 20, 2024
610ad19
Format with Black
maxachis Jun 20, 2024
d16c6fb
Merge pull request #33 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 20, 2024
4a16914
Refactor webhook logic to include timeout parameter for better error …
maxachis Jun 20, 2024
665696d
Reformat with black
maxachis Jun 20, 2024
cd0ca10
Merge pull request #34 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 20, 2024
d1e085e
Merge pull request #32 from Police-Data-Accessibility-Project/mc-add-…
maxachis Jun 21, 2024
b6d643f
Update README.md
maxachis Jun 21, 2024
0264e3b
Update README.md
maxachis Jun 21, 2024
a5cc693
Merge branch 'dev' into 319-replace-hardcoded-http-status-values-with…
EvilDrPurple Jun 21, 2024
08435eb
Resolve merge conflicts
EvilDrPurple Jun 21, 2024
67dcfcc
Merge pull request #31 from Police-Data-Accessibility-Project/319-rep…
maxachis Jun 21, 2024
3bf7932
Fixed bug in SearchTokens.get() causing error.
maxachis Jun 21, 2024
f605760
Merge pull request #35 from Police-Data-Accessibility-Project/mc_fix_…
maxachis Jun 21, 2024
2897b0e
Refactor post_to_webhook function to include base URL in message
maxachis Jun 21, 2024
decd0b1
Updated test case for post_to_webhook function to include additional …
maxachis Jun 21, 2024
9a96072
Refactor data source queries to use cursor objects instead of connect…
maxachis Jun 23, 2024
31c7e07
Format with black.
maxachis Jun 23, 2024
5cf8de9
Merge pull request #38 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 23, 2024
4118f6a
Refactor exception handling in security and data source queries middl…
maxachis Jun 23, 2024
a8af267
Merge pull request #39 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jun 23, 2024
81f03a7
Remove unused tests
maxachis Jun 24, 2024
6c8a02b
Remove unused tests
maxachis Jun 24, 2024
8909ac3
Add GitHub workflow to run Pytest for testing API endpoints
maxachis Jun 24, 2024
ab6307c
Implemented bypass_api_required fixture to bypass the api_required de…
maxachis Jun 24, 2024
5042b56
Correct bug in Github Actions
maxachis Jun 24, 2024
fda2b8c
Correct bug in Github Actions
maxachis Jun 24, 2024
def1f24
Change name of Github Action
maxachis Jun 24, 2024
ec8fc77
Merge pull request #40 from Police-Data-Accessibility-Project/mc_setu…
maxachis Jun 24, 2024
8394f97
Merge pull request #37 from Police-Data-Accessibility-Project/mc_qol_…
maxachis Jun 25, 2024
aded2d5
Implemented database client functionality for user management
maxachis Jun 26, 2024
47bc110
Remove token_management.py
maxachis Jun 26, 2024
52296b4
Refactored PsycopgResource.py to include a context manager for settin…
maxachis Jun 26, 2024
cadebc2
Updated fixtures.py to include a new fixture for live_database_client…
maxachis Jun 26, 2024
5de1117
Refactor database interaction to utilize DatabaseClient class in User…
maxachis Jun 26, 2024
1447406
Refactored get_role and get_session_token in security.py to use Datab…
maxachis Jun 26, 2024
3df8eca
Refactor reset token validation endpoint to use database client, impr…
maxachis Jun 26, 2024
63273a7
Add get_data_source_by_id()
EvilDrPurple Jun 27, 2024
e157367
Add test_get_data_source_by_id() placeholder
EvilDrPurple Jun 27, 2024
2dd8daa
Add get_approved_data_sources()
EvilDrPurple Jun 27, 2024
44604bf
Add test_get_approved_data_sources() placeholder
EvilDrPurple Jun 27, 2024
ec5cd4f
Add get_needs_identification_data_source()
EvilDrPurple Jun 27, 2024
9fc5b72
Add test_get_needs_identification_data_sources() placeholder
EvilDrPurple Jun 27, 2024
7d53f73
Add add_new_data_source() and companion function
EvilDrPurple Jun 29, 2024
7d1074d
Add test_add_new_data_source() placeholder function
EvilDrPurple Jun 29, 2024
db6f584
Add test_create_new_data_source_query() placeholder function
EvilDrPurple Jun 29, 2024
df15622
Add update_data_source() and companion function
EvilDrPurple Jun 29, 2024
ddfa616
Add get_data_sources_for_map()
EvilDrPurple Jun 29, 2024
049ed56
Add test_get_data_sources_for_map() placeholder function
EvilDrPurple Jun 29, 2024
3741008
Add get_agencies_from_page() and companion function
EvilDrPurple Jun 29, 2024
b6f7cd2
Add test_get_agencies_from_page() placeholder function
EvilDrPurple Jun 29, 2024
ba7346e
Add test_get_offset() placeholder function
EvilDrPurple Jun 29, 2024
6e241c6
Add test_update_data_sorce() placeholder function
EvilDrPurple Jun 29, 2024
6907859
Add test_create_data_source_update_query() placeholder function
EvilDrPurple Jun 29, 2024
c932d85
Add get_data_sources_to_archive() function
EvilDrPurple Jun 29, 2024
9d0d40e
Add test_get_data_sources_to_archive() placeholder function
EvilDrPurple Jun 29, 2024
8134d99
Add update_url_status_to_broken() function
EvilDrPurple Jun 29, 2024
bccbcd8
Add test_update_url_status_to_broken() placeholder function
EvilDrPurple Jun 29, 2024
719df42
Add update_last_cached() function
EvilDrPurple Jun 29, 2024
88a4858
Add test_update_last_cached() placeholder function
EvilDrPurple Jun 29, 2024
bbdd5bf
Add unaltered_qucik_search() function
EvilDrPurple Jun 30, 2024
4603d67
Add test_unaltered_quick_search placeholder function
EvilDrPurple Jun 30, 2024
71514db
Combine functionality into one method
EvilDrPurple Jun 30, 2024
d1cb5d9
Add log_quick_search() function
EvilDrPurple Jun 30, 2024
56dc655
Add test_log_quick_search() placeholder function
EvilDrPurple Jun 30, 2024
ffacd99
Add insert_access_token() function
EvilDrPurple Jun 30, 2024
9594f4a
Add test_add_new_access_token() placeholder function
EvilDrPurple Jun 30, 2024
f258eb6
Add get_user_info() function
EvilDrPurple Jun 30, 2024
939e543
Add test_database_client() placeholder method
EvilDrPurple Jun 30, 2024
1215810
Add get_role_by_email() function
EvilDrPurple Jun 30, 2024
22b06f9
Add test_get_role_by_email() placeholder function
EvilDrPurple Jun 30, 2024
cf38b6e
Refactor functions to only include database logic
EvilDrPurple Jun 30, 2024
51b2a1a
Add add_new_session_token() function
EvilDrPurple Jun 30, 2024
5e3385d
Add test_add_new_session_token() placeholder function
EvilDrPurple Jun 30, 2024
2f280cf
Add get_user_info_by_session_token() function
EvilDrPurple Jul 1, 2024
7f36a71
Add test_get_user_info_by_session_token() placeholder function
EvilDrPurple Jul 1, 2024
7972a88
Add delete_session_token() function
EvilDrPurple Jul 1, 2024
8999d35
Add test_delete_session_token() placeholder function
EvilDrPurple Jul 1, 2024
4afa63e
Naming updates
EvilDrPurple Jul 1, 2024
0d965f0
Add get_access_token() function
EvilDrPurple Jul 1, 2024
f3d013c
Add test_get_access_token() placeholder function
EvilDrPurple Jul 1, 2024
c230ede
Add delete_expired_access_tokens() function
EvilDrPurple Jul 1, 2024
08e3c85
Add test_delete_expired_access_tokens() placeholder function
EvilDrPurple Jul 1, 2024
cb9ad18
Format with black
EvilDrPurple Jul 1, 2024
da814e6
Resolve circular imports
EvilDrPurple Jul 1, 2024
81cc971
Add missing import
EvilDrPurple Jul 1, 2024
502969f
Fix typo
EvilDrPurple Jul 1, 2024
119ac1b
Merge pull request #41 from Police-Data-Accessibility-Project/databas…
maxachis Jul 1, 2024
b959731
Fixing issue with cursor reference in database_client and middleware …
maxachis Jul 3, 2024
92d2e97
Fix casing search issue
EvilDrPurple Jul 5, 2024
15489de
Fix quick search
EvilDrPurple Jul 5, 2024
ac3356c
Added constants for approved columns in the database_client module, i…
maxachis Jul 5, 2024
c06c066
Add dynamic query constructor class for constructing complex queries
maxachis Jul 5, 2024
e05c886
Refactored result_formatter.py to improve readability and maintainabi…
maxachis Jul 5, 2024
0c55a8c
Refactored data source queries, removed redundant code, and added dyn…
maxachis Jul 5, 2024
0a095b4
Refactor access token insertion logic to use DatabaseClient method in…
maxachis Jul 5, 2024
9477d5a
Refactor data source queries to use DatabaseClient in data_source_que…
maxachis Jul 5, 2024
6f516b5
Refactor quick search query method to use DatabaseClient for database…
maxachis Jul 5, 2024
6a1f735
Refactor search_tokens_logic.py to use DatabaseClient instance instea…
maxachis Jul 5, 2024
0630d70
Refactor security middleware to use DatabaseClient methods for handli…
maxachis Jul 5, 2024
1f6b301
Refactor database handling in DataSources.py for more modular and mai…
maxachis Jul 5, 2024
92c024d
Refactor QuickSearch.py to use database client setup for query execut…
maxachis Jul 5, 2024
fec5cf8
Refactor database client setup in SearchTokens.py to use 'with' state…
maxachis Jul 5, 2024
da0dd52
Fixed helper function to avoid duplicating data in the database by ch…
maxachis Jul 5, 2024
f9e226c
Add database client tests for adding new user, resetting token, updat…
maxachis Jul 5, 2024
856e43f
Merge pull request #43 from Police-Data-Accessibility-Project/348-qui…
maxachis Jul 5, 2024
903b178
Merge pull request #42 from Police-Data-Accessibility-Project/346-qui…
maxachis Jul 5, 2024
5dabec3
Quick search fix
EvilDrPurple Jul 5, 2024
d09329a
Delete test_managed_cursor.pyn
maxachis Jul 5, 2024
eef2178
Refactor psycopg2 connection initialization and import statements
maxachis Jul 5, 2024
46f0a97
Remove comments
maxachis Jul 5, 2024
7030667
Refactor db_cursor to use DictCursor
maxachis Jul 5, 2024
084a218
Refactor PsycopgResource's setup_database_client method to use DictCu…
maxachis Jul 5, 2024
4bb84dc
Refactor to use db_client. Remove subsequent unused code.
maxachis Jul 5, 2024
ca36a3e
Finish filling in database_client.py
maxachis Jul 5, 2024
ad2607a
Refactor create_test_user_api() to use check_response_status()
maxachis Jul 5, 2024
aee2388
Refactor resources to utilize db_client.
maxachis Jul 5, 2024
aa21655
Update tests to account for database_client updates.
maxachis Jul 5, 2024
5e0e8b1
Merge pull request #45 from Police-Data-Accessibility-Project/348-to-337
maxachis Jul 5, 2024
af12401
Consolidate get_session_token_info and get_user_info_by_session_token
maxachis Jul 5, 2024
5cbcbb8
Consolidate get_session_token_info and get_user_info_by_session_token
maxachis Jul 5, 2024
fbd1060
Consolidate get_session_token_info and get_user_info_by_session_token
maxachis Jul 5, 2024
e82b9cb
Cleanup unused imports
maxachis Jul 5, 2024
3351224
Cleanup unused imports
maxachis Jul 5, 2024
15dbc44
Cleanup unused imports
maxachis Jul 5, 2024
2826752
Cleanup unused imports
maxachis Jul 5, 2024
3c65921
Consolidate mocks
maxachis Jul 5, 2024
86dd1bd
Merge branch 'dev' into mc_issue_337_create_database_client
maxachis Jul 5, 2024
b4096be
Create TestDataGenerator
maxachis Jul 9, 2024
6aea5ea
Merge pull request #48 from Police-Data-Accessibility-Project/mc_test…
maxachis Jul 9, 2024
2b6f168
Merge remote-tracking branch 'Data-Sources-App-V2/dev' into mc_issue_…
maxachis Jul 10, 2024
1c41db6
Merge pull request #46 from Police-Data-Accessibility-Project/mc_issu…
maxachis Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Bandit Security Linting

on: [pull_request]

jobs:
bandit:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit

- name: Run Bandit
run: |
bandit -r middleware resources app.py

- name: Upload Bandit results
uses: actions/upload-artifact@v2
with:
name: bandit-report
path: bandit_output.txt

2 changes: 1 addition & 1 deletion .github/workflows/pull.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest app_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
pytest tests/resources/app_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

setup_client:
defaults:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
uses: reviewdog/action-flake8@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
flake8_args: --ignore E501,W291 # Does not check for max line exceed or trailing whitespace
level: warning
31 changes: 31 additions & 0 deletions .github/workflows/run_pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test using Pytest

on:
pull_request:

jobs:
run_tests:
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DEV_DB_CONN_STRING: ${{secrets.DEV_DB_CONN_STRING}}
DO_DATABASE_URL: ${{secrets.DEV_DB_CONN_STRING}} # TODO: Ideally, won't need both for testing, but this is for safety for now
name: Run Pytest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m spacy download en_core_web_sm
pip install pytest pytest-cov
- name: Run tests
run: |
pytest tests/integration
pytest tests/middleware
pytest tests/resources
pytest tests/test_endpoints.py

40 changes: 0 additions & 40 deletions .github/workflows/tests.yml

This file was deleted.

24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,32 @@ pip install -r requirements.txt

### 5. Add environment secrets

Either add a `.env` file to your local root directory or manually export these secrets: `DO_DATABASE_URL` and `VITE_VUE_API_BASE_URL`.
In both the local root directory and the `/client` directory, either:
1. Either add a `.env` file to your local root directory with the below secrets
2. or manually export the below secrets

Reach out to contact@pdap.io or make noise in Discord if you'd like access to these keys.

```
# .env

DO_DATABASE_URL="postgres://data_sources_app:<password>@db-postgresql-nyc3-38355-do-user-8463429-0.c.db.ondigitalocean.com:25060/defaultdb"
DEV_DB_CONN_STRING="postgresql://data_sources_app_v2:<password>@pdap-db-dev-do-user-8463429-0.c.db.ondigitalocean.com:25060/pdap_dev_db?sslmode=require"
VITE_VUE_API_BASE_URL="http://localhost:5000"
VITE_VUE_APP_BASE_URL="http://localhost:8888"
SECRET_KEY="mySecretKey"
```

```
# shell

export DO_DATABASE_URL=postgres://data_sources_app:<password>@db-postgresql-nyc3-38355-do-user-8463429-0.c.db.ondigitalocean.com:25060/defaultdb
export DEV_DB_CONN_STRING="postgresql://data_sources_app_v2:<password>@pdap-db-dev-do-user-8463429-0.c.db.ondigitalocean.com:25060/pdap_dev_db?sslmode=require"
export VITE_VUE_API_BASE_URL="http://localhost:5000"
export VITE_VUE_APP_BASE_URL="http://localhost:8888"
export SECRET_KEY="mySecretKey"
```
Additionally, if you are testing the email functionality, you will need to also provide the `MAILGUN_KEY` environment variable as well (also obtainable from the sources mentioned above).

### 6. Allow your IP address

Expand Down Expand Up @@ -104,11 +111,20 @@ npm run dev

## Testing

All unit tests for the API live in the app_test.py file. It is best practice to add tests for any new feature to ensure it is working as expected and that any future code changes do not affect its functionality. All tests will be automatically run when a PR into dev is opened in order to ensure any changes do not break current app functionality. If a test fails, it is a sign that the new code should be checked or possibly that the test needs to be updated. Tests are currently run with pytest and can be run locally with the `pytest` command.
### Location
All unit and integration tests for the API live in the `tests` folder

Endpoints are structured for simplified testing and debugging. Code for interacting with the database is contained in a function suffixed with "_results" and tested against a local sqlite database instance. Limited rows (stored in the DATA_SOURCES_ROWS and AGENCIES_ROWS variables in app_test_data.py) are inserted into this local instance on setup, you may need to add additional rows to test other functionality fully.
It is best practice to add tests for any new feature to ensure it is working as expected and that any future code changes do not affect its functionality. All tests will be automatically run when a PR into dev is opened in order to ensure any changes do not break current app functionality. If a test fails, it is a sign that the new code should be checked or possibly that the test needs to be updated.

Remaining API code is stored in functions suffixed with "_query" tested against static query results stored in app_test_data.py. Tests for hitting the endpoint directly should be included in regular_api_checks.py, makes sure to add the test function name in the list at the bottom so it is included in the Github actions run every 15 minutes.

### How to run tests
Some tests involve interfacing with the development database, which copies the production database's data and schema daily.

To ensure such tests properly connect to the database, create or amend an `.env` file in the root direct of the project with the environment variable `DEV_DB_CONN_STRING`. Provide as a value a connection string giving you access to the `data_sources_app` user. If you do not have this connection string, DM a database administrator.

Tests are currently run with pytest and can be run locally with the `pytest` command.

Remaining API code is stored in functions suffixed with "_query" tested against static query results stored in app_test_data.py.

```
pip install pytest
Expand Down
3 changes: 1 addition & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Flask
from flask_restful import Api
from flask_restx import Api
from flask_cors import CORS
from resources.User import User
from resources.Login import Login
Expand Down Expand Up @@ -27,7 +27,6 @@ def add_resource(api, resource, endpoint, **kwargs):

def create_app() -> Flask:
psycopg2_connection = initialize_psycopg2_connection()

app = Flask(__name__)
api = Api(app)
CORS(app)
Expand Down
Loading
Loading