コード例 #1
0
ファイル: tests.py プロジェクト: happinesstaker/more-website
    def test_update_personal_information(self):
        user = RegisterHelper.create_user()
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)

        first_name = "new first name"
        last_name = "new last name"

        self.selenium.get(self.profile_url)
        self.selenium.find_element_by_id('id_first_name').send_keys(first_name)
        self.selenium.find_element_by_id('id_last_name').send_keys(last_name)
        self._save_profile()

        # check the if the form was updated correctly or not
        self.assertEqual(self.selenium.current_url, self.profile_url,
                         "Failed to redirect to profile page after submit")
        self.assertEqual(
            self.selenium.find_element_by_id('id_first_name').get_attribute(
                'value'), first_name,
            "Failed to update first name in profile form")
        self.assertEqual(
            self.selenium.find_element_by_id('id_last_name').get_attribute(
                'value'), last_name,
            "Failed to update last name in profile form")

        # reload user to check updates in the model
        user = get_user_model().objects.get(pk=user.pk)
        self.assertEqual(user.first_name, first_name,
                         "Failed to update first name in user model")
        self.assertEqual(user.last_name, last_name,
                         "Failed to update last name in user model")
コード例 #2
0
ファイル: tests.py プロジェクト: CaveSentinels/ReportWriter
    def test_deactivate_account(self):
        user = RegisterHelper.create_user()
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)

        self.selenium.get(self.profile_url)

        # show deactivation popup
        self.selenium.find_element_by_xpath('//button[@name="_deactivate_account"]').click()

        # wait for popup
        deactivate_button = WebDriverWait(self.selenium, 10).until(
            EC.visibility_of_element_located((By.ID, "deactivate_account_button"))
        )
        deactivate_button.click()

        # reload user to check updates in the model
        user = get_user_model().objects.get(pk=user.pk)
        self.assertFalse(user.is_active, "User still active even after clicking on deactivate button")

        # Test that the user is redirected to home screen
        self.assertEqual(self.selenium.current_url, '%s/' % self.live_server_url, "Browser is not redirected to home screen after deactivating the user")

        # Test the user has been logged out
        self.selenium.get(self.login_redirect_url)
        self.assertTrue(RegisterHelper.is_login_page(self.selenium, self.live_server_url),
                        "User is still logged in after deactivating his account")

        # Test the user is not able to login
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)
        self.assertEqual(self.selenium.current_url, self.inactive_url, "User is not redirected to inactive URL when trying to login")
コード例 #3
0
    def test_register_invited(self):
        invitation = EmailInvitation.objects.create(
            email=RegisterHelper.form_params['email'])
        signup_url = '%s?token=%s&email=%s' % (self.signup_url, invitation.key,
                                               invitation.email)

        RegisterHelper.fill_register_form(self.selenium, signup_url)
        RegisterHelper.submit_register_form(self.selenium)

        invitation = EmailInvitation.objects.get(
            pk=invitation.pk)  # reload invitation object
        self.assertEqual(
            invitation.status, 'accepted',
            'Invitation status was not updated to accepted after registration')

        email_obj = EmailAddress.objects.filter(email=invitation.email)[0]
        self.assertTrue(
            email_obj.verified,
            'Email was not verified after signup with invitation token')

        if 'register_approval' in settings.INSTALLED_APPS:
            # Verify email is automatically approved if registered with invitation token
            self.assertEqual(
                email_obj.admin_approval, 'approved',
                'Registration request was not automatically approved when registering with invitation token'
            )

        self.assertEqual(
            self.selenium.current_url, self.login_redirect_url,
            'Auto login failed after registering with invitation token!')
コード例 #4
0
    def test_rest_token(self):
        user = RegisterHelper.create_user()
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)

        # This user should not have REST token when he is created
        assert Token.objects.filter(user=user).exists() == False, "User should not have REST token right after creation"

        # User without a token should not see the Token field or button in his profile
        self.selenium.get(self.profile_url)
        self.assertFalse(self.selenium.find_elements_by_id('id_rest_token'), "REST token is visible even though the user doesn't have one!")
        self.assertFalse(self.selenium.find_elements_by_id('id_rest_token_submit'), "REST token is visible even though the user doesn't have one!")

        # Create REST token for the user
        token = Token.objects.create(user=user)
        old_key = token.key

        # User with a token should see the Token field or button in his profile
        self.selenium.get(self.profile_url)
        self.assertTrue(self.selenium.find_elements_by_id('id_rest_token'), "REST token is not visible even though the user have one!")
        self.assertTrue(self.selenium.find_elements_by_id('id_rest_token_submit'), "REST token is not visible even though the user have one!")


        # Request change REST token
        self.selenium.find_element_by_id('id_rest_token_submit').click()
        self.assertEqual(self.selenium.current_url, self.profile_url, "Failed to redirect to profile page after REST token change")

        # Test the token has been updated
        new_token = Token.objects.filter(user=user)[0]
        self.assertNotEqual(old_key, new_token.key, "Failed to change REST token")

        # Test the user has been notified by email when the token was changed
        self.assertEqual(len(mail.outbox), 1, 'Token changed email failed to send')
