Exemplo n.º 1
0
def send_verification_letter(company):
    recipient = {
        'postal_full_name':
        company.postal_full_name,
        'address_line_1':
        company.address_line_1,
        'address_line_2':
        company.address_line_2,
        'locality':
        company.locality,
        'country':
        company.country,
        'postal_code':
        company.postal_code,
        'po_box':
        company.po_box,
        'custom_fields': [
            ('full_name', company.postal_full_name),
            ('company_name', company.name),
            ('verification_code', company.verification_code),
            ('date', datetime.date.today().strftime('%d/%m/%Y')),
            ('company', company.name),
        ]
    }

    stannp_client.send_letter(
        template=settings.STANNP_VERIFICATION_LETTER_TEMPLATE_ID,
        recipient=recipient)

    company.is_verification_letter_sent = True
    company.date_verification_letter_sent = timezone.now()
    company.save()
Exemplo n.º 2
0
def test_send_letter_not_ok_response_send_message_to_sentry(
        mock_requests, mock_raven_client, stannp_not_ok_response):
    mock_requests.post.return_value = stannp_not_ok_response
    stannp_client.send_letter(
        template='whatever',
        recipient={
            'postal_full_name':
            'test_postal_full_name',
            'address_line_1':
            'test_address_line_1',
            'address_line_2':
            'test_address_line_2',
            'locality':
            'test_locality',
            'postal_code':
            'test_postal_code',
            'country':
            'test_country',
            'custom_fields': [
                ('test_field_name1', 'test_value1'),
                ('test_field_name2', 'test_value2'),
            ]
        },
    )
    assert mock_raven_client.captureMessage.call_count == 1
    assert mock_raven_client.captureMessage.call_args == call(
        b'Insufficient credit', stack=True)
Exemplo n.º 3
0
def test_send_letter(mock_post, stannp_200_response):
    mock_post.return_value = stannp_200_response

    stannp_client.send_letter(
        template='whatever',
        recipient={
            'postal_full_name':
            'test_postal_full_name',
            'address_line_1':
            'test_address_line_1',
            'address_line_2':
            'test_address_line_2',
            'locality':
            'test_locality',
            'postal_code':
            'test_postal_code',
            'country':
            'test_country',
            'custom_fields': [
                ('test_field_name1', 'test_value1'),
                ('test_field_name2', 'test_value2'),
            ]
        },
    )

    assert mock_post.call_count == 1
    assert mock_post.call_args == call(
        'https://dash.stannp.com/api/v1/letters/create',
        auth=('debug', ''),
        data={
            'recipient[address2]': 'test_address_line_2',
            'recipient[test_field_name1]': 'test_value1',
            'template': 'whatever',
            'recipient[country]': 'test_country',
            'recipient[postcode]': 'test_postal_code',
            'test': True,
            'recipient[title]': 'test_postal_full_name',
            'recipient[address1]': 'test_address_line_1',
            'recipient[city]': 'test_locality',
            'recipient[test_field_name2]': 'test_value2'
        })
Exemplo n.º 4
0
def test_send_letter():
    with mock.patch('requests.post') as mock_requests:
        stannp_client.send_letter(
            template='whatever',
            recipient={
                'postal_full_name':
                'test_postal_full_name',
                'address_line_1':
                'test_address_line_1',
                'address_line_2':
                'test_address_line_2',
                'locality':
                'test_locality',
                'postal_code':
                'test_postal_code',
                'country':
                'test_country',
                'custom_fields': [
                    ('test_field_name1', 'test_value1'),
                    ('test_field_name2', 'test_value2'),
                ]
            },
        )

    mock_requests.assert_called_once_with(
        'https://dash.stannp.com/api/v1/letters/create',
        auth=('debug', ''),
        data={
            'recipient[address2]': 'test_address_line_2',
            'recipient[test_field_name1]': 'test_value1',
            'template': 'whatever',
            'recipient[country]': 'test_country',
            'recipient[postcode]': 'test_postal_code',
            'test': True,
            'recipient[title]': 'test_postal_full_name',
            'recipient[address1]': 'test_address_line_1',
            'recipient[city]': 'test_locality',
            'recipient[test_field_name2]': 'test_value2'
        })
Exemplo n.º 5
0
def send_verification_letter(company, form_url=None):
    if settings.FEATURE_VERIFICATION_LETTERS_VIA_GOVNOTIFY_ENABLED:
        recipient = extract_recipient_address_gov_notify(company)
        recipient['verification_code'] = company.verification_code

        action = actions.GovNotifyLetterAction(
            template_id=settings.GOVNOTIFY_VERIFICATION_LETTER_TEMPLATE_ID,
            form_url=form_url,

        )
        action.save(recipient)

    else:
        recipient = {
            'postal_full_name': company.postal_full_name,
            'address_line_1': company.address_line_1,
            'address_line_2': company.address_line_2,
            'locality': company.locality,
            'country': company.country,
            'postal_code': company.postal_code,
            'po_box': company.po_box,
            'custom_fields': [
                ('full_name', company.postal_full_name),
                ('company_name', company.name),
                ('verification_code', company.verification_code),
                ('date', datetime.date.today().strftime('%d/%m/%Y')),
                ('company', company.name),
            ]
        }

        stannp_client.send_letter(
            template=settings.STANNP_VERIFICATION_LETTER_TEMPLATE_ID,
            recipient=recipient
        )

    company.is_verification_letter_sent = True
    company.date_verification_letter_sent = timezone.now()
    company.save()