Exemple #1
0
def test_contact_page_agent_email_utm_codes(mock_clean_captcha,
                                            contact_request, contact_form_data,
                                            settings):
    mail.outbox = []

    settings.IIGB_AGENT_EMAIL = "*****@*****.**"

    utm_codes = {
        'utm_source': 'test_source',
        'utm_medium': 'test_medium',
        'utm_campaign': 'test_campaign',
        'utm_term': 'test_term',
        'utm_content': 'test_content'
    }

    contact_request.utm = utm_codes

    ContactFormView.as_view()(contact_request)

    assert len(mail.outbox) == 2

    if mail.outbox[0].to == [settings.IIGB_AGENT_EMAIL]:
        agent_email = mail.outbox[0]
    else:
        agent_email = mail.outbox[1]

    body = agent_email.alternatives[0][0]
    for code, value in utm_codes.items():
        assert f"{code}: {value}" in body, code
Exemple #2
0
def test_contact_form(mock_clean_captcha, contact_request, contact_form_data,
                      settings):

    mail.outbox = []

    settings.IIGB_AGENT_EMAIL = "*****@*****.**"

    response = ContactFormView.as_view()(contact_request)
    assert response.status_code == 302
    assert response.url == "success/"

    assert len(mail.outbox) == 2

    agent_email, user_email = mail.outbox

    if agent_email.to != [settings.IIGB_AGENT_EMAIL]:
        agent_email, user_email = user_email, agent_email

    assert agent_email.to == [settings.IIGB_AGENT_EMAIL]
    assert user_email.to == [contact_form_data["email"]]

    form_data = ContactFormView.extract_data(contact_form_data)

    for email in [agent_email, user_email]:
        body = email.alternatives[0][0]
        for field, value in form_data:
            assert f"<td>{field}</td>" in body, field
            assert f"<td>{value}</td>" in body, value

    assert mock_clean_captcha.call_count == 1
Exemple #3
0
    def test_contact_form_view_post_missing_fields(self, mock_render_to_response):
        """
        Test contact page display (POST), with missing fields values
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.post('/contact/')
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 2)
        self.assertEqual(mock_call[0], 'contact_form/contact_form.html')
        self.assertEqual(len(mock_call[1]), 2)
        self.assertTrue(mock_call[1]['field_id2name'])
        self.assertTrue(mock_call[1]['form'])

        form = mock_call[1]['form']
        self.assertTrue(form.errors['name'])
        self.assertTrue(form.errors['email'])
        self.assertTrue(form.errors['body'])
        self.assertTrue(form.errors['inquiry'])
        self.assertTrue('function' not in form.errors)
        self.assertTrue('phone' not in form.errors)

        self.assertEqual(len(mail.outbox), 0)
Exemple #4
0
def test_contact_form(mock_clean_captcha, mock_ticket_create,
                      mock_user_create_or_update, contact_request,
                      contact_form_data):
    mock_user_create_or_update.return_value = Mock(id=999)
    response = ContactFormView.as_view()(contact_request)

    assert response.status_code == http.client.OK
    assert response.template_name == ContactFormView.success_template

    assert mock_user_create_or_update.call_count == 1
    user = mock_user_create_or_update.call_args[0][0]
    assert user.__class__ == User
    assert user.email == contact_form_data['email']
    assert user.name == contact_form_data['name']

    assert mock_ticket_create.call_count == 1
    ticket = mock_ticket_create.call_args[0][0]
    assert ticket.__class__ == Ticket
    assert ticket.subject == 'Invest feedback'
    assert ticket.submitter_id == 999
    assert ticket.requester_id == 999
    contact_form_data['company_website'] = ''
    contact_form_data['phone_number'] = '0000000000'
    description = ('Name: {name}\n'
                   'Email: {email}\n'
                   'Job title: {job_title}\n'
                   'Phone number: {phone_number}\n'
                   'Company name: {company_name}\n'
                   'Company website: {company_website}\n'
                   'Country: {country}\n'
                   'Staff number: {staff_number}\n'
                   'Investment description: {description}').format(
                       **contact_form_data)
    assert ticket.description == description
    assert mock_clean_captcha.call_count == 1
Exemple #5
0
    def test_contact_form_view_post_missing_fields(self,
                                                   mock_render_to_response):
        """
        Test contact page display (POST), with missing fields values
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.post('/contact/')
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 2)
        self.assertEqual(mock_call[0], 'contact_form/contact_form.html')
        self.assertEqual(len(mock_call[1]), 2)
        self.assertTrue(mock_call[1]['field_id2name'])
        self.assertTrue(mock_call[1]['form'])

        form = mock_call[1]['form']
        self.assertTrue(form.errors['name'])
        self.assertTrue(form.errors['email'])
        self.assertTrue(form.errors['body'])
        self.assertTrue(form.errors['inquiry'])
        self.assertTrue('function' not in form.errors)
        self.assertTrue('phone' not in form.errors)

        self.assertEqual(len(mail.outbox), 0)