コード例 #5
0
ファイル: tests.py プロジェクト: happinesstaker/more-website
    def test_update_notifications(self):
        user = RegisterHelper.create_user()
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)

        # Get the notification profile
        mailer_profile = user.mailer_profile
        mailer_profile.notify_report_accepted = True
        mailer_profile.save()

        self.selenium.get(self.profile_url)
        self.selenium.find_element_by_id('id_notify_report_accepted').click()
        self._save_profile()

        # check the if the form was updated correctly or not
        self.assertEqual(self.selenium.current_url, self.profile_url,
                         "Failed to redirect to profile page after submit")
        self.assertFalse(
            self.selenium.find_element_by_id(
                'id_notify_report_accepted').is_selected(),
            "Failed to deselect notification option")

        # reload user to check updates in the model
        user = get_user_model().objects.get(pk=user.pk)
        mailer_profile = user.mailer_profile
        self.assertFalse(
            mailer_profile.notify_report_accepted,
            "Failed to update notification option in mailer model")
コード例 #6
0
 def setUp(self):
     # Call the setUp() of parent class.
     super(MUOReviewerTest, self).setUp()
     # Log in.
     RegisterHelper.fill_login_form(
         selenium=self.browser,
         login_url="%s%s" %
         (self.live_server_url, reverse("account_login")),
         admin=False)
     RegisterHelper.submit_login_form(selenium=self.browser)
コード例 #7
0
    def test_approve_request(self):
        # Create admin
        RegisterHelper.create_superuser()
        RegisterHelper.fill_login_form(self.selenium,
                                       self.login_url,
                                       admin=True)
        RegisterHelper.submit_login_form(self.selenium)

        # Create user
        user = RegisterHelper.create_user(approved=False)
        # Get EmailAddress URL
        email_obj = EmailAddress.objects.filter(user=user)[0]
        assert email_obj.admin_approval != 'approved', 'EmailAddress is already approved when created!'

        email_url = reverse('admin:account_emailaddress_change',
                            args=[email_obj.id])
        email_url = '%s%s' % (self.live_server_url, email_url)
        self.selenium.get(email_url)
        self.selenium.find_element_by_xpath(
            '//input[@name="_approve"]').click()
        self.assertEqual(self.selenium.current_url, email_url)

        # Reload email_obj
        email_obj = EmailAddress.objects.get(pk=email_obj.pk)
        self.assertEqual(email_obj.admin_approval, 'approved',
                         'Failed to approve EmailAddress')
コード例 #8
0
 def setUp(self):
     # Call the setUp() of parent class.
     super(MUOTestBase, self).setUp()
     # Launch a browser.
     self.browser = webdriver.Firefox()
     self.browser.implicitly_wait(
         SELENIUM_WEB_ELEMENT_PRESENCE_CHECK_TIMEOUT)
     # Create test data.
     self._set_up_test_data()
     # Create the user.
     user = RegisterHelper.create_user()
     # Assign user's permissions.
     self._assign_user_permissions(user)
コード例 #9
0
    def test_reject_request(self):
        # Create admin
        RegisterHelper.create_superuser()
        RegisterHelper.fill_login_form(self.selenium,
                                       self.login_url,
                                       admin=True)
        RegisterHelper.submit_login_form(self.selenium)

        # Create user
        user = RegisterHelper.create_user(approved=False)
        # Get EmailAddress URL
        email_obj = EmailAddress.objects.filter(user=user)[0]
        assert email_obj.admin_approval != 'rejected', 'EmailAddress is already rejected when created!'

        email_url = reverse('admin:account_emailaddress_change',
                            args=[email_obj.id])
        email_url = '%s%s' % (self.live_server_url, email_url)
        self.selenium.get(email_url)

        # show rejection popup
        self.selenium.find_element_by_xpath(
            '//button[@name="_reject"]').click()

        # wait for popup
        reject_textarea = WebDriverWait(self.selenium, 10).until(
            EC.visibility_of_element_located((By.ID, "reject_reason_text")))

        reject_button = self.selenium.find_element_by_xpath(
            '//input[@name="_reject"]')
        self.assertFalse(
            reject_button.is_enabled(),
            'Reject button is enabled even though reject reason is empty')

        reject_reason = "These are more than 15 characters"
        reject_textarea.send_keys(reject_reason)
        self.assertTrue(
            reject_button.is_enabled(),
            'Reject button is disabled even after filling reject reason')

        reject_button.click()
        self.assertEqual(self.selenium.current_url, email_url)

        # Reload email_obj
        email_obj = EmailAddress.objects.get(pk=email_obj.pk)
        self.assertEqual(email_obj.admin_approval, 'rejected',
                         'Failed to reject EmailAddress')
        self.assertEqual(email_obj.reject_reason, reject_reason,
                         'Failed to update reject reason')
