Example #1
0
 def test_template_rendered_experiment_slug(self, mocked_experiments_flag,
                                            mocked_switch):
     """Test that both experiments slugs render the static templates."""
     # Experiment enable-and-disable-cookies
     mocked_switch.return_value = True
     mocked_experiments_flag.return_value = True
     doc = DocumentFactory(
         slug='enable-and-disable-cookies-website-preferences')
     url = reverse('wiki.document', args=[doc.slug], locale='en-US')
     client = Client(HTTP_USER_AGENT='Mozilla/5.0')
     response = client.get(url)
     # Check redirect is happening
     eq_(response.status_code, 302)
     # get the redirected url
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     assert template_used(
         response,
         'kb-ux-experiment/enable-and-disable-cookies-website-preferences.html'
     )
     # Experiment insecure-password-warning
     doc = DocumentFactory(slug='insecure-password-warning-firefox')
     url = reverse('wiki.document', args=[doc.slug], locale='en-US')
     client = Client(HTTP_USER_AGENT='Mozilla/5.0')
     response = client.get(url)
     # Check redirect is happening
     eq_(response.status_code, 302)
     # get the redirected url
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     assert template_used(
         response,
         'kb-ux-experiment/insecure-password-warning-firefox.html')
Example #2
0
 def test_authenticated_user(self):
     """
     An active, authenticated user can access the AAQ flow
     """
     user = UserFactory(is_superuser=False)
     self.client.login(username=user.username, password="******")
     url = reverse("questions.aaq_step1")
     response = self.client.get(url, follow=True)
     assert not template_used(response, "users/auth.html")
     assert template_used(response, "questions/new_question.html")
Example #3
0
 def test_non_authenticated_user(self):
     """
     A non-authenticated user cannot access the AAQ flow and will be redirected to auth screen
     """
     url = reverse("questions.aaq_step1")
     response = self.client.get(url, follow=True)
     assert template_used(response, "users/auth.html")
Example #4
0
    def test_logged_in_get(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        u = UserFactory()
        self.client.login(username=u.username, password='******')

        response = self._new_question()
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/new_question.html')
Example #5
0
    def test_logged_in_get(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        u = UserFactory()
        self.client.login(username=u.username, password='******')

        response = self._new_question()
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/new_question.html')
Example #6
0
 def test_translate_with_parent_slug_while_trans_article_available(self):
     doc = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE)
     r = RevisionFactory(document=doc)
     trans_doc = DocumentFactory(parent=doc, locale='bn-BD', slug='bn-BD_slug')
     RevisionFactory(document=trans_doc, based_on=r)
     url = reverse('wiki.edit_document', args=[doc.slug], locale=trans_doc.locale)
     response = self.client.get(url)
     eq_(response.status_code, 200)
     # Check translate article template is being used
     assert template_used(response, 'wiki/translate.html')
     content = pq(response.content)
     eq_(content('#id_title').val(), trans_doc.title)
     eq_(content('#id_slug').val(), trans_doc.slug)
Example #7
0
    def test_template_rendered_non_en_US_locale(self, mocked_experiments_flag,
                                                mocked_switch):
        """Test that the default template is used for a non en-US locale."""

        mocked_switch.return_value = True
        mocked_experiments_flag.return_value = True
        ProductFactory()
        doc = DocumentFactory(slug='insecure-password-warning-firefox')
        url = reverse('wiki.document', args=[doc.slug], locale='es')
        client = Client(HTTP_USER_AGENT='Mozilla/5.0')
        response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        assert template_used(response, 'wiki/document.html')
Example #8
0
    def test_inactive_user(self):
        """
        An inactive user cannot access the AAQ flow
        """
        user = UserFactory(is_superuser=False)
        self.client.login(username=user.username, password="******")

        # After log in, set user to inactive
        user.is_active = False
        user.save()

        url = reverse("questions.aaq_step1")
        response = self.client.get(url, follow=True)
        assert not template_used(response, "questions/new_question.html")
Example #9
0
 def test_translate_with_parent_slug_while_trans_article_available(self):
     doc = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE)
     r = RevisionFactory(document=doc)
     trans_doc = DocumentFactory(parent=doc, locale="bn", slug="bn_slug")
     RevisionFactory(document=trans_doc, based_on=r)
     url = reverse("wiki.edit_document",
                   args=[doc.slug],
                   locale=trans_doc.locale)
     response = self.client.get(url)
     eq_(response.status_code, 200)
     # Check translate article template is being used
     assert template_used(response, "wiki/translate.html")
     content = pq(response.content)
     eq_(content("#id_title").val(), trans_doc.title)
     eq_(content("#id_slug").val(), trans_doc.slug)
Example #10
0
 def test_template_rendered_non_experiment_slug(self,
                                                mocked_experiments_flag,
                                                mocked_switch):
     """
     Test that a slug that does not belong in the experiments renders the default template.
     """
     mocked_switch.return_value = True
     mocked_experiments_flag.return_value = True
     ProductFactory()
     doc = DocumentFactory(slug='a-slug')
     url = reverse('wiki.document', args=[doc.slug], locale='en-US')
     client = Client(HTTP_USER_AGENT='Mozilla/5.0')
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     assert template_used(response, 'wiki/document.html')
Example #11
0
 def test_translate_with_parent_slug_while_trans_article_not_available(self):
     doc = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE)
     RevisionFactory(document=doc)
     url = reverse('wiki.edit_document', args=[doc.slug], locale='bn-BD')
     response = self.client.get(url)
     # Check redirect is happening
     eq_(response.status_code, 302)
     # get the redirected url
     response = self.client.get(url, follow=True)
     eq_(response.status_code, 200)
     # Check translate article template is being used
     assert template_used(response, 'wiki/translate.html')
     content = pq(response.content)
     # While first translation, the slug and title field is always blank.
     # So the value field should be None
     eq_(content('#id_title').val(), None)
     eq_(content('#id_slug').val(), None)
