forked from bcgov/wps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added .env file in root (needed for vscode tests to work correctly), which meant not having a blanket .env ignore rule. Adding launch.json and settings.json configuration for vscode, which meant not having blank .vscode ignore rule, and adding poetry.toml file to force common location for python virtual env. Updated and added info to README files. Adding logging exception in audits. (otherwise, if db is configured incorrectly, it will fail without logging anything) Added a default failback for missing static folder. That's all garbage code that needs to be made redundant anyway by serving up the static content elsewhere. (Without this, an incorrectly configured static folder causes unit tests to fail, which in turn result in unit test discovery failure in vscode) Added example .env Made some changes to s3-backup
- Loading branch information
Showing
15 changed files
with
207 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PYTHONPATH=api |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "api", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "api/app/main.py", | ||
"console": "integratedTerminal" | ||
}, | ||
{ | ||
"name": "api - module", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "app.main", | ||
"console": "integratedTerminal" | ||
}, | ||
{ | ||
"name": "app.weather_models.env_canada RDPS", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "app.weather_models.env_canada", | ||
"args": [ | ||
"RDPS" | ||
] | ||
}, | ||
{ | ||
"name": "app.weather_models.env_canada HRDPS", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "app.weather_models.env_canada", | ||
"args": [ | ||
"HRDPS" | ||
] | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"python.pythonPath": "${workspaceFolder}/api/.venv/bin/python", | ||
"python.defaultInterpreterPath": "${workspaceFolder}/api/.venv/bin/python", | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.promptToConfigure": true, | ||
"python.envFile": "${workspaceFolder}/.env", | ||
"python.formatting.autopep8Args": [ | ||
"--max-line-length=110", | ||
"--ignore=E402" | ||
], | ||
"files.exclude": { | ||
".github": false, | ||
"**/.pytest_cache": true, | ||
"**/__pycache__**": true, | ||
"web/node_modules": true, | ||
"api/python_cache": true | ||
}, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true, | ||
"source.fixAll.prettier": true | ||
}, | ||
"editor.formatOnSave": true, | ||
"eslint.format.enable": true, | ||
"eslint.validate": [ | ||
"javascript", | ||
"typescript" | ||
], | ||
"eslint.run": "onSave", | ||
"[python]": { | ||
"editor.rulers": [110] | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.tabSize": 2 | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.tabSize": 2 | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.tabSize": 2 | ||
}, | ||
"[yaml]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.insertSpaces": true, | ||
"editor.tabSize": 2, | ||
"editor.formatOnSave": true | ||
}, | ||
"python.testing.pytestArgs": [ | ||
"api" | ||
] | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" Unit tests for api_access_audit_log """ | ||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
from app.db.crud.api_access_audits import create_api_access_audit_log | ||
|
||
|
||
class TestApiAccessAudit(unittest.TestCase): | ||
""" Access audit test cases """ | ||
|
||
@patch('app.db.database._get_write_session', return_value=MagicMock()) | ||
@patch('app.db.crud.api_access_audits.logger') | ||
def test_exception_logged(self, mock_logger, mock_get_write_session): | ||
# Create a mock object that raises an exception when commit is called. | ||
mock_session = MagicMock() | ||
mock_session.commit = MagicMock(side_effect=Exception()) | ||
mock_get_write_session.return_value = mock_session | ||
|
||
# We expect an exception to be thrown when we do the audit log | ||
with self.assertRaises(Exception): | ||
create_api_access_audit_log('user', True, '/something') | ||
# But - critically, we expect the exception to be logged. | ||
mock_logger.error.assert_called() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" Unit tests for front end """ | ||
import unittest | ||
|
||
from unittest.mock import patch | ||
from app.frontend import get_static_foldername | ||
|
||
|
||
class TestFrontend(unittest.TestCase): | ||
""" Front end unit tests""" | ||
|
||
@patch('app.frontend.config.get') | ||
def test_get_static_foldername_not_exist(self, get_patch): | ||
""" If the configured folder doesn't exist, return the default static folder. """ | ||
get_patch.return_value = 'folder_does_not_exist' | ||
self.assertTrue(get_static_foldername().endswith('static')) | ||
|
||
@patch('app.frontend.config.get') | ||
def test_get_static_foldername_exist(self, get_patch): | ||
""" If the configured folder does exist, we get it back """ | ||
get_patch.return_value = '.' | ||
self.assertEqual(get_static_foldername(), '.') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[virtualenvs] | ||
in-project = true |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
PG_HOSTNAME=patroni-wps-pr-1427-leader | ||
PG_DATABASE=wps | ||
PG_PASSWORD=wps | ||
OBJECT_STORE_SERVER=nrs.objectstore.gov.bc.ca | ||
OBJECT_STORE_USER_ID=nr-wps-dev | ||
OBJECT_STORE_SECRET=your secret key | ||
OBJECT_STORE_BUCKET=gpdqha | ||
AWS_HOSTNAME=nrs.objectstore.gov.bc.ca | ||
AWS_ACCESS_KEY=nr-wps-dev | ||
AWS_SECRET_KEY=yoursecretkey | ||
AWS_BUCKET=gpdqha |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
.env.docker |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
version: "3.7" | ||
services: | ||
backup: | ||
build: | ||
context: . | ||
env_file: | ||
- .env.docker | ||
- .env.docker |
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