コード例 #10
0
ファイル: tests.py プロジェクト: happinesstaker/more-website
    def test_login_pre_approved(self):
        RegisterHelper.fill_register_form(self.selenium, self.signup_url)
        RegisterHelper.submit_register_form(self.selenium)

        email_obj = EmailAddress.objects.filter(email=RegisterHelper.form_params.get('email'))[0]
        email_obj.admin_approval = 'approved'
        email_obj.save()

        RegisterHelper.verify_email(self.live_server_url, self.selenium)

        # Test that user is redirected to login page after email confirmation as he is already approved
        self.assertEqual(self.selenium.current_url, self.login_redirect_url,
                         'Failed to redirect to login page after email confirmation of pre-approved user')
コード例 #11
0
 def setUp(self):
     # Create the admin.
     RegisterHelper.create_superuser()
     # Launch a browser.
     self.browser = webdriver.Firefox()
     self.browser.implicitly_wait(SELENIUM_WEB_ELEMENT_PRESENCE_CHECK_TIMEOUT)
     # Log in.
     RegisterHelper.fill_login_form(
         selenium=self.browser,
         login_url="%s%s" % (self.live_server_url, reverse("account_login")),
         admin=True
     )
     RegisterHelper.submit_login_form(selenium=self.browser)
コード例 #12
0
 def setUp(self):
     # Create test data.
     self._set_up_test_data()
     # Create the admin.
     RegisterHelper.create_superuser()
     # Launch a browser.
     self.browser = webdriver.Firefox()
     self.browser.implicitly_wait(10)
     # Log in.
     RegisterHelper.fill_login_form(
         selenium=self.browser,
         login_url="%s%s" % (self.live_server_url, reverse("account_login")),
         admin=True
     )
     RegisterHelper.submit_login_form(selenium=self.browser)
コード例 #13
0
    def setUp(self):
        # Create the admin.
        RegisterHelper.create_superuser()

        # Launch a browser.
        self.browser = webdriver.Firefox()

        # Log in.
        RegisterHelper.fill_login_form(
            selenium=self.browser,
            login_url="%s%s" %
            (self.live_server_url, reverse("account_login")),
            admin=True)
        RegisterHelper.submit_login_form(selenium=self.browser)

        # Call the setUp() of parent class.
        super(KeywordManagement, self).setUp()
コード例 #14
0
ファイル: tests.py プロジェクト: CaveSentinels/ReportWriter
 def tearDown(self):
     RegisterHelper.logout(self.selenium, self.live_server_url)
     super(UserProfileTest, self).tearDown()
コード例 #15
0
ファイル: tests.py プロジェクト: happinesstaker/more-website
    def test_login_approval(self):
        RegisterHelper.fill_register_form(self.selenium, self.signup_url)
        RegisterHelper.submit_register_form(self.selenium)
        RegisterHelper.verify_email(self.live_server_url, self.selenium)

        # Test that user is redirected to login page after email confirmation
        self.assertEqual(self.selenium.current_url, self.login_url,
                         'Failed to redirect to login page after email confirmation')

        email_obj = EmailAddress.objects.filter(email=RegisterHelper.form_params.get('email'))[0]

        # Verify email is not approved
        self.assertEqual(email_obj.admin_approval, 'pending', 'Registration request is not in pending state by default')


        # Try to login before approving from admin
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)
        self.assertEqual(self.selenium.current_url, self.login_url,
                         'Login succeeded even though admin did not approve registration request!')


        # Reject request
        email_count = len(mail.outbox)
        email_obj.action_reject("this is rejection reason")
        self.assertEqual(email_obj.admin_approval, 'rejected', 'Registration request rejection failed')

        # Verify rejection email was sent
        self.assertEqual(len(mail.outbox), email_count + 1, 'Registration rejection email failed to send')

        # Try to login after rejecting the request
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)
        self.assertEqual(self.selenium.current_url, self.login_url,
                         'Login succeeded even after admin rejected registration request!')


        # Approve request
        email_count = len(mail.outbox)
        email_obj.action_approve()
        self.assertEqual(email_obj.admin_approval, 'approved', 'Registration request approval failed')

        # Verify approval email was sent
        self.assertEqual(len(mail.outbox), email_count + 1, 'Registration approval email failed to send')


        # Try to login after approving the request
        RegisterHelper.fill_login_form(self.selenium, self.login_url)
        RegisterHelper.submit_login_form(self.selenium)
        self.assertEqual(self.selenium.current_url, self.login_redirect_url,
                         'Login failed even after admin approved registration request!')