def send_agent_message(self, form_data):
     sender = Sender(email_address=form_data['email'], country_code=None)
     action = actions.EmailAction(
         recipients=[form_data['region_office_email']],
         subject=settings.CONTACT_EXPORTING_AGENT_SUBJECT,
         reply_to=[settings.DEFAULT_FROM_EMAIL],
         form_url=reverse(
             'contact-us-export-advice', kwargs={'step': 'comment'}
         ),
         form_session=self.form_session,
         sender=sender,
     )
     template_name = 'contact/exporting-from-uk-agent-email.html'
     html = render_to_string(template_name, {'form_data': form_data})
     response = action.save(
         {'text_body': strip_tags(html), 'html_body': html}
     )
     response.raise_for_status()
def test_email_action_mixin_action_class(settings, form_session, spam_control,
                                         sender):

    mock_client = mock.Mock(spec_set=client.APIFormsClient)
    action = actions.EmailAction(
        recipients=['*****@*****.**'],
        client=mock_client,
        subject='a subject',
        reply_to=['*****@*****.**'],
        form_url='/the/form/',
        form_session=form_session,
        spam_control=spam_control,
        sender=sender,
    )

    action.save({'field_one': 'value one', 'field_two': 'value two'})

    assert mock_client.submit_generic.call_count == 1
    assert mock_client.submit_generic.call_args == mock.call({
        'data': {
            'field_one': 'value one',
            'field_two': 'value two'
        },
        'meta': {
            'action_name': 'email',
            'recipients': ['*****@*****.**'],
            'reply_to': ['*****@*****.**'],
            'subject': 'a subject',
            'form_url': '/the/form/',
            'funnel_steps': ['one', 'two'],
            'ingress_url': 'example.com',
            'sender': {
                'email_address': '*****@*****.**',
                'country_code': 'UK',
                'ip_address': '192.168.0.1',
            },
            'spam_control': {
                'contents': ['hello buy my goods'],
            }
        }
    })