class QidLinkProcessor(Processor): file_prefix = Config.BULK_QID_LINK_FILE_PREFIX routing_key = Config.BULK_QID_LINK_ROUTING_KEY exchange = Config.EVENTS_EXCHANGE bucket_name = Config.BULK_QID_LINK_BUCKET_NAME project_id = Config.BULK_QID_LINK_PROJECT_ID schema = { "case_id": [is_uuid(), case_exists_by_id()], "qid": [qid_exists(), qid_linked_to_correct_survey_type()] } def build_event_messages(self, row): return [{ "event": { "type": "QUESTIONNAIRE_LINKED", "source": "RM_QID_LINK_PROCESSOR", "channel": "RM", "dateTime": datetime.utcnow().isoformat() + 'Z', "transactionId": str(uuid.uuid4()) }, "payload": { "uac": { "questionnaireId": row['qid'], "caseId": row['case_id'] } } }]
class InvalidAddressProcessor(Processor): file_prefix = Config.BULK_INVALID_ADDRESS_FILE_PREFIX routing_key = Config.INVALID_ADDRESS_EVENT_ROUTING_KEY exchange = Config.EVENTS_EXCHANGE bucket_name = Config.BULK_INVALID_ADDRESS_BUCKET_NAME project_id = Config.BULK_INVALID_ADDRESS_PROJECT_ID schema = { "case_id": [is_uuid(), case_exists_by_id()], "reason": [mandatory(), max_length(255)] } def build_event_messages(self, row): address_resolution = "AR" return [{ "event": { "type": "ADDRESS_NOT_VALID", "source": "RM_BULK_INVALID_ADDRESS_PROCESSOR", "channel": address_resolution, "dateTime": datetime.utcnow().isoformat() + 'Z', "transactionId": str(uuid.uuid4()) }, "payload": { "invalidAddress": { "reason": row['reason'], "collectionCase": { "id": row['case_id'] } } } }]
class RefusalProcessor(Processor): file_prefix = Config.BULK_REFUSAL_FILE_PREFIX routing_key = Config.REFUSAL_EVENT_ROUTING_KEY exchange = Config.EVENTS_EXCHANGE bucket_name = Config.BULK_REFUSAL_BUCKET_NAME project_id = Config.BULK_REFUSAL_PROJECT_ID schema = { "case_id": [is_uuid(), case_exists_by_id()], "refusal_type": [in_set({"HARD_REFUSAL", "EXTRAORDINARY_REFUSAL"}, label='refusal types')] } def build_event_messages(self, row): return [{ "event": { "type": "REFUSAL_RECEIVED", "source": "RM_BULK_REFUSAL_PROCESSOR", "channel": "RM", "dateTime": datetime.utcnow().isoformat() + 'Z', "transactionId": str(uuid.uuid4()) }, "payload": { "refusal": { "type": row['refusal_type'], "collectionCase": { "id": row['case_id'] } } } }]
def test_is_uuid(value, is_valid): is_uuid_validator = validators.is_uuid() if is_valid: # No exception should be raised is_uuid_validator(value) else: with pytest.raises(validators.Invalid): is_uuid_validator(value)
class NonComplianceProcessor(Processor): file_prefix = Config.BULK_NON_COMPLIANCE_FILE_PREFIX routing_key = Config.BULK_NON_COMPLIANCE_ROUTING_KEY exchange = '' bucket_name = Config.BULK_NON_COMPLIANCE_BUCKET_NAME project_id = Config.BULK_NON_COMPLIANCE_PROJECT_ID schema = { "CASE_ID": [is_uuid(), hh_case_exists_by_id()], "NC_STATUS": [in_set({"NCL", "NCF", "NCFW"}, label='non-compliance status')], "FIELDCOORDINATOR_ID": [ max_length(10), no_padding_whitespace(), no_pipe_character(), alphanumeric_plus_hyphen_field_values_ignore_empty_strings() ], "FIELDOFFICER_ID": [ max_length(13), no_padding_whitespace(), no_pipe_character(), alphanumeric_plus_hyphen_field_values_ignore_empty_strings() ] } def build_event_messages(self, row): return [{ "event": { "type": "SELECTED_FOR_NON_COMPLIANCE", "source": "NON_COMPLIANCE", "channel": "NC", "dateTime": datetime.utcnow().isoformat() + 'Z', "transactionId": str(uuid.uuid4()) }, "payload": { "collectionCase": { "id": row['CASE_ID'], "fieldCoordinatorId": row['FIELDCOORDINATOR_ID'], "fieldOfficerId": row['FIELDOFFICER_ID'], "nonComplianceStatus": row['NC_STATUS'], } } }]
class UnInvalidateAddressProcessor(Processor): file_prefix = Config.BULK_UNINVALIDATED_ADDRESS_FILE_PREFIX routing_key = Config.UNINVALIDATED_ADDRESS_EVENT_ROUTING_KEY exchange = '' bucket_name = Config.BULK_UNINVALIDATED_ADDRESS_BUCKET_NAME project_id = Config.BULK_UNINVALIDATED_ADDRESS_PROJECT_ID schema = {"CASE_ID": [is_uuid(), case_exists_by_id()]} def build_event_messages(self, row): address_resolution = "AR" return [{ "event": { "type": "RM_UNINVALIDATE_ADDRESS", "source": "RM_UNINVALIDATE_ADDRESS_PROCESSOR", "channel": address_resolution, "dateTime": datetime.utcnow().isoformat() + 'Z', "transactionId": str(uuid.uuid4()) }, "payload": { "rmUnInvalidateAddress": { "caseId": row['CASE_ID'] } } }]