Exemplo n.º 1
0
    def test_email_users(self, send_mass_mail):
        data = {
            'title': 'yeah',
            'content': 'message'
        }
        form = UserQueryForm(data)

        user_1 = User(email='*****@*****.**')
        user_2 = User(email='*****@*****.**')
        user_3 = User(email='*****@*****.**')

        view = EmailInterface()
        view.users_result = [user_1, user_2, user_3]

        view.email_users(form)

        admin_emails = []
        for admin in settings.ADMINS:
            admin_emails.append(admin[1])

        messages = [
            (data['title'], data['content'], '*****@*****.**', [user_1.email]),
            (data['title'], data['content'], '*****@*****.**', [user_2.email]),
            (data['title'], data['content'], '*****@*****.**', [user_3.email]),

            (data['title'] + ' (sent from admin panel)', data['content'], '*****@*****.**', admin_emails)
        ]

        send_mass_mail.assert_called_with(messages)
Exemplo n.º 2
0
    def test_email_users(self, send_mass_mail):
        data = {'title': 'yeah', 'content': 'message'}
        form = UserQueryForm(data)

        user_1 = User(email='*****@*****.**')
        user_2 = User(email='*****@*****.**')
        user_3 = User(email='*****@*****.**')

        view = EmailInterface()
        view.users_result = [user_1, user_2, user_3]

        view.email_users(form)

        admin_emails = []
        for admin in settings.ADMINS:
            admin_emails.append(admin[1])

        messages = [(data['title'], data['content'], '*****@*****.**',
                     [user_1.email]),
                    (data['title'], data['content'], '*****@*****.**',
                     [user_2.email]),
                    (data['title'], data['content'], '*****@*****.**',
                     [user_3.email]),
                    (data['title'] + ' (sent from admin panel)',
                     data['content'], '*****@*****.**', admin_emails)]

        send_mass_mail.assert_called_with(messages)
Exemplo n.º 3
0
    def test_post_invalid_email_form(self, execute_sql, form_invalid):
        request = HttpRequest()
        request.POST['_submit'] = 'yes'
        view = EmailInterface()
        view.request = request

        view.post(request)

        self.assertTrue(form_invalid.called)
Exemplo n.º 4
0
    def test_database_error(self):
        data = {'query': 'asdaddsd'}

        form = UserQueryForm(data)
        view = EmailInterface()

        self.assertFalse(view.execute_sql(form))
        self.assertEquals(form.data['result'], 0)
        self.assertTrue('__all__' in form.errors)
Exemplo n.º 5
0
    def test_post_invalid_email_form(self, execute_sql, form_invalid):
        request = HttpRequest()
        request.POST['_submit'] = 'yes'
        view = EmailInterface()
        view.request = request

        view.post(request)

        self.assertTrue(form_invalid.called)
Exemplo n.º 6
0
    def test_select(self):
        UserFactory.create_batch(3)

        data = {'query': 'select * from access_user'}

        form = UserQueryForm(data)
        view = EmailInterface()

        self.assertTrue(view.execute_sql(form))
        self.assertEquals(form.data['result'], 3)
Exemplo n.º 7
0
    def test_post_ignore_email_fields_on_sql_test(self, get_form, execute_sql, form_valid):
        request = HttpRequest()
        request.POST['_test'] = 'yes'
        view = EmailInterface()
        view.request = request

        view.post(request)

        get_form().errors.pop.assert_any_call('title', None)
        get_form().errors.pop.assert_any_call('content', None)
        self.assertTrue(form_valid.called)
Exemplo n.º 8
0
    def test_database_error(self):
        data = {
            'query': 'asdaddsd'
        }

        form = UserQueryForm(data)
        view = EmailInterface()

        self.assertFalse(view.execute_sql(form))
        self.assertEquals(form.data['result'], 0)
        self.assertTrue('__all__' in form.errors)
Exemplo n.º 9
0
    def test_post_ignore_email_fields_on_sql_test(self, get_form, execute_sql,
                                                  form_valid):
        request = HttpRequest()
        request.POST['_test'] = 'yes'
        view = EmailInterface()
        view.request = request

        view.post(request)

        get_form().errors.pop.assert_any_call('title', None)
        get_form().errors.pop.assert_any_call('content', None)
        self.assertTrue(form_valid.called)
Exemplo n.º 10
0
    def test_select(self):
        UserFactory.create_batch(3)

        data = {
            'query': 'select * from access_user'
        }

        form = UserQueryForm(data)
        view = EmailInterface()

        self.assertTrue(view.execute_sql(form))
        self.assertEquals(form.data['result'], 3)
Exemplo n.º 11
0
    def test_email_error(self, mass_mail):
        data = {'title': 'yeah', 'content': 'message'}
        form = UserQueryForm(data)

        user_1 = User(email='*****@*****.**')

        view = EmailInterface()
        view.users_result = [user_1]

        mass_mail.side_effect = SMTPException('fail')

        view.email_users(form)

        self.assertEquals(form.errors['__all__'], 'error sending email: fail')
Exemplo n.º 12
0
    def test_post_valid_email_form(self, execute_sql, form_valid, email_users):
        request = HttpRequest()
        request.POST['_submit'] = 'yes'
        request.POST['query'] = 'sddasd'
        request.POST['title'] = 'oba'
        request.POST['content'] = 'foo'
        request.method = 'POST'
        view = EmailInterface()
        view.request = request

        view.post(request)

        self.assertTrue(form_valid.called)
        self.assertTrue(email_users.called)
Exemplo n.º 13
0
    def test_post_valid_email_form(self, execute_sql, form_valid, email_users):
        request = HttpRequest()
        request.POST['_submit'] = 'yes'
        request.POST['query'] = 'sddasd'
        request.POST['title'] = 'oba'
        request.POST['content'] = 'foo'
        request.method = 'POST'
        view = EmailInterface()
        view.request = request

        view.post(request)

        self.assertTrue(form_valid.called)
        self.assertTrue(email_users.called)
Exemplo n.º 14
0
    def test_email_error(self, mass_mail):
        data = {
            'title': 'yeah',
            'content': 'message'
        }
        form = UserQueryForm(data)

        user_1 = User(email='*****@*****.**')

        view = EmailInterface()
        view.users_result = [user_1]

        mass_mail.side_effect = SMTPException('fail')

        view.email_users(form)

        self.assertEquals(form.errors['__all__'], 'error sending email: fail')