Ejemplo n.º 1
0
def test_in_set_invalid():
    # Given
    in_set_validator = validators.in_set({'a'}, label=test_label)

    # When, then raises
    with pytest.raises(validators.Invalid):
        in_set_validator('abc')
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']
                    }
                }
            }
        }]
Ejemplo n.º 3
0
def test_in_set_valid():
    # Given
    in_set_validator = validators.in_set({'a', 'b', 'c'}, label=test_label)

    # When
    in_set_validator('a')
    in_set_validator('b')
    in_set_validator('c')
Ejemplo n.º 4
0
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 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]