Example #12
0
    def test_redirect_from_experiment_view(self, mocked_experiments_flag,
                                           mocked_switch):
        """
        Test redirect to the document view.

        When the waffle switch is inactive and the experiment url is directly visited,
        the user needs to be redirected to the document view.
        """
        mocked_switch.return_value = False
        mocked_experiments_flag.return_value = True
        ProductFactory()
        doc = DocumentFactory(
            slug='enable-and-disable-cookies-website-preferences')
        url = reverse('wiki.document', args=[doc.slug], locale='en-US')
        client = Client(HTTP_USER_AGENT='Mozilla/5.0')
        response = client.get(url, follow=True)
        assert template_used(response, 'wiki/document.html')
Example #13
0
    def test_rendered_template_en_US_locale(self, mocked_experiments_flag,
                                            mocked_switch):
        """Test that the static page is rendered for the en-US locale."""

        mocked_switch.return_value = True
        mocked_experiments_flag.return_value = True
        doc = DocumentFactory(slug='insecure-password-warning-firefox')
        url = reverse('wiki.document', args=[doc.slug], locale='en-US')
        client = Client(HTTP_USER_AGENT='Mozilla/5.0')
        response = client.get(url)
        # Check redirect is happening
        eq_(response.status_code, 302)
        # get the redirected url
        response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        assert template_used(
            response,
            'kb-ux-experiment/insecure-password-warning-firefox.html')
Example #14
0
 def test_translate_with_parent_slug_while_trans_article_not_available(
         self):
     doc = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE)
     RevisionFactory(document=doc)
     url = reverse("wiki.edit_document", args=[doc.slug], locale="bn")
     response = self.client.get(url)
     # Check redirect is happening
     eq_(response.status_code, 302)
     # get the redirected url
     response = self.client.get(url, follow=True)
     eq_(response.status_code, 200)
     # Check translate article template is being used
     assert template_used(response, "wiki/translate.html")
     content = pq(response.content)
     # While first translation, the slug and title field is always blank.
     # So the value field should be None
     eq_(content("#id_title").val(), "")
     eq_(content("#id_slug").val(), "")
Example #15
0
    def test_aaq_new_question_inactive(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        # Log in first.
        u = UserFactory()
        self.client.login(username=u.username, password='******')

        # Then become inactive.
        u.is_active = False
        u.save()

        # Set 'in-aaq' for the session. It isn't already set because this
        # test doesn't do a GET of the form first.
        s = self.client.session
        s['in-aaq'] = True
        s.save()

        response = self._new_question(post_it=True)
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/confirm_email.html')
Example #16
0
    def test_aaq_new_question_inactive(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        # Log in first.
        u = UserFactory()
        self.client.login(username=u.username, password='******')

        # Then become inactive.
        u.is_active = False
        u.save()

        # Set 'in-aaq' for the session. It isn't already set because this
        # test doesn't do a GET of the form first.
        s = self.client.session
        s['in-aaq'] = True
        s.save()

        response = self._new_question(post_it=True)
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/confirm_email.html')
Example #17
0
 def test_it_works(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     url += '?minimal=1&mobile=1'
     res = self.client.get(url)
     assert template_used(res, 'wiki/mobile/document-minimal.html')
Example #18
0
 def test_waffle_flag(self):
     url = reverse('questions.aaq_step1')
     response = self.client.get(url, follow=True)
     assert template_used(response, 'questions/new_question_react.html')
Example #19
0
 def test_logged_out(self):
     """New question is posted through mobile."""
     response = self._new_question()
     eq_(200, response.status_code)
     assert template_used(response,
                          'questions/mobile/new_question_login.html')
Example #20
0
 def test_it_works(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     res = self.client.get(url)
     eq_(res.status_code, 200)
     assert template_used(res, 'wiki/mobile/document.html')
Example #21
0
 def test_only_if_mobile(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     url += '?minimal=1'
     res = self.client.get(url)
     assert template_used(res, 'wiki/document.html')
Example #22
0
 def test_it_works(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     url += '?minimal=1&mobile=1'
     res = self.client.get(url)
     assert template_used(res, 'wiki/mobile/document-minimal.html')
Example #23
0
 def test_waffle_flag(self):
     url = reverse("questions.aaq_step1")
     response = self.client.get(url, follow=True)
     assert template_used(response, "questions/new_question_react.html")
Example #24
0
 def test_only_if_mobile(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     url += '?minimal=1'
     res = self.client.get(url)
     assert template_used(res, 'wiki/document.html')
Example #25
0
 def test_it_works(self):
     url = reverse('wiki.document', args=[self.doc.slug], locale='en-US')
     res = self.client.get(url)
     eq_(res.status_code, 200)
     assert template_used(res, 'wiki/mobile/document.html')
Example #26
0
 def test_logged_out(self):
     """New question is posted through mobile."""
     response = self._new_question()
     eq_(200, response.status_code)
     assert template_used(response, 'questions/mobile/new_question_login.html')