diff --git a/README.md b/README.md index c16d192..28fa389 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,21 @@ The project is built on Python with FastAPI framework. All the regular nuances f - Connecting this to cloud will need the following in the `.env` file ```bash -UPLOAD_TOPIC=xxxx -UPLOAD_SUBSCRIPTION=xxxx -VALIDATION_TOPIC=xxxx QUEUECONNECTION=xxxx STORAGECONNECTION=xxxx +VALIDATION_REQ_TOPIC=xxxx +VALIDATION_REQ_SUB=xxxx +VALIDATION_RES_TOPIC=xxxx +CONTAINER_NAME=xxxx +AUTH_PERMISSION_URL=xxx + ``` The application connect with the `STORAGECONNECTION` string provided in `.env` file and validates downloaded zipfile using `python-osw-validation` package. `QUEUECONNECTION` is used to send out the messages and listen to messages. -### How to Setup and Build + +### How to Set up and Build Follow the steps to install the python packages required for both building and running the application 1. Setup virtual environment @@ -56,9 +60,42 @@ Follow the steps to install the python packages required for both building and r ``` 3. By default `get` call on `localhost:8000/health` gives a sample response 4. Other routes include a `ping` with get and post. Make `get` or `post` request to `http://localhost:8000/health/ping` -5. Once the server starts, it will start to listening the subscriber(`UPLOAD_SUBSCRIPTION` should be in env file) +5. Once the server starts, it will start to listening the subscriber(`VALIDATION_REQ_SUB` should be in env file) + + +#### Request Format + +```json + { + "messageId": "tdei_record_id", + "messageType": "workflow_identifier", + "data": { + "file_upload_path": "file_upload_path", + "user_id": "user_id", + "tdei_project_group_id": "tdei_project_group_id" + } + } +``` -### How to Setup and run the Tests +#### Response Format + +```json + { + "messageId": "tdei_record_id", + "messageType": "workflow_identifier", + "data": { + "file_upload_path": "file_upload_path", + "user_id": "user_id", + "tdei_project_group_id": "tdei_project_group_id", + "success": true/false, + "message": "message" // if false the error string else empty string + }, + "publishedDate": "published date" + } +``` + + +### How to Set up and run the Tests Make sure you have set up the project properly before running the tests, see above for `How to Setup and Build`. @@ -111,3 +148,4 @@ The format is mentioned in [osw-upload.json](./src/assets/osw-upload.json) The outgoing messages will be to the `osw-validation` topic. The format of the message is at [osw-validation.json](./src/assets/osw-validation.json) + diff --git a/requirements.txt b/requirements.txt index 7a37957..1b4e1ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ uvicorn==0.20.0 coverage==7.2.7 html_testRunner==1.2.1 httpx==0.24.1 -python-osw-validation==0.0.3 \ No newline at end of file +python-osw-validation==0.0.5 \ No newline at end of file diff --git a/src/assets/osw-upload.json b/src/assets/osw-upload.json index 09ce62b..15e722e 100644 --- a/src/assets/osw-upload.json +++ b/src/assets/osw-upload.json @@ -1,76 +1,9 @@ { - "messageType": "osw-upload", - "publishedDate": "2023-02-08T08:33:36.267213Z", + "messageId": "c8c76e89f30944d2b2abd2491bd95337", + "messageType": "workflow_identifier", "data": { - "stage": "OSW-Upload", - "request": { - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "collected_by": "6D3E5B8C-FB16-4B6A-9436-72FD24756CC9", - "collection_date": "2022-11-22T09:43:07.978Z", - "collection_method": "manual", - "publication_date": "2022-11-22T09:43:07.978Z", - "data_source": "local", - "polygon": { - "coordinates": [ - [ - [ - 77.5873101438346, - 12.975857172137523 - ], - [ - 77.58650666918095, - 12.97272532145334 - ], - [ - 77.5869485802404, - 12.970219812510848 - ], - [ - 77.58739049129997, - 12.967792576658127 - ], - [ - 77.5886760507459, - 12.967753427498707 - ], - [ - 77.58911796180547, - 12.969123644412946 - ], - [ - 77.59016247885529, - 12.972921063276544 - ], - [ - 77.58984108899386, - 12.973429991296015 - ], - [ - 77.5904035212514, - 12.974995917131267 - ], - [ - 77.58863587701325, - 12.975074213164191 - ], - [ - 77.5873101438346, - 12.975857172137523 - ] - ] - ] - }, - "osw_schema_version": "1.0.0" - }, - "meta": { - "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip" - }, - "response": { - "success": true, - "message": "File uploaded for the Project Group : 0b41ebc5-350c-42d3-90af-3af4ad3628fb with tdei record id : c8c76e89f30944d2b2abd2491bd95337" - }, - "tdei_record_id": "c8c76e89f30944d2b2abd2491bd95337", - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab" + "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip", + "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab", + "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb" } } \ No newline at end of file diff --git a/src/assets/osw-validation.json b/src/assets/osw-validation.json index 5f6adf9..1a72f45 100644 --- a/src/assets/osw-validation.json +++ b/src/assets/osw-validation.json @@ -1,78 +1,11 @@ { - "messageType": "osw-validation", - "publishedDate": "2023-02-08T08:33:36.267213Z", - "data": { - "stage": "OSW-Validation", - "request": { - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "collected_by": "6D3E5B8C-FB16-4B6A-9436-72FD24756CC9", - "collection_date": "2022-11-22T09:43:07.978Z", - "collection_method": "manual", - "valid_from": "2022-11-22T09:43:07.978Z", - "valid_to": "2022-11-22T09:43:07.978Z", - "data_source": "local", - "polygon": { - "coordinates": [ - [ - [ - 77.5873101438346, - 12.975857172137523 - ], - [ - 77.58650666918095, - 12.97272532145334 - ], - [ - 77.5869485802404, - 12.970219812510848 - ], - [ - 77.58739049129997, - 12.967792576658127 - ], - [ - 77.5886760507459, - 12.967753427498707 - ], - [ - 77.58911796180547, - 12.969123644412946 - ], - [ - 77.59016247885529, - 12.972921063276544 - ], - [ - 77.58984108899386, - 12.973429991296015 - ], - [ - 77.5904035212514, - 12.974995917131267 - ], - [ - 77.58863587701325, - 12.975074213164191 - ], - [ - 77.5873101438346, - 12.975857172137523 - ] - ] - ] - }, - "osw_schema_version": "1.0.0" - }, - "meta": { - "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/2023%2FFEBRUARY%2F0b41ebc5-350c-42d3-90af-3af4ad3628fb%2Fvalid_c8c76e89f30944d2b2abd2491bd95337.zip", - "isValid": true - }, - "response": { - "success": true, - "message": "Validation successful" - }, - "tdei_record_id": "c8c76e89f30944d2b2abd2491bd95337", - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab" - } + "messageId": "c8c76e89f30944d2b2abd2491bd95337", + "messageType": "workflow_identifier", + "data": { + "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip", + "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab", + "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", + "success": true, + "message": "" + } } \ No newline at end of file diff --git a/src/config.py b/src/config.py index c6396c6..3e1accb 100644 --- a/src/config.py +++ b/src/config.py @@ -7,9 +7,9 @@ class EventBusSettings: connection_string: str = os.environ.get('QUEUECONNECTION', None) - upload_topic: str = os.environ.get('UPLOAD_TOPIC', None) - upload_subscription: str = os.environ.get('UPLOAD_SUBSCRIPTION', None) - validation_topic: str = os.environ.get('VALIDATION_TOPIC', None) + upload_topic: str = os.environ.get('VALIDATION_REQ_TOPIC', None) + upload_subscription: str = os.environ.get('VALIDATION_REQ_SUB', None) + validation_topic: str = os.environ.get('VALIDATION_RES_TOPIC', None) container_name: str = os.environ.get('CONTAINER_NAME', 'osw') diff --git a/src/models/queue_message_content.py b/src/models/queue_message_content.py index 4b13e11..aad3f7d 100644 --- a/src/models/queue_message_content.py +++ b/src/models/queue_message_content.py @@ -13,7 +13,6 @@ def __init__(self, data: dict): self._message = data.get('message', None) self._message_type = data.get('messageType', None) self._message_id = data.get('messageId', '') - self._published_date = data.get('publishedDate', None) self.data = UploadData(data=upload_data) if upload_data else {} @property @@ -40,14 +39,6 @@ def message_id(self): def message_id(self, value): self._message_id = value - @property - def published_date(self): - return self._published_date - - @published_date.setter - def published_date(self, value): - self._published_date = value - def to_json(self): self.data = self.data.to_json() return to_json(self.__dict__) @@ -66,30 +57,17 @@ def data_from(self): class UploadData: def __init__(self, data: dict): - polygon = data.get('polygon', None) - request = data.get('request', None) - meta = data.get('meta', None) - - response = data.get('response', None) - self._stage = data.get('stage', '') - self.request = Request(data=request) if request else {} - self.meta = Meta(data=meta) if meta else {} - self.response = Response(data=response) if response else {} - self._tdei_record_id = data.get('tdei_record_id', '') + self._file_upload_path = data.get('file_upload_path', '') self._tdei_project_group_id = data.get('tdei_project_group_id', '') self._user_id = data.get('user_id', '') + self._success = data.get('success', False) + self._message = data.get('message', '') @property - def stage(self): return self._stage - - @stage.setter - def stage(self, value): self._stage = value - - @property - def tdei_record_id(self): return self._tdei_record_id + def file_upload_path(self): return self._file_upload_path - @tdei_record_id.setter - def tdei_record_id(self, value): self._tdei_record_id = value + @file_upload_path.setter + def file_upload_path(self, value): self._file_upload_path = value @property def tdei_project_group_id(self): return self._tdei_project_group_id @@ -103,105 +81,6 @@ def user_id(self): return self._user_id @user_id.setter def user_id(self, value): self._user_id = value - def to_json(self): - self.request = to_json(self.request.__dict__) - self.meta = to_json(self.meta.__dict__) - self.response = to_json(self.response.__dict__) - return to_json(self.__dict__) - - -class Request: - def __init__(self, data: dict): - self._tdei_project_group_id = data.get('tdei_project_group_id', '') - self._collected_by = data.get('collected_by', '') - self._collection_date = data.get('collection_date', '') - self._collection_method = data.get('collection_method', '') - self._publication_date = data.get('publication_date', '') - self._data_source = data.get('data_source', '') - self._polygon = data.get('polygon', {}) - self._osw_schema_version = data.get('osw_schema_version', '') - - @property - def tdei_project_group_id(self): return self._tdei_project_group_id - - @tdei_project_group_id.setter - def tdei_project_group_id(self, value): self._tdei_project_group_id = value - - @property - def collected_by(self): return self._collected_by - - @collected_by.setter - def collected_by(self, value): self._collected_by = value - - @property - def collection_date(self): return self._collection_date - - @collection_date.setter - def collection_date(self, value): self._collection_date = value - - @property - def collection_method(self): return self._collection_method - - @collection_method.setter - def collection_method(self, value): self._collection_method = value - - @property - def data_source(self): return self._data_source - - @data_source.setter - def data_source(self, value): self._data_source = value - - @property - def polygon(self): return self._polygon - - @polygon.setter - def polygon(self, value): self._polygon = value - - @property - def publication_date(self): return self._publication_date - - @publication_date.setter - def publication_date(self, value): self._publication_date = value - - @property - def osw_schema_version(self): return self._osw_schema_version - - @osw_schema_version.setter - def osw_schema_version(self, value): self._osw_schema_version = value - - -class Meta: - def __init__(self, data: dict): - self._file_upload_path = data.get('file_upload_path', '') - self._isValid = False - self._validationMessage = '' - self.validationTime = 90 - - @property - def file_upload_path(self): return self._file_upload_path - - @file_upload_path.setter - def file_upload_path(self, value): self._file_upload_path = value - - @property - def isValid(self): return self._isValid - - @isValid.setter - def isValid(self, value): self._isValid = value - - @property - def validationMessage(self): return self._validationMessage - - @validationMessage.setter - def validationMessage(self, value): self._validationMessage = value - - -class Response: - - def __init__(self, data: dict): - self._success = data.get('success', False) - self._message = data.get('message', '') - @property def success(self): return self._success @@ -214,6 +93,9 @@ def message(self): return self._message @message.setter def message(self, value): self._message = value + def to_json(self): + return to_json(self.__dict__) + def remove_underscore(string: str): return string if not string.startswith('_') else string[1:] diff --git a/src/osw_validator.py b/src/osw_validator.py index e227c4f..fdece3a 100644 --- a/src/osw_validator.py +++ b/src/osw_validator.py @@ -47,25 +47,22 @@ def process(message) -> None: def validate(self, received_message: Upload): tdei_record_id: str = '' try: - tdei_record_id = received_message.data.tdei_record_id + tdei_record_id = received_message.message_id logger.info(f'Received message for : {tdei_record_id} Message received for OSW validation !') - if received_message.data.response.success is False: - error_msg = 'Received failed workflow request' - logger.error(f'{tdei_record_id}, {error_msg} !') - raise Exception(error_msg) - if received_message.data.meta.file_upload_path is None: + if received_message.data.file_upload_path is None: error_msg = 'Request does not have valid file path specified.' logger.error(f'{tdei_record_id}, {error_msg} !') raise Exception(error_msg) - if self.has_permission(roles=['tdei-admin', 'poc', 'osw_data_generator'], - queue_message=received_message) is None: - error_msg = 'Unauthorized request !' - logger.error(tdei_record_id, error_msg, received_message) - raise Exception(error_msg) + if 'VALIDATION_ONLY' not in received_message.message_type: + if self.has_permission(roles=['tdei-admin', 'poc', 'osw_data_generator'], + queue_message=received_message) is None: + error_msg = 'Unauthorized request !' + logger.error(tdei_record_id, error_msg, received_message) + raise Exception(error_msg) - file_upload_path = urllib.parse.unquote(received_message.data.meta.file_upload_path) + file_upload_path = urllib.parse.unquote(received_message.data.file_upload_path) if file_upload_path: validation_result = Validation(file_path=file_upload_path, storage_client=self.storage_client) result = validation_result.validate() @@ -80,26 +77,19 @@ def validate(self, received_message: Upload): self.send_status(result=result, upload_message=received_message) def send_status(self, result: ValidationResult, upload_message: Upload): - upload_message.data.meta.isValid = result.is_valid - upload_message.data.meta.validationMessage = result.validation_message - upload_message.data.stage = 'osw-validation' - - upload_message.data.response.success = result.is_valid - upload_message.data.response.message = str(result.validation_message) + upload_message.data.success = result.is_valid + upload_message.data.message = result.validation_message data = QueueMessage.data_from({ - 'messageId': uuid.uuid1().hex[0:24], - 'message': upload_message.message or 'OSW validation output', - 'messageType': 'osw-validation', - 'data': upload_message.data.to_json(), - 'publishedDate': str(datetime.datetime.now()) + 'messageId': upload_message.message_id, + 'messageType': upload_message.message_type, + 'data': upload_message.data.to_json() }) try: - self.publishing_topic.publish(data=data) except Exception as e: print(e) - logger.info(f'Publishing message for : {upload_message.data.tdei_record_id}') + logger.info(f'Publishing message for : {upload_message.message_id}') def has_permission(self, roles: List[str], queue_message: Upload) -> bool: try: diff --git a/test_report.py b/test_report.py index f93085d..1364dcd 100644 --- a/test_report.py +++ b/test_report.py @@ -2,8 +2,7 @@ import HtmlTestRunner # Define your test cases -from tests.unit_tests.test_queue_message_content import TestUpload, TestUploadData, TestRequest, \ - TestMeta, TestResponse, TestToJson, TestValidationResult +from tests.unit_tests.test_queue_message_content import TestUpload, TestUploadData, TestToJson, TestValidationResult from tests.unit_tests.test_validation import TestSuccessValidation, TestFailureValidation from tests.unit_tests.test_osw_validator import TestOSWValidator from tests.unit_tests.test_main import TestApp @@ -14,9 +13,6 @@ # Add your test cases to the test suite test_suite.addTest(unittest.makeSuite(TestUpload)) test_suite.addTest(unittest.makeSuite(TestUploadData)) - test_suite.addTest(unittest.makeSuite(TestRequest)) - test_suite.addTest(unittest.makeSuite(TestMeta)) - test_suite.addTest(unittest.makeSuite(TestResponse)) test_suite.addTest(unittest.makeSuite(TestToJson)) test_suite.addTest(unittest.makeSuite(TestValidationResult)) test_suite.addTest(unittest.makeSuite(TestSuccessValidation)) diff --git a/tests/integration_tests/osw_integration.py b/tests/integration_tests/osw_integration.py index f50e42a..e0c57f2 100644 --- a/tests/integration_tests/osw_integration.py +++ b/tests/integration_tests/osw_integration.py @@ -10,9 +10,9 @@ # Execute to apply environment variable overrides load_dotenv() -os.environ['UPLOAD_TOPIC'] = 'temp-upload' -os.environ['UPLOAD_SUBSCRIPTION'] = 'upload-validation-processor' -os.environ['VALIDATION_TOPIC'] = 'temp-validation' +os.environ['VALIDATION_REQ_TOPIC'] = 'temp-upload' +os.environ['VALIDATION_REQ_SUB'] = 'upload-validation-processor' +os.environ['VALIDATION_RES_TOPIC'] = 'temp-validation' from src.osw_validator import OSWValidator from python_ms_core import Core @@ -27,9 +27,9 @@ class TestOSWIntegration(unittest.TestCase): @classmethod def setUpClass(cls): cls.core = Core() - cls.upload_topic_name = os.environ['UPLOAD_TOPIC'] - cls.upload_subscription_name = os.environ['UPLOAD_SUBSCRIPTION'] - cls.validation_topic_name = os.environ['VALIDATION_TOPIC'] + cls.upload_topic_name = os.environ['VALIDATION_REQ_TOPIC'] + cls.upload_subscription_name = os.environ['VALIDATION_REQ_SUB'] + cls.validation_topic_name = os.environ['VALIDATION_RES_TOPIC'] def setUp(self): self.test_data = self.read_test_data() diff --git a/tests/test_harness/run_tests.py b/tests/test_harness/run_tests.py index 1e53c26..b88e4f7 100644 --- a/tests/test_harness/run_tests.py +++ b/tests/test_harness/run_tests.py @@ -19,8 +19,8 @@ class Settings(BaseSettings): - publishing_topic_name: str = os.environ.get('UPLOAD_TOPIC', None) - subscription_topic_name: str = os.environ.get('VALIDATION_TOPIC', None) + publishing_topic_name: str = os.environ.get('VALIDATION_REQ_TOPIC', None) + subscription_topic_name: str = os.environ.get('VALIDATION_RES_TOPIC', None) subscription_name: str = 'test_subscribtion' container_name: str = os.environ.get('CONTAINER_NAME', 'tdei-storage-test') diff --git a/tests/test_harness/test_files/osw_test_case1.json b/tests/test_harness/test_files/osw_test_case1.json index 5cfe2c4..73434a0 100644 --- a/tests/test_harness/test_files/osw_test_case1.json +++ b/tests/test_harness/test_files/osw_test_case1.json @@ -1,73 +1,9 @@ { - "stage": "OSW-Validation", - "request": { - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "collected_by": "6D3E5B8C-FB16-4B6A-9436-72FD24756CC9", - "collection_date": "2022-11-22T09:43:07.978Z", - "collection_method": "manual", - "valid_from": "2022-11-22T09:43:07.978Z", - "valid_to": "2022-11-22T09:43:07.978Z", - "data_source": "local", - "polygon": { - "coordinates": [ - [ - [ - 77.5873101438346, - 12.975857172137523 - ], - [ - 77.58650666918095, - 12.97272532145334 - ], - [ - 77.5869485802404, - 12.970219812510848 - ], - [ - 77.58739049129997, - 12.967792576658127 - ], - [ - 77.5886760507459, - 12.967753427498707 - ], - [ - 77.58911796180547, - 12.969123644412946 - ], - [ - 77.59016247885529, - 12.972921063276544 - ], - [ - 77.58984108899386, - 12.973429991296015 - ], - [ - 77.5904035212514, - 12.974995917131267 - ], - [ - 77.58863587701325, - 12.975074213164191 - ], - [ - 77.5873101438346, - 12.975857172137523 - ] - ] - ] - }, - "osw_schema_version": "1.0.0" - }, - "meta": { - "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/invalid.zip" - }, - "response": { - "success": true, - "message": "File uploaded for the Project Group : 0b41ebc5-350c-42d3-90af-3af4ad3628fb with tdei record id : c8c76e89f30944d2b2abd2491bd95337" - }, - "tdei_record_id": "c8c76e89f30944d2b2abd2491bd95337", - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab" - } \ No newline at end of file + "messageId": "c8c76e89f30944d2b2abd2491bd95337", + "messageType": "workflow_identifier", + "data": { + "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/invalid.zip", + "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab", + "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb" + } +} \ No newline at end of file diff --git a/tests/test_harness/test_files/osw_test_case2.json b/tests/test_harness/test_files/osw_test_case2.json index 21fd808..15e722e 100644 --- a/tests/test_harness/test_files/osw_test_case2.json +++ b/tests/test_harness/test_files/osw_test_case2.json @@ -1,73 +1,9 @@ { - "stage": "OSW-Validation", - "request": { - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "collected_by": "6D3E5B8C-FB16-4B6A-9436-72FD24756CC9", - "collection_date": "2022-11-22T09:43:07.978Z", - "collection_method": "manual", - "valid_from": "2022-11-22T09:43:07.978Z", - "valid_to": "2022-11-22T09:43:07.978Z", - "data_source": "local", - "polygon": { - "coordinates": [ - [ - [ - 77.5873101438346, - 12.975857172137523 - ], - [ - 77.58650666918095, - 12.97272532145334 - ], - [ - 77.5869485802404, - 12.970219812510848 - ], - [ - 77.58739049129997, - 12.967792576658127 - ], - [ - 77.5886760507459, - 12.967753427498707 - ], - [ - 77.58911796180547, - 12.969123644412946 - ], - [ - 77.59016247885529, - 12.972921063276544 - ], - [ - 77.58984108899386, - 12.973429991296015 - ], - [ - 77.5904035212514, - 12.974995917131267 - ], - [ - 77.58863587701325, - 12.975074213164191 - ], - [ - 77.5873101438346, - 12.975857172137523 - ] - ] - ] - }, - "osw_schema_version": "1.0.0" - }, - "meta": { - "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip" - }, - "response": { - "success": true, - "message": "File uploaded for the Project Group : 0b41ebc5-350c-42d3-90af-3af4ad3628fb with tdei record id : c8c76e89f30944d2b2abd2491bd95338" - }, - "tdei_record_id": "c8c76e89f30944d2b2abd2491bd95338", - "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb", - "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab" - } \ No newline at end of file + "messageId": "c8c76e89f30944d2b2abd2491bd95337", + "messageType": "workflow_identifier", + "data": { + "file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip", + "user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab", + "tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb" + } +} \ No newline at end of file diff --git a/tests/unit_tests/test_queue_message_content.py b/tests/unit_tests/test_queue_message_content.py index 2fd7013..17422c2 100644 --- a/tests/unit_tests/test_queue_message_content.py +++ b/tests/unit_tests/test_queue_message_content.py @@ -2,7 +2,7 @@ import json import unittest from unittest.mock import MagicMock -from src.models.queue_message_content import ValidationResult, Upload, UploadData, Request, Meta, Response, to_json +from src.models.queue_message_content import ValidationResult, Upload, UploadData, to_json current_dir = os.path.dirname(os.path.abspath(os.path.join(__file__, '../'))) parent_dir = os.path.dirname(current_dir) @@ -19,43 +19,27 @@ def setUp(self): data = TEST_DATA self.upload = Upload(data) - def test_message(self): - self.upload.message = 'New message' - self.assertEqual(self.upload.message, 'New message') - def test_message_type(self): - self.assertEqual(self.upload.message_type, 'osw-upload') + self.assertEqual(self.upload.message_type, 'workflow_identifier') self.upload.message_type = 'New messageType' self.assertEqual(self.upload.message_type, 'New messageType') def test_message_id(self): + self.assertEqual(self.upload.message_id, 'c8c76e89f30944d2b2abd2491bd95337') self.upload.message_id = 'New messageId' self.assertEqual(self.upload.message_id, 'New messageId') - def test_published_date(self): - self.assertEqual(self.upload.published_date, '2023-02-08T08:33:36.267213Z') - self.upload.published_date = '2023-05-24' - self.assertEqual(self.upload.published_date, '2023-05-24') - - def test_data(self): - self.assertIsInstance(self.upload.data, UploadData) - self.assertEqual(self.upload.data.stage, 'OSW-Upload') - self.upload.data.stage = 'Test stage' - self.assertEqual(self.upload.data.stage, 'Test stage') - def test_to_json(self): self.upload.data.to_json = MagicMock(return_value={}) json_data = self.upload.to_json() self.assertIsInstance(json_data, dict) - self.assertEqual(json_data['message_type'], 'osw-upload') - self.assertEqual(json_data['published_date'], '2023-02-08T08:33:36.267213Z') + self.assertEqual(json_data['message_type'], 'workflow_identifier') def test_data_from(self): message = TEST_DATA upload = Upload.data_from(json.dumps(message)) self.assertIsInstance(upload, Upload) - self.assertEqual(upload.message_type, 'osw-upload') - self.assertEqual(upload.published_date, '2023-02-08T08:33:36.267213Z') + self.assertEqual(upload.message_type, 'workflow_identifier') def test_upload_to_json(self): json_data = self.upload.to_json() @@ -68,16 +52,6 @@ def setUp(self): data = TEST_DATA['data'] self.upload_data = UploadData(data) - def test_stage(self): - self.assertEqual(self.upload_data.stage, 'OSW-Upload') - self.upload_data.stage = 'Test stage' - self.assertEqual(self.upload_data.stage, 'Test stage') - - def test_tdei_record_id(self): - self.assertEqual(self.upload_data.tdei_record_id, 'c8c76e89f30944d2b2abd2491bd95337') - self.upload_data.tdei_record_id = 'Test record ID' - self.assertEqual(self.upload_data.tdei_record_id, 'Test record ID') - def test_tdei_project_group_id(self): self.assertEqual(self.upload_data.tdei_project_group_id, '0b41ebc5-350c-42d3-90af-3af4ad3628fb') self.upload_data.tdei_project_group_id = 'Test Project Group ID' @@ -88,86 +62,13 @@ def test_user_id(self): self.upload_data.user_id = 'Test user ID' self.assertEqual(self.upload_data.user_id, 'Test user ID') - -class TestRequest(unittest.TestCase): - - def setUp(self): - data = TEST_DATA['data']['request'] - self.request = Request(data) - - def test_tdei_project_group_id(self): - self.assertEqual(self.request.tdei_project_group_id, '0b41ebc5-350c-42d3-90af-3af4ad3628fb') - self.request.tdei_project_group_id = 'Test Project Group ID' - self.assertEqual(self.request.tdei_project_group_id, 'Test Project Group ID') - - def test_collected_by(self): - self.assertEqual(self.request.collected_by, '6D3E5B8C-FB16-4B6A-9436-72FD24756CC9') - self.request.collected_by = 'Test Collected By' - self.assertEqual(self.request.collected_by, 'Test Collected By') - - def test_collection_date(self): - self.assertEqual(self.request.collection_date, '2022-11-22T09:43:07.978Z') - self.request.collection_date = 'Test Collected Date' - self.assertEqual(self.request.collection_date, 'Test Collected Date') - - def test_collection_method(self): - self.assertEqual(self.request.collection_method, 'manual') - self.request.collection_method = 'Test Collected Method' - self.assertEqual(self.request.collection_method, 'Test Collected Method') - - def test_publication_date(self): - self.assertEqual(self.request.publication_date, '2022-11-22T09:43:07.978Z') - self.request.publication_date = 'Test Publication Date' - self.assertEqual(self.request.publication_date, 'Test Publication Date') - - def test_data_source(self): - self.assertEqual(self.request.data_source, 'local') - self.request.data_source = 'Test Data Source' - self.assertEqual(self.request.data_source, 'Test Data Source') - - def test_polygon(self): - self.request.polygon = { - 'test': 'Polygon' - } - self.assertEqual(self.request.polygon, { - 'test': 'Polygon' - }) - - def test_osw_schema_version(self): - self.assertEqual(self.request.osw_schema_version, '1.0.0') - self.request.osw_schema_version = '1.1.0' - self.assertEqual(self.request.osw_schema_version, '1.1.0') - - -class TestMeta(unittest.TestCase): - - def setUp(self): - data = TEST_DATA['data']['meta'] - self.meta = Meta(data) - - def test_file_upload_path(self): - self.assertEqual(self.meta.file_upload_path, - 'https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip') - self.meta.file_upload_path = 'Test file path' - self.assertEqual(self.meta.file_upload_path, 'Test file path') - - -class TestResponse(unittest.TestCase): - - def setUp(self): - data = TEST_DATA['data']['response'] - self.response = Response(data) - def test_success(self): - self.assertEqual(self.response.success, True) - self.response.success = False - self.assertEqual(self.response.success, False) + self.upload_data.success = True + self.assertEqual(self.upload_data.success, True) def test_message(self): - self.assertEqual(self.response.message, - 'File uploaded for the Project Group : 0b41ebc5-350c-42d3-90af-3af4ad3628fb with tdei record id : c8c76e89f30944d2b2abd2491bd95337') - self.response.message = 'Successful' - self.assertEqual(self.response.message, 'Successful') + self.upload_data.message = 'SOME_MESSAGE' + self.assertEqual(self.upload_data.message, 'SOME_MESSAGE') class TestToJson(unittest.TestCase):