コード例 #1
0
    def test_get_initial_anonymous(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.session = {}
        view.request.user = AnonymousUser()
        initial = view.get_initial()

        self.assertFalse('name' in initial)
        self.assertFalse('email' in initial)
コード例 #2
0
    def test_get_initial_anonymous(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.session = {}
        view.request.user = AnonymousUser()
        initial = view.get_initial()

        self.assertFalse('name' in initial)
        self.assertFalse('email' in initial)
コード例 #3
0
    def test_get_initial_not_anonymous(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.session = {}
        view.request.user = User.objects.create(
            first_name='Foo', last_name='Bar', email='*****@*****.**')

        initial = view.get_initial()
        self.assertEquals(initial['name'], 'Foo Bar')
        self.assertEquals(initial['email'], '*****@*****.**')

        # a subsequent call using an anonymous session returns a clean initial
        view.request.session = {}
        view.request.user = AnonymousUser()
        initial = view.get_initial()
        self.assertFalse('name' in initial)
        self.assertFalse('email' in initial)
コード例 #4
0
    def test_get_initial_not_anonymous(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.session = {}
        view.request.user = User.objects.create(
            first_name='Foo', last_name='Bar', email='*****@*****.**')

        initial = view.get_initial()
        self.assertEquals(initial['name'], 'Foo Bar')
        self.assertEquals(initial['email'], '*****@*****.**')

        # a subsequent call using an anonymous session returns a clean initial
        view.request.session = {}
        view.request.user = AnonymousUser()
        initial = view.get_initial()
        self.assertFalse('name' in initial)
        self.assertFalse('email' in initial)
コード例 #5
0
    def test_form_valid(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.user = AnonymousUser()

        form = ContactUsForm()
        form.cleaned_data = {
            'name': 'Foo Bar',
            'email': '*****@*****.**',
            'subject': 'other',
            'description': 'There is a problem'
        }

        view.form_valid(form)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(mail.outbox[0].subject, view.subject)
        self.assertEquals(mail.outbox[0].from_email, 'root@localhost')
        self.assertEquals(mail.outbox[0].to, [settings.CONTACT_US_EMAIL])
コード例 #6
0
    def test_form_valid(self):
        view = ContactUsView()
        view.request = RequestFactory().get('/contact/')
        view.request.user = AnonymousUser()

        form = ContactUsForm()
        form.cleaned_data = {
            'name': 'Foo Bar',
            'email': '*****@*****.**',
            'subject': 'other',
            'description': 'There is a problem'
        }

        view.form_valid(form)
        self.assertEqual(len(mail.outbox), 1)

        self.assertEqual(mail.outbox[0].subject,
                         view.subject)
        self.assertEquals(mail.outbox[0].from_email,
                          '*****@*****.**')
        self.assertEquals(mail.outbox[0].to,
                          [settings.CONTACT_US_EMAIL])