예제 #1
0
def test_short_notify_form_serialize_data(domestic_data):
    office_details = [{
        'is_match': True,
        'name': 'Some Office',
        'email': '*****@*****.**'
    }]
    form = forms.ShortNotifyForm(data=domestic_data)

    assert form.is_valid()
    with requests_mock.mock() as mock:
        mock.get(url_lookup_by_postcode.format(postcode='ABC123'),
                 json=office_details)
        data = form.serialized_data

    assert data == {
        'given_name': 'Test',
        'family_name': 'Example',
        'email': '*****@*****.**',
        'company_type': 'LIMITED',
        'company_type_other': '',
        'organisation_name': 'Example corp',
        'postcode': 'ABC123',
        'comment': 'Help please',
        'dit_regional_office_name': 'Some Office',
        'dit_regional_office_email': '*****@*****.**',
    }
def test_short_notify_form_serialize_data(domestic_data):
    form = forms.ShortNotifyForm(data=domestic_data)

    assert form.is_valid()

    url = api_client.exporting.endpoints['lookup-by-postcode'].format(
        postcode='ABC123'
    )
    office_details = {'name': 'Some Office', 'email': '*****@*****.**'}
    with requests_mock.mock() as mock:
        mock.get(url, json=office_details)
        data = form.serialized_data

    assert data == {
        'given_name': 'Test',
        'family_name': 'Example',
        'email': '*****@*****.**',
        'company_type': 'LIMITED',
        'company_type_other': '',
        'organisation_name': 'Example corp',
        'postcode': 'ABC123',
        'comment': 'Help please',
        'dit_regional_office_name': 'Some Office',
        'dit_regional_office_email': '*****@*****.**',
    }
예제 #3
0
def test_domestic_contact_form_serialize_data_office_lookup_none_returned(
        domestic_data):
    form = forms.ShortNotifyForm(data=domestic_data)

    assert form.is_valid()

    with requests_mock.mock() as mock:
        mock.get(url_lookup_by_postcode.format(postcode='ABC123'), json=None)

    data = form.serialized_data

    assert data['dit_regional_office_name'] == ''
    assert data['dit_regional_office_email'] == ''
예제 #4
0
def test_domestic_contact_form_serialize_data_office_lookup_error(
        domestic_data):
    form = forms.ShortNotifyForm(data=domestic_data)

    assert form.is_valid()

    with requests_mock.mock() as mock:
        mock.get(url_lookup_by_postcode.format(postcode='ABC123'),
                 exc=requests.exceptions.ConnectTimeout)
        data = form.serialized_data

    assert data['dit_regional_office_name'] == ''
    assert data['dit_regional_office_email'] == ''
예제 #5
0
def test_domestic_contact_form_serialize_data_office_lookup_not_found(
    domestic_data
):
    form = forms.ShortNotifyForm(data=domestic_data)

    assert form.is_valid()

    url = api_client.exporting.endpoints['lookup-by-postcode'].format(
        postcode='ABC123'
    )
    with requests_mock.mock() as mock:
        mock.get(url, status_code=404)
        data = form.serialized_data

    assert data['dit_regional_office_name'] == ''
    assert data['dit_regional_office_email'] == ''