def test_correct_action_for_insert():
    field_vals = ['I' if f == 'change_type' else f for f in DPA._fields]
    dpa = DPA(*field_vals)
    blpu = BLPU_COORDINATES_ONLY(x_coordinate=12.34, y_coordinate=56.78)
    entry_datetime = '2015-03-05T12:00:00'
    actions = make_es_actions(dpa, blpu, entry_datetime)

    expected_actions = [
        {
            '_op_type': 'index',
            '_index': 'address-search-api-index',
            '_type': 'address_by_joined_fields',
            '_id': 'uprn',
            '_source': {
                'building_name': 'building_name',
                'building_number': 'building_number',
                'department_name': 'department_name',
                'dependent_locality': 'dependent_locality',
                'dependent_thoroughfare_name': 'dependent_thoroughfare_name',
                'double_dependent_locality': 'double_dependent_locality',
                'entry_datetime': '2015-03-05T12:00:00',
                'joined_fields': 'sub_building_name, building_name, building_number, dependent_thoroughfare_name, thoroughfare_name, double_dependent_locality, dependent_locality, post_town, postcode',
                'postcode': 'postcode',
                'organisation_name': 'organisation_name',
                'post_town': 'post_town',
                'sub_building_name': 'sub_building_name',
                'thoroughfare_name': 'thoroughfare_name',
                'uprn': 'uprn',
                'x_coordinate': 12.34,
                'y_coordinate': 56.78,
            },
        },
        {
            '_op_type': 'index',
            '_index': 'address-search-api-index',
            '_type': 'address_by_postcode',
            '_id': 'uprn',
            '_source': {
                'building_name': 'building_name',
                'building_number': 'building_number',
                'department_name': 'department_name',
                'dependent_locality': 'dependent_locality',
                'dependent_thoroughfare_name': 'dependent_thoroughfare_name',
                'double_dependent_locality': 'double_dependent_locality',
                'entry_datetime': '2015-03-05T12:00:00',
                'joined_fields': 'sub_building_name, building_name, building_number, dependent_thoroughfare_name, thoroughfare_name, double_dependent_locality, dependent_locality, post_town, postcode',
                'postcode': 'postcode',
                'organisation_name': 'organisation_name',
                'post_town': 'post_town',
                'sub_building_name': 'sub_building_name',
                'thoroughfare_name': 'thoroughfare_name',
                'uprn': 'uprn',
                'x_coordinate': 12.34,
                'y_coordinate': 56.78,
            },
        },
    ]

    assert len(actions) == len(expected_actions)
    assert all(action in expected_actions for action in actions)
示例#2
0
def test_correct_action_for_delete():
    field_vals = ['D' if f == 'change_type' else f for f in DPA._fields]
    dpa = DPA(*field_vals)
    blpu = BLPU_COORDINATES_ONLY(x_coordinate=12.34, y_coordinate=56.78)
    entry_datetime = '2015-03-05T12:00:00'
    actions = make_es_actions(dpa, blpu, entry_datetime)

    expected_actions = [
        {
            '_op_type': 'delete',
            '_index': 'address-search-api-index',
            '_type': 'address_by_joined_fields',
            '_id': 'uprn',
        },
        {
            '_op_type': 'delete',
            '_index': 'address-search-api-index',
            '_type': 'address_by_postcode',
            '_id': 'uprn',
        },
    ]

    assert len(actions) == len(expected_actions)
    assert all(action in expected_actions for action in actions)
def test_correct_action_for_delete():
    field_vals = ['D' if f == 'change_type' else f for f in DPA._fields]
    dpa = DPA(*field_vals)
    blpu = BLPU_COORDINATES_ONLY(x_coordinate=12.34, y_coordinate=56.78)
    entry_datetime = '2015-03-05T12:00:00'
    actions = make_es_actions(dpa, blpu, entry_datetime)

    expected_actions = [
        {
            '_op_type': 'delete',
            '_index': 'address-search-api-index',
            '_type': 'address_by_joined_fields',
            '_id': 'uprn',
        },
        {
            '_op_type': 'delete',
            '_index': 'address-search-api-index',
            '_type': 'address_by_postcode',
            '_id': 'uprn',
        },
    ]

    assert len(actions) == len(expected_actions)
    assert all(action in expected_actions for action in actions)
示例#4
0
def test_correct_action_for_update():
    field_vals = ['U' if f == 'change_type' else f for f in DPA._fields]
    dpa = DPA(*field_vals)
    blpu = BLPU_COORDINATES_ONLY(x_coordinate=12.34, y_coordinate=56.78)
    entry_datetime = '2015-03-05T12:00:00'
    actions = make_es_actions(dpa, blpu, entry_datetime)

    expected_actions = [
        {
            '_op_type': 'update',
            '_index': 'address-search-api-index',
            '_type': 'address_by_joined_fields',
            '_id': 'uprn',
            'doc': {
                'building_name': 'building_name',
                'building_number': 'building_number',
                'department_name': 'department_name',
                'dependent_locality': 'dependent_locality',
                'dependent_thoroughfare_name': 'dependent_thoroughfare_name',
                'double_dependent_locality': 'double_dependent_locality',
                'entry_datetime': '2015-03-05T12:00:00',
                'joined_fields':
                'sub_building_name, building_name, building_number, dependent_thoroughfare_name, thoroughfare_name, double_dependent_locality, dependent_locality, post_town, postcode',
                'postcode': 'postcode',
                'organisation_name': 'organisation_name',
                'post_town': 'post_town',
                'sub_building_name': 'sub_building_name',
                'thoroughfare_name': 'thoroughfare_name',
                'uprn': 'uprn',
                'x_coordinate': 12.34,
                'y_coordinate': 56.78,
            },
        },
        {
            '_op_type': 'update',
            '_index': 'address-search-api-index',
            '_type': 'address_by_postcode',
            '_id': 'uprn',
            'doc': {
                'building_name': 'building_name',
                'building_number': 'building_number',
                'department_name': 'department_name',
                'dependent_locality': 'dependent_locality',
                'dependent_thoroughfare_name': 'dependent_thoroughfare_name',
                'double_dependent_locality': 'double_dependent_locality',
                'entry_datetime': '2015-03-05T12:00:00',
                'joined_fields':
                'sub_building_name, building_name, building_number, dependent_thoroughfare_name, thoroughfare_name, double_dependent_locality, dependent_locality, post_town, postcode',
                'postcode': 'postcode',
                'organisation_name': 'organisation_name',
                'post_town': 'post_town',
                'sub_building_name': 'sub_building_name',
                'thoroughfare_name': 'thoroughfare_name',
                'uprn': 'uprn',
                'x_coordinate': 12.34,
                'y_coordinate': 56.78,
            },
        },
    ]

    assert len(actions) == len(expected_actions)
    assert all(action in expected_actions for action in actions)