Exemple #6
0
    def test_contact_form_view_get(self, mock_render_to_response):
        """
        Test contact page display (GET)
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.get('/contact/')
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 1)
        self.assertEqual(['form'], mock_call[0].keys())
        self.assertEqual(len(mail.outbox), 0)
Exemple #7
0
    def test_contact_form_view_get(self, mock_render_to_response):
        """
        Test contact page display (GET)
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.get(reverse('contact:contact'))
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 1)
        self.assertEqual(['form'], mock_call[0].keys())
        self.assertEqual(len(mail.outbox), 0)
Exemple #8
0
    def test_contact_form_view_post_sent(self):
        """
        Test contact page display (POST), all correct & sent
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.post('/contact/', self.post_vars)

        self.assertEqual(len(mail.outbox), 0)
        response = contact_form_view(request)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], '/contact/sent/')
        self.assertEqual(mail.outbox[0].subject, 'Contact request - edX')
        self.assertEqual(mail.outbox[0].body, u'Inquiry: My account\nFrom: John Doe <*****@*****.**>\nPhone: +33664446505\n\nHello! \xe6\xea\xe9\n')
Exemple #9
0
    def test_contact_form_view_post_sent(self):
        """
        Test contact page display (POST), all correct & sent
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.post('/contact/', self.post_vars)

        self.assertEqual(len(mail.outbox), 0)
        response = contact_form_view(request)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], '/contact/sent/')
        self.assertEqual(mail.outbox[0].subject, 'Contact request - edX')
        self.assertEqual(
            mail.outbox[0].body,
            u'Inquiry: My account\nFrom: John Doe <*****@*****.**>\nPhone: +33664446505\n\nHello! \xe6\xea\xe9\n'
        )
