Skip to content

Commit cc354bd

Browse files
authored
Merge pull request #38 from TaskarCenterAtUW/dev
Dev to Stage
2 parents 963b493 + bd83973 commit cc354bd

File tree

11 files changed

+331
-25
lines changed

11 files changed

+331
-25
lines changed

.github/workflows/unit_tests.yaml

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches-ignore:
66
- '**'
77
pull_request:
8-
branches: [main, dev, stage]
8+
branches: [ main, dev, stage ]
99

1010
jobs:
1111
UnitTest:
@@ -15,28 +15,61 @@ jobs:
1515
DATABASE_NAME: test_database
1616

1717
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v2
18+
- name: Checkout code
19+
uses: actions/checkout@v2
2020

21-
- name: Set up Python
22-
uses: actions/setup-python@v2
23-
with:
24-
python-version: '3.10'
21+
- name: Set up Python
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: '3.10'
2525

26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install -r requirements.txt
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements.txt
3030
31-
- name: Run tests with coverage
32-
run: |
33-
coverage run --source=src -m unittest discover -s tests/unit_tests
34-
coverage xml
35-
36-
- name: Check coverage
37-
run: |
38-
coverage report --fail-under=85
31+
- name: Determine output folder
32+
id: set_output_folder
33+
run: |
34+
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
35+
branch_name=$GITHUB_BASE_REF
36+
else
37+
branch_name=$GITHUB_REF_NAME
38+
fi
39+
40+
if [[ $branch_name == "main" ]]; then
41+
echo "output_folder=prod" >> $GITHUB_ENV
42+
elif [[ $branch_name == "stage" ]]; then
43+
echo "output_folder=stage" >> $GITHUB_ENV
44+
elif [[ $branch_name == "dev" ]]; then
45+
echo "output_folder=dev" >> $GITHUB_ENV
46+
else
47+
echo "Unknown branch: $branch_name"
48+
exit 1
49+
fi
3950
51+
- name: Run tests with coverage
52+
run: |
53+
timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
54+
mkdir -p test_results
55+
log_file="test_results/${timestamp}_report.log"
56+
echo -e "\nTest Cases Report Report\n" >> $log_file
57+
# Run the tests and append output to the log file
58+
python -m coverage run --source=src -m unittest discover -s tests/unit_tests >> $log_file 2>&1
59+
echo -e "\nCoverage Report\n" >> $log_file
60+
coverage report >> $log_file
4061
62+
- name: Check coverage
63+
run: |
64+
coverage report --fail-under=85
4165
66+
- name: Upload report to Azure
67+
uses: LanceMcCarthy/Action-AzureBlobUpload@v2
68+
with:
69+
source_folder: 'test_results'
70+
destination_folder: '${{ env.output_folder }}'
71+
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
72+
container_name: 'osw-validation-service '
73+
clean_destination_folder: false
74+
delete_if_exists: false
4275

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,6 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
.idea/
161161
reports/
162+
test_results
163+
download.py
164+
test.py

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fastapi==0.88.0
22
pydantic==1.10.4
3-
python-ms-core==0.0.22
3+
python-ms-core==0.0.23
44
uvicorn==0.20.0
55
html_testRunner==1.2.1
66
geopandas==0.14.4
7-
python-osw-validation==0.2.7
7+
python-osw-validation==0.2.9

test_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HtmlTestRunner
33

44
# Define your test cases
5-
from tests.unit_tests.test_queue_message_content import TestUpload, TestUploadData, TestToJson, TestValidationResult
5+
from tests.unit_tests.models.test_queue_message_content import TestUpload, TestUploadData, TestToJson, TestValidationResult
66
from tests.unit_tests.test_validation import TestOtherValidation, TestValidation
77
from tests.unit_tests.test_osw_validator import TestOSWValidator
88
from tests.unit_tests.test_main import TestApp

tests/__init__.py

Whitespace-only changes.

