Esempio n. 1
0
    def test_email_change_request_email_taken_by_active_account(self):
        # Create/activate a second user with the new email
        activation_key = account_api.create_account(self.ALTERNATE_USERNAME, self.PASSWORD, self.NEW_EMAIL)
        account_api.activate_account(activation_key)

        # Request to change the original user's email to the email now used by the second user
        response = self._change_email(self.NEW_EMAIL, self.PASSWORD)
        self.assertEquals(response.status_code, 409)
    def test_request_email_change_same_address(self):
        # Create and activate the account
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)

        # Try to change the email address to the current address
        with self.assertRaises(account_api.AccountEmailAlreadyExists):
            account_api.request_email_change(self.USERNAME, self.EMAIL, self.PASSWORD)
Esempio n. 3
0
    def test_request_email_change_same_address(self):
        # Create and activate the account
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)

        # Try to change the email address to the current address
        with self.assertRaises(account_api.AccountEmailAlreadyExists):
            account_api.request_email_change(self.USERNAME, self.EMAIL, self.PASSWORD)
    def test_request_email_change_duplicates_unactivated_account(self):
        # Create two accounts, but the second account is inactive
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        account_api.create_account(u"another_user", u"password", u"*****@*****.**")

        # Try to change the first user's email to the same as the second user's
        # Since the second user has not yet activated, this should succeed.
        account_api.request_email_change(self.USERNAME, u"*****@*****.**", self.PASSWORD)
Esempio n. 5
0
    def test_request_email_change_duplicates_unactivated_account(self):
        # Create two accounts, but the second account is inactive
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        account_api.create_account(u'another_user', u'password', u'*****@*****.**')

        # Try to change the first user's email to the same as the second user's
        # Since the second user has not yet activated, this should succeed.
        account_api.request_email_change(self.USERNAME, u'*****@*****.**', self.PASSWORD)
Esempio n. 6
0
    def setUp(self):
        super(StudentAccountViewTest, self).setUp()

        # Create/activate a new account
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.OLD_EMAIL)
        account_api.activate_account(activation_key)

        # Login
        result = self.client.login(username=self.USERNAME, password=self.PASSWORD)
        self.assertTrue(result)
    def test_request_email_change_already_exists(self):
        # Create two accounts, both activated
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        activation_key = account_api.create_account(u"another_user", u"password", u"*****@*****.**")
        account_api.activate_account(activation_key)

        # Try to change the first user's email to the same as the second user's
        with self.assertRaises(account_api.AccountEmailAlreadyExists):
            account_api.request_email_change(self.USERNAME, u"*****@*****.**", self.PASSWORD)
Esempio n. 8
0
    def test_request_email_change_already_exists(self):
        # Create two accounts, both activated
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        activation_key = account_api.create_account(u'another_user', u'password', u'*****@*****.**')
        account_api.activate_account(activation_key)

        # Try to change the first user's email to the same as the second user's
        with self.assertRaises(account_api.AccountEmailAlreadyExists):
            account_api.request_email_change(self.USERNAME, u'*****@*****.**', self.PASSWORD)
Esempio n. 9
0
    def test_login_and_registration_form_already_authenticated(self, url_name):
        # Create/activate a new account and log in
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        result = self.client.login(username=self.USERNAME, password=self.PASSWORD)
        self.assertTrue(result)

        # Verify that we're redirected to the dashboard
        response = self.client.get(reverse(url_name))
        self.assertRedirects(response, reverse("dashboard"))
Esempio n. 10
0
    def test_login_and_registration_form_already_authenticated(self, url_name):
        # Create/activate a new account and log in
        activation_key = account_api.create_account(self.USERNAME,
                                                    self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)
        result = self.client.login(username=self.USERNAME,
                                   password=self.PASSWORD)
        self.assertTrue(result)

        # Verify that we're redirected to the dashboard
        response = self.client.get(reverse(url_name))
        self.assertRedirects(response, reverse("dashboard"))
    def test_activate_account(self):
        # Create the account, which is initially inactive
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account = account_api.account_info(self.USERNAME)
        self.assertEqual(account, {
            'username': self.USERNAME,
            'email': self.EMAIL,
            'is_active': False
        })

        # Activate the account and verify that it is now active
        account_api.activate_account(activation_key)
        account = account_api.account_info(self.USERNAME)
        self.assertTrue(account['is_active'])
Esempio n. 12
0
    def test_activate_account(self):
        # Create the account, which is initially inactive
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account = account_api.account_info(self.USERNAME)
        self.assertEqual(account, {
            'username': self.USERNAME,
            'email': self.EMAIL,
            'is_active': False
        })

        # Activate the account and verify that it is now active
        account_api.activate_account(activation_key)
        account = account_api.account_info(self.USERNAME)
        self.assertTrue(account['is_active'])
Esempio n. 13
0
    def test_email_change_confirmation_email_already_exists(self):
        # Get an email change activation key
        email_activation_key = account_api.request_email_change(self.USERNAME, self.NEW_EMAIL, self.PASSWORD)

        # Create/activate a second user with the new email
        account_activation_key = account_api.create_account(self.ALTERNATE_USERNAME, self.PASSWORD, self.NEW_EMAIL)
        account_api.activate_account(account_activation_key)

        # Follow the link sent to the original user
        response = self.client.get(reverse('email_change_confirm', kwargs={'key': email_activation_key}))
        self.assertContains(response, "address you wanted to use is already used")

        # Verify that the email associated with the original account has not changed
        profile_info = profile_api.profile_info(self.USERNAME)
        self.assertEquals(profile_info['email'], self.OLD_EMAIL)
Esempio n. 14
0
    def test_request_password_change(self):
        # Create and activate an account
        activation_key = account_api.create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
        account_api.activate_account(activation_key)

        # Request a password change
        account_api.request_password_change(self.EMAIL, self.ORIG_HOST, self.IS_SECURE)

        # Verify that one email message has been sent
        self.assertEqual(len(mail.outbox), 1)

        # Verify that the body of the message contains something that looks
        # like an activation link
        email_body = mail.outbox[0].body
        result = re.search('(?P<url>https?://[^\s]+)', email_body)
        self.assertIsNot(result, None)
 def test_activate_account_invalid_key(self):
     account_api.activate_account(u"invalid")
Esempio n. 16
0
 def test_activate_account_invalid_key(self):
     account_api.activate_account(u'invalid')