Skip to content

Commit 42a1ebf

Browse files
authored
Merge pull request #41 from TaskarCenterAtUW/stage
Stage to Prod
2 parents 2ae0062 + e3685a4 commit 42a1ebf

File tree

13 files changed

+342
-29
lines changed

13 files changed

+342
-29
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

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ The project is built on Python with FastAPI framework. All the regular nuances f
2323
- Connecting this to cloud will need the following in the `.env` file
2424

2525
```bash
26+
PROVIDER=Azure
2627
QUEUECONNECTION=xxxx
2728
STORAGECONNECTION=xxxx
2829
VALIDATION_REQ_TOPIC=xxxx
2930
VALIDATION_REQ_SUB=xxxx
3031
VALIDATION_RES_TOPIC=xxxx
3132
CONTAINER_NAME=xxxx
32-
AUTH_PERMISSION_URL=xxx
33-
MAX_CONCURRENT_MESSAGES=xxx
34-
33+
AUTH_PERMISSION_URL=xxx # This is the URL to get the token
34+
MAX_CONCURRENT_MESSAGES=xxx # Optional if not provided defaults to 2
35+
AUTH_SIMULATE=xxx # Optional if not provided defaults to False
3536
```
3637

3738
The application connect with the `STORAGECONNECTION` string provided in `.env` file and validates downloaded zipfile using `python-osw-validation` package.

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

src/osw_validator.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .models.queue_message_content import Upload, ValidationResult
1010
from .config import Settings
1111
import threading
12+
import python_osw_validation
1213

1314
logging.basicConfig()
1415
logger = logging.getLogger('OSW_VALIDATOR')
@@ -77,11 +78,16 @@ def validate(self, received_message: Upload):
7778
def send_status(self, result: ValidationResult, upload_message: Upload):
7879
upload_message.data.success = result.is_valid
7980
upload_message.data.message = result.validation_message
81+
resp_data = upload_message.data.to_json()
82+
resp_data['package'] = {
83+
'python-ms-core': Core.__version__,
84+
'python-osw-validation': python_osw_validation.__version__
85+
}
8086

8187
data = QueueMessage.data_from({
8288
'messageId': upload_message.message_id,
8389
'messageType': upload_message.message_type,
84-
'data': upload_message.data.to_json()
90+
'data': resp_data
8591
})
8692
try:
8793
self.core.get_topic(topic_name=self._settings.event_bus.validation_topic).publish(data=data)

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.

0 commit comments

Comments
 (0)