Exemple #1
0
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']
                }
            }
        }]
Exemple #2
0
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']
                    }
                }
            }
        }]
Exemple #4
0
def test_case_exists_by_id_fails_gracefully_on_invalid_uuid(
        mock_execute_method):
    # When, then raises
    with pytest.raises(validators.Invalid):
        case_exists_validator = validators.case_exists_by_id()
        case_exists_validator("invalid_uuid",
                              db_connection_pool='db_connection_pool')

    # Then we never try to look up an invalid UUID in the database
    mock_execute_method.assert_not_called()
Exemple #5
0
def test_case_exists_by_id_succeeds(mock_execute_method):
    # Given
    mock_execute_method.return_value = [(1, )]
    # When
    case_exists_validator = validators.case_exists_by_id()

    case_exists_validator(str(uuid.uuid4()),
                          db_connection_pool='db_connection_pool')

    # Then no invalid exception is raised
    mock_execute_method.assert_called_once()
Exemple #6
0
def test_case_exists_by_id_fails(mock_execute_method):
    # Given
    mock_execute_method.return_value = []

    # When, then raises
    with pytest.raises(validators.Invalid):
        case_exists_validator = validators.case_exists_by_id()
        case_exists_validator(str(uuid.uuid4()),
                              db_connection_pool='db_connection_pool')

    # Then
    mock_execute_method.assert_called_once()
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']
                }
            }
        }]
class AddressUpdateProcessor(Processor):
    file_prefix = Config.BULK_ADDRESS_UPDATE_FILE_PREFIX
    routing_key = Config.BULK_ADDRESS_UPDATE_ROUTING_KEY
    exchange = ''
    bucket_name = Config.BULK_ADDRESS_UPDATE_BUCKET_NAME
    project_id = Config.BULK_ADDRESS_UPDATE_PROJECT_ID
    schema = {
        'CASE_ID': [mandatory(), case_exists_by_id()],
        'UPRN': [
            max_length(13),
            numeric(),
            no_padding_whitespace(),
            cant_be_deleted(),
            mandatory_after_update('uprn')
        ],
        'ESTAB_UPRN': [
            max_length(13),
            numeric(),
            no_padding_whitespace(),
            cant_be_deleted(),
            mandatory_after_update('estab_uprn')
        ],
        'ESTAB_TYPE':
        [mandatory(),
         in_set(Config.ESTAB_TYPES, label='ESTAB_TYPE')],
        'ABP_CODE': [
            max_length(6),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted(),
            mandatory_after_update('abp_code')
        ],
        'ORGANISATION_NAME': [
            max_length(60),
            no_padding_whitespace(),
            no_pipe_character(),
            check_delete_keyword()
        ],
        'ADDRESS_LINE1': [
            max_length(60),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted(),
            mandatory_after_update('address_line1')
        ],
        'ADDRESS_LINE2': [
            max_length(60),
            no_padding_whitespace(),
            no_pipe_character(),
            check_delete_keyword()
        ],
        'ADDRESS_LINE3': [
            max_length(60),
            no_padding_whitespace(),
            no_pipe_character(),
            check_delete_keyword()
        ],
        'TOWN_NAME': [
            max_length(30),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted(),
            mandatory_after_update('town_name')
        ],
        'POSTCODE': [
            max_length(8),
            no_padding_whitespace(),
            cant_be_deleted(),
            alphanumeric_postcode(),
            no_pipe_character(),
            mandatory_after_update('postcode')
        ],
        'LATITUDE': [
            mandatory(),
            latitude_longitude(max_scale=7, max_precision=9),
            cant_be_deleted(),
            no_padding_whitespace(),
            no_pipe_character(),
            latitude_longitude_range()
        ],
        'LONGITUDE': [
            mandatory(),
            latitude_longitude(max_scale=7, max_precision=8),
            cant_be_deleted(),
            no_padding_whitespace(),
            no_pipe_character(),
            latitude_longitude_range()
        ],
        'OA': [
            mandatory(),
            max_length(9),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'LSOA': [
            mandatory(),
            max_length(9),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'MSOA': [
            mandatory(),
            max_length(9),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'LAD': [
            mandatory(),
            max_length(9),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'HTC_WILLINGNESS': [
            in_set({'0', '1', '2', '3', '4', '5'}, label='HTC_WILLINGNESS'),
            mandatory_after_update('htc_willingness')
        ],
        'HTC_DIGITAL': [
            in_set({'0', '1', '2', '3', '4', '5'}, label='HTC_DIGITAL'),
            mandatory_after_update('htc_digital')
        ],
        'TREATMENT_CODE':
        [mandatory(),
         in_set(Config.TREATMENT_CODES, label='TREATMENT_CODE')],
        'FIELDCOORDINATOR_ID': [
            mandatory(),
            max_length(10),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'FIELDOFFICER_ID': [
            mandatory(),
            max_length(13),
            no_padding_whitespace(),
            no_pipe_character(),
            cant_be_deleted()
        ],
        'CE_EXPECTED_CAPACITY':
        [numeric(), max_length(4),
         no_padding_whitespace()],
        'CE_SECURE': [
            optional_in_set({'0', '1'}, label='CE_SECURE'),
            no_padding_whitespace()
        ],
        'PRINT_BATCH': [
            no_padding_whitespace(),
            numeric_2_digit_or_delete(),
            check_delete_keyword()
        ]
    }

    def build_event_messages(self, row):
        event_message = {
            "event": {
                "type": "RM_CASE_UPDATED",
                "source": "RM_BULK_ADDRESS_UPDATE_PROCESSOR",
                "channel": address_resolution,
                "dateTime": datetime.utcnow().isoformat() + 'Z',
                "transactionId": str(uuid.uuid4())
            },
            "payload": {
                "rmCaseUpdated": {
                    # Set the mandatory values up front
                    'caseId': row['CASE_ID'],
                    'treatmentCode': row['TREATMENT_CODE'],
                    'estabType': row['ESTAB_TYPE'],
                    'oa': row['OA'],
                    'lsoa': row['LSOA'],
                    'msoa': row['MSOA'],
                    'lad': row['LAD'],
                    'fieldCoordinatorId': row['FIELDCOORDINATOR_ID'],
                    'fieldOfficerId': row['FIELDOFFICER_ID'],
                    'latitude': row['LATITUDE'],
                    'longitude': row['LONGITUDE'],
                }
            }
        }

        # Set the optional values if present
        event_message = set_optional_values_if_present(row, event_message)

        # Set the deletable fields
        event_message = set_deleteable_fields(row, event_message)

        return [event_message]