Exemple #1
0
    def test_send_change_email_to_old(self, render_to_string_mock,
                                      send_mail_mock, get_connection_mock):
        old_email = '*****@*****.**'
        new_email = '*****@*****.**'
        default_template = 'registration/email_change_email_old_email.txt'
        template = 'mytemplate/template.txt'
        message = 'imamessage'
        connection = 0

        render_to_string_mock.return_value = message
        get_connection_mock.return_value = connection

        user = get_local_user(old_email)
        email_change = EmailChange.objects.create(user=user,
                                                  new_email_address=new_email)

        send_change_email_to_old(email_change)
        render_to_string_mock.assert_called_once_with(default_template,
                                                      {'ec': email_change})
        send_mail_mock.assert_called_once_with(
            _(astakos_messages.EMAIL_CHANGE_OLD_EMAIL_SUBJECT),
            message,
            astakos_settings.SERVER_EMAIL, [email_change.user.email],
            connection=connection)

        send_change_email_to_old(email_change, template)
        render_to_string_mock.assert_called_with(template,
                                                 {'ec': email_change})
Exemple #2
0
    def test_send_change_email_to_old(self,
            render_to_string_mock, send_mail_mock, get_connection_mock):
        old_email = '*****@*****.**'
        new_email = '*****@*****.**'
        default_template = 'registration/email_change_email_old_email.txt'
        template = 'mytemplate/template.txt'
        message = 'imamessage'
        connection = 0

        render_to_string_mock.return_value = message
        get_connection_mock.return_value = connection

        user = get_local_user(old_email)
        email_change = EmailChange.objects.create(
            user=user,
            new_email_address=new_email
        )

        send_change_email_to_old(email_change)
        render_to_string_mock.assert_called_once_with(default_template, {'ec': email_change})
        send_mail_mock.assert_called_once_with(
            _(astakos_messages.EMAIL_CHANGE_OLD_EMAIL_SUBJECT),
            message,
            astakos_settings.SERVER_EMAIL,
            [email_change.user.email],
            connection=connection
        )

        send_change_email_to_old(email_change, template)
        render_to_string_mock.assert_called_with(template, {'ec': email_change})
Exemple #3
0
    def setUp(self):
        baseurl = reverse('oauth2_authenticate').replace('/auth', '/')
        self.client = OA2Client(baseurl)
        client1 = Client.objects.create(identifier="client1", secret="secret")
        self.client1_redirect_uri = "https://server.com/handle_code?α=β&a=b"
        client1.redirecturl_set.create(url=self.client1_redirect_uri)

        client2 = Client.objects.create(identifier="client2", type='public')
        self.client2_redirect_uri = "https://server2.com/handle_code"
        client2.redirecturl_set.create(url=self.client2_redirect_uri)

        client3 = Client.objects.create(identifier="client3", secret='secret',
                                        is_trusted=True)
        self.client3_redirect_uri = "https://server3.com/handle_code"
        client3.redirecturl_set.create(url=self.client3_redirect_uri)

        common.get_local_user("*****@*****.**", password="******")
Exemple #4
0
    def setUp(self):
        baseurl = reverse('oauth2_authenticate').replace('/auth', '/')
        self.client = OA2Client(baseurl)
        client1 = Client.objects.create(identifier="client1", secret="secret")
        self.client1_redirect_uri = "https://server.com/handle_code?α=β&a=b"
        client1.redirecturl_set.create(url=self.client1_redirect_uri)

        client2 = Client.objects.create(identifier="client2", type='public')
        self.client2_redirect_uri = "https://server2.com/handle_code"
        client2.redirecturl_set.create(url=self.client2_redirect_uri)

        client3 = Client.objects.create(identifier="client3", secret='secret',
                                        is_trusted=True)
        self.client3_redirect_uri = "https://server3.com/handle_code"
        client3.redirecturl_set.create(url=self.client3_redirect_uri)

        common.get_local_user("*****@*****.**", password="******")
Exemple #5
0
    def test_change_user_email(self, send_change_email_to_old_mock,
                               send_change_email_to_new_mock):
        """
        The `change_user_email` method should check if the email
        provided is valid. If it is invalid it should raise a
        `ValidationError` exception. Otherwise it should create
        an `EmailChange` instance on the database and call
        `send_change_email_to_new` with the email template provided.
        """
        user = get_local_user('*****@*****.**')

        # invalid new_email
        new_email = 'something.com'

        with self.assertRaises(ValidationError):
            change_user_email(user, new_email)

        # valid `new_email`, default `email_to_new_template_name`
        new_email = '*****@*****.**'
        default_to_new_template = 'registration/email_change_email_new_email.txt'
        default_to_old_template = 'registration/email_change_email_old_email.txt'

        change_user_email(user, new_email)

        email_change = EmailChange.objects.get(new_email_address=new_email)
        send_change_email_to_new_mock.assert_called_once_with(
            email_change, default_to_new_template)
        send_change_email_to_old_mock.assert_called_once_with(
            email_change, default_to_old_template)
        self.assertTrue(user.email_change_is_pending())
        self.assertEqual(user.emailchanges.count(), 1)

        # valid mail, different `email_to_new_template_name`
        to_new_template = 'mytemplate/template.txt'
        to_old_template = 'mysecondtemplate/template.txt'
        change_user_email(user,
                          new_email,
                          email_to_new_template_name=to_new_template,
                          email_to_old_template_name=to_old_template)

        email_change = EmailChange.objects.get(new_email_address=new_email)
        send_change_email_to_new_mock.assert_called_with(
            email_change, to_new_template)
        send_change_email_to_old_mock.assert_called_with(
            email_change, to_old_template)

        # the previous email change was deleted
        self.assertEqual(user.emailchanges.count(), 1)
        self.assertEqual(email_change, user.emailchanges.all()[0])
Exemple #6
0
    def test_change_user_email(self,
            send_change_email_to_old_mock,
            send_change_email_to_new_mock):
        """
        The `change_user_email` method should check if the email
        provided is valid. If it is invalid it should raise a
        `ValidationError` exception. Otherwise it should create
        an `EmailChange` instance on the database and call
        `send_change_email_to_new` with the email template provided.
        """
        user = get_local_user('*****@*****.**')

        # invalid new_email
        new_email = 'something.com'

        with self.assertRaises(ValidationError):
            change_user_email(user, new_email)

        # valid `new_email`, default `email_to_new_template_name`
        new_email = '*****@*****.**'
        default_to_new_template = 'registration/email_change_email_new_email.txt'
        default_to_old_template = 'registration/email_change_email_old_email.txt'

        change_user_email(user, new_email)

        email_change = EmailChange.objects.get(new_email_address=new_email)
        send_change_email_to_new_mock.assert_called_once_with(email_change, default_to_new_template)
        send_change_email_to_old_mock.assert_called_once_with(email_change, default_to_old_template)
        self.assertTrue(user.email_change_is_pending())
        self.assertEqual(user.emailchanges.count(), 1)

        # valid mail, different `email_to_new_template_name`
        to_new_template = 'mytemplate/template.txt'
        to_old_template = 'mysecondtemplate/template.txt'
        change_user_email(
            user,
            new_email,
            email_to_new_template_name=to_new_template,
            email_to_old_template_name=to_old_template
        )

        email_change = EmailChange.objects.get(new_email_address=new_email)
        send_change_email_to_new_mock.assert_called_with(email_change, to_new_template)
        send_change_email_to_old_mock.assert_called_with(email_change, to_old_template)

        # the previous email change was deleted
        self.assertEqual(user.emailchanges.count(), 1)
        self.assertEqual(email_change, user.emailchanges.all()[0])