Beispiel #1
0
 def test_form_valid_redirects_to_claim_url_if_save_and_email(self):
     view = UpdateContact()
     view.request = RequestFactory().post('/')
     view.request.POST.update({'save-and-email': ''})
     view.object = mock.Mock(id=3)
     assert view.get_success_url() == reverse('contact_claim_account',
                                              args=(3, ))
def test_update_contact_form_invalid_adds_a_message_to_messages(rf):
    view = UpdateContact()
    view.object = mock.MagicMock()
    r = rf.get('/')
    view.request = r
    form = mock.MagicMock()
    with mock.patch('contacts.views.contact_info.messages') as messages:
        view.form_invalid(form)
        messages.error.assert_called_once_with(r, 'Contact data not valid, \
                please check and try again.')
def test_activation_email_link_is_rendered_if_contact_has_not_set_password(rf):
    view = UpdateContact.as_view()
    contact_for_editing = UserFactory()
    request_user = ContactsManagerFactory()
    request = rf.get('/')
    request.user = request_user
    response = view(request, pk=contact_for_editing.id)
    response.render()
    assert 'Account not claimed' in response.content.decode('utf-8')
    # The button name that triggers an activation email to be sent is the
    # save-and-email button - see views_test
    assert 'name="save-and-email"' in response.content.decode('utf-8')
Beispiel #4
0
def test_update_contact_form_invalid_adds_a_message_to_messages(rf):
    view = UpdateContact()
    view.object = mock.MagicMock()
    r = rf.get('/')
    view.request = r
    form = mock.MagicMock()
    with mock.patch('contacts.views.contact_info.messages') as messages:
        view.form_invalid(form)
        messages.error.assert_called_once_with(
            r, 'Contact data not valid, \
                please check and try again.')
Beispiel #5
0
from django.conf.urls import url
from contacts.views import (AddContact, UpdateContact, DeleteContact,
                            ListContacts, SendActivationEmailView,
                            UpdatePersonalInfo, ListContactsExport)

urlpatterns = [
    url(r'edit/$', AddContact.as_view(), name='contact_add'),
    url(r'edit/(?P<pk>\d+)/$', UpdateContact.as_view(), name='contact_update'),
    url(r'delete/(?P<pk>\d+)/$',
        DeleteContact.as_view(),
        name='contact_delete'),
    url(r'activate/(?P<pk>\d+)/$',
        SendActivationEmailView.as_view(),
        name='contact_claim_account'),
    url(r'personal/$', UpdatePersonalInfo.as_view(), name='personal_edit'),
    url(r'export_as_csv/$',
        ListContactsExport.as_view(), {'format': 'csv'},
        name='contact_list_csv'),
    url(r'export_as_excel/$',
        ListContactsExport.as_view(), {'format': 'excel'},
        name='contact_list_excel'),
    url(r'$', ListContacts.as_view(), name='contact_list'),
]
Beispiel #6
0
 def test_has_expected_permissions_properties(self):
     view = UpdateContact()
     self.assertEqual(view.permission_required, 'contacts.add_user')
     self.assertTrue(view.raise_exception)
Beispiel #7
0
from django.conf.urls import url
from contacts.views import (
    AddContact, UpdateContact, DeleteContact, ListContacts,
    SendActivationEmailView,
    UpdatePersonalInfo, ListContactsExport
)


urlpatterns = [
    url(r'edit/$', AddContact.as_view(), name='contact_add'),
    url(r'edit/(?P<pk>\d+)/$', UpdateContact.as_view(),
        name='contact_update'),
    url(r'delete/(?P<pk>\d+)/$', DeleteContact.as_view(),
        name='contact_delete'),
    url(r'activate/(?P<pk>\d+)/$', SendActivationEmailView.as_view(),
        name='contact_claim_account'),
    url(r'personal/$', UpdatePersonalInfo.as_view(), name='personal_edit'),
    url(r'export_as_csv/$', ListContactsExport.as_view(), {'format': 'csv'},
        name='contact_list_csv'),
    url(r'export_as_excel/$', ListContactsExport.as_view(), {'format': 'excel'},
        name='contact_list_excel'),
    url(r'$', ListContacts.as_view(), name='contact_list'),
]
 def test_form_valid_redirects_to_claim_url_if_save_and_email(self):
     view = UpdateContact()
     view.request = RequestFactory().post('/')
     view.request.POST.update({'save-and-email': ''})
     view.object = mock.Mock(id=3)
     assert view.get_success_url() == reverse('contact_claim_account', args=(3,))