tests/unit_tests/interface/__init__.py

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import unittest
2+
from abc import ABC
3+
from unittest.mock import MagicMock
4+
from python_ms_core.core.queue.models.queue_message import QueueMessage
5+
from src.interface.validator_abstract import ValidatorAbstract
6+
7+
8+
# A concrete implementation of ValidatorAbstract for testing
9+
class ConcreteValidator(ValidatorAbstract):
10+
def validate(self, message: QueueMessage) -> None:
11+
# Example implementation: Simply pass for testing purposes
12+
pass
13+
14+
15+
class TestValidatorAbstract(unittest.TestCase):
16+
17+
def test_abstract_method_enforcement(self):
18+
# Ensure that ValidatorAbstract cannot be instantiated directly
19+
with self.assertRaises(TypeError):
20+
ValidatorAbstract()
21+
22+
def test_concrete_validator_instance(self):
23+
# Ensure a concrete class can be instantiated and implements `validate`
24+
validator = ConcreteValidator()
25+
self.assertIsInstance(validator, ValidatorAbstract)
26+
27+
def test_validate_method_called(self):
28+
# Mock a QueueMessage object
29+
message = MagicMock(spec=QueueMessage)
30+
31+
# Create an instance of the concrete validator
32+
validator = ConcreteValidator()
33+
34+
# Call the validate method and ensure it executes without error
35+
validator.validate(message)
36+
37+
# Assert that the mocked message object is a valid argument
38+
self.assertTrue(hasattr(message, '__class__'))
39+
40+
41+
if __name__ == '__main__':
42+
unittest.main()

tests/unit_tests/models/__init__.py

Whitespace-only changes.

tests/unit_tests/test_queue_message_content.py renamed to tests/unit_tests/models/test_queue_message_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import MagicMock
55
from src.models.queue_message_content import ValidationResult, Upload, UploadData, to_json
66

7-
current_dir = os.path.dirname(os.path.abspath(os.path.join(__file__, '../')))
7+
current_dir = os.path.dirname(os.path.abspath(os.path.join(__file__, '../../')))
88
parent_dir = os.path.dirname(current_dir)
99

1010
TEST_JSON_FILE = os.path.join(parent_dir, 'src/assets/osw-upload.json')

tests/unit_tests/test_config.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import unittest
3+
from unittest.mock import patch
4+
from src.config import Settings
5+
6+
7+
class TestSettings(unittest.TestCase):
8+
9+
@patch.dict(os.environ, {
10+
'AUTH_PERMISSION_URL': 'http://auth-url.com',
11+
'MAX_CONCURRENT_MESSAGES': '5',
12+
'AUTH_SIMULATE': 'True'
13+
}, clear=True)
14+
def test_settings_with_simulated_auth(self):
15+
settings = Settings()
16+
self.assertEqual(settings.app_name, 'python-osw-validation')
17+
self.assertEqual(settings.auth_permission_url, 'http://auth-url.com')
18+
self.assertEqual(settings.max_concurrent_messages, 5)
19+
self.assertEqual(settings.auth_provider, 'Simulated')
20+
21+
@patch.dict(os.environ, {
22+
'AUTH_PERMISSION_URL': 'http://auth-url.com',
23+
'MAX_CONCURRENT_MESSAGES': '10',
24+
'AUTH_SIMULATE': 'False'
25+
}, clear=True)
26+
def test_settings_with_hosted_auth(self):
27+
settings = Settings()
28+
self.assertEqual(settings.auth_provider, 'Hosted')
29+
30+
@patch.dict(os.environ, {
31+
'AUTH_SIMULATE': 'invalid_value'
32+
}, clear=True)
33+
def test_settings_with_invalid_auth_simulate(self):
34+
settings = Settings()
35+
self.assertEqual(settings.auth_provider, 'Hosted')
36+
37+
@patch.dict(os.environ, {}, clear=True)
38+
def test_default_settings(self):
39+
settings = Settings()
40+
self.assertEqual(settings.app_name, 'python-osw-validation')
41+
self.assertEqual(settings.event_bus.container_name, 'osw')
42+
self.assertIsNone(settings.auth_permission_url)
43+
self.assertEqual(settings.max_concurrent_messages, 2)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

0 commit comments

Comments
 (0)