Exemple #10
0
    def test_contact_form_view_get(self, mock_render_to_response):
        """
        Test contact page display (GET)
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.get('/contact/')
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 2)
        self.assertEqual(mock_call[0], 'contact_form/contact_form.html')
        self.assertEqual(len(mock_call[1]), 2)
        self.assertEqual(mock_call[1]['field_id2name'], {
            'name': 'Name',
            'email': 'Email',
            'body': 'Message',
            'inquiry': 'Inquiry'
        })
        self.assertTrue(mock_call[1]['form'])

        self.assertEqual(len(mail.outbox), 0)
Exemple #11
0
    def test_contact_form_view_get(self, mock_render_to_response):
        """
        Test contact page display (GET)
        """
        contact_form_view = ContactFormView.as_view()
        request = self.factory.get('/contact/')
        contact_form_view(request)

        self.assertEqual(len(mock_render_to_response.call_args_list), 1)
        mock_call = mock_render_to_response.call_args_list[0][0]
        self.assertEqual(len(mock_call), 2)
        self.assertEqual(mock_call[0], 'contact_form/contact_form.html')
        self.assertEqual(len(mock_call[1]), 2)
        self.assertEqual(
            mock_call[1]['field_id2name'], {
                'name': 'Name',
                'email': 'Email',
                'body': 'Message',
                'inquiry': 'Inquiry'
            })
        self.assertTrue(mock_call[1]['form'])

        self.assertEqual(len(mail.outbox), 0)
Exemple #12
0
from django.conf.urls import url
from contact.views import ContactFormView, ContactFormThankyouView

urlpatterns = [
    url(r'^$', ContactFormView.as_view(), name='contactform'),
    url(r'^thankyou/$', ContactFormThankyouView.as_view(), name='contactformthankyou'),
]
Exemple #13
0
from django.conf.urls import patterns, url

from contact.views import ContactFormView

urlpatterns = patterns('',
	url(r'^$', ContactFormView.as_view()),
	)
Exemple #14
0
from django.conf.urls import patterns, url
from contact.views import ContactFormView, ContactFormViewSubmit, JBKahmContactFormViewSubmit

urlpatterns = patterns(
    '',
    url(r'^$', ContactFormView.as_view(), name='form'),
    url(r'^submit/$', ContactFormViewSubmit.as_view(), name='form_submit'),
    url(r'^jbkahn/form_submit/$', JBKahmContactFormViewSubmit.as_view(), name='jbkahn_form_submit'),
)
Exemple #15
0
    OntologyMapView,
    SearchFormView,
)
from nanopub import views as nanopub_views
from django.views.generic import TemplateView

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', diseasemods_views.home, name='home'),
    url(r'^ontomap/$',
        TemplateView.as_view(template_name='ontomap.html'),
        name='ontomap'),
    url(r'^ontomap-list/$', OntologyMapView.as_view(), name='ontomaplist'),
    url(r'^testform/$', TestFormView.as_view(), name='testform'),
    url(r'^search/$', search, name='search'),
    url(r'^search-test/$', SearchFormView.as_view(), name='searchtest'),
    url(r'^contact-form/$', ContactFormView.as_view(), name='contact_form'),
    url(r'^api-auth/',
        include('rest_framework.urls', namespace='rest_framework')),
    url(r'^do-viewer/$',
        TemplateView.as_view(template_name='do_viewer.html'),
        name='do_viewer'),
]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL,
                          document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
Exemple #16
0
from django.conf.urls import url

from contact.views import ContactFormView

urlpatterns = [
	url(r'^$', ContactFormView.as_view(),name='contact-view'),
	]
Exemple #17
0
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView
from django.contrib import admin

from galleries.views import GalleryList, GalleryDetail
from contact.views import ContactFormView

admin.autodiscover()

urlpatterns = patterns('',
    #url(r'^$', TemplateView.as_view(template_name='landing.html')),
    url(r'^$', GalleryList.as_view()),
    url(r'^galerie/(?P<slug>[A-Za-z0-9_\-]+)/$', GalleryDetail.as_view()),
    url(r'^kontakt/$', ContactFormView.as_view()),
    url(r'^wyslane/$',TemplateView.as_view(template_name='contact/sent.html')),
    url(r'^omnie/$', TemplateView.as_view(template_name='about/about.html')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^.*$', RedirectView.as_view(url='/', permanent=True))
)

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}))
Exemple #18
0
        name='tos'),
    url(r'^privacy/$',
        TemplateView.as_view(template_name='text/privacy.html'),
        name='privacy'),

    # Sales
    url(r'^bucket/$', create_order, name='create_order_or_add_item'),
    url(r'^order/delete-item/$',
        remove_item_from_order,
        name='remove_item_from_order'),
    url(r'^edit-add-addresses/$',
        edit_order_and_next,
        name='edit_order_and_next'),
    url(r'^checkout/$', checkout, name='checkout'),
    # Contact
    url(r'^contact/$', ContactFormView.as_view(), name='contact'),
    # Slack app
    url(r'^slack/actions/$', slack_actions, name='slack_actions'),
    url(r'^graphql$', csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
handler404 = TicketList.as_view()

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL,
                          document_root=settings.STATIC_ROOT)
    try:
        import debug_toolbar

        urlpatterns = [
Exemple #19
0
from django.urls import path

from contact.views import ContactFormView

urlpatterns = [
    path('', ContactFormView.as_view(), name='contact'),
]