Exemple #1
0
def test_lat_long_valid():
    # Given
    lat_long_validator = validators.latitude_longitude(max_scale=5,
                                                       max_precision=10)

    # When
    lat_long_validator('1234.5678')
Exemple #2
0
def test_lat_long_invalid_precision():
    # Given
    lat_long_validator = validators.latitude_longitude(max_scale=10,
                                                       max_precision=5)

    # When, then raises
    with pytest.raises(validators.Invalid):
        lat_long_validator('123456.7')
Exemple #3
0
def test_lat_long_invalid_scale():
    # Given
    lat_long_validator = validators.latitude_longitude(max_scale=5,
                                                       max_precision=10)

    # When, then raises
    with pytest.raises(validators.Invalid):
        lat_long_validator('1.567889')
Exemple #4
0
def test_lat_long_malformed_decimal():
    # Given
    lat_long_validator = validators.latitude_longitude(max_scale=5,
                                                       max_precision=10)

    # When, then raises
    with pytest.raises(validators.Invalid):
        lat_long_validator('1')
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]