Beispiel #1
0
    def setUp(self):
        from ask_cfpb.models import Answer
        from v1.models import HomePage

        self.ROOT_PAGE = HomePage.objects.get(slug="cfgov")
        self.english_parent_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerLandingPage",
            "Ask CFPB",
            ENGLISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language="en",
            live=True,
        )
        self.spanish_parent_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerLandingPage",
            "Obtener respuestas",
            SPANISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language="es",
            live=True,
        )
        self.test_answer = baker.make(Answer)
        self.test_answer2 = baker.make(Answer)
        self.english_answer_page = AnswerPage(
            answer_base=self.test_answer,
            language="en",
            slug="test-question1-en-{}".format(self.test_answer.pk),
            title="Test question1",
            answer_content="Test answer1.",
            question="Test question1.",
        )
        self.english_parent_page.add_child(instance=self.english_answer_page)
        self.english_answer_page.save_revision().publish()
        self.english_answer_page2 = AnswerPage(
            answer_base=self.test_answer2,
            language="en",
            slug="test-question2-en-{}".format(self.test_answer2.pk),
            title="Test question2",
            answer_content="Test answer2.",
            question="Test question2.",
        )
        self.english_parent_page.add_child(instance=self.english_answer_page2)
        self.english_answer_page2.save_revision().publish()
        self.site = baker.make(
            Site,
            root_page=self.ROOT_PAGE,
            hostname="localhost",
            port=8000,
            is_default_site=True,
        )
        self.sharing_site = baker.make(
            SharingSite,
            site=self.site,
            hostname="preview.localhost",
            port=8000,
        )
Beispiel #2
0
 def setUp(self):
     from v1.models import HomePage
     from ask_cfpb.models import Answer
     self.ROOT_PAGE = HomePage.objects.get(slug='cfgov')
     self.english_parent_page = get_or_create_page(apps,
                                                   'ask_cfpb',
                                                   'AnswerLandingPage',
                                                   'Ask CFPB',
                                                   ENGLISH_PARENT_SLUG,
                                                   self.ROOT_PAGE,
                                                   language='en',
                                                   live=True)
     self.spanish_parent_page = get_or_create_page(apps,
                                                   'ask_cfpb',
                                                   'AnswerLandingPage',
                                                   'Obtener respuestas',
                                                   SPANISH_PARENT_SLUG,
                                                   self.ROOT_PAGE,
                                                   language='es',
                                                   live=True)
     self.test_answer = mommy.make(Answer,
                                   answer="Test answer1.",
                                   question="Test question1.",
                                   slug='test-question1')
     self.test_answer2 = mommy.make(Answer,
                                    answer="Test answer2.",
                                    question="Test question2.",
                                    slug='test-question2')
     self.english_answer_page = AnswerPage(
         answer_base=self.test_answer,
         answer_id=self.test_answer.pk,
         language='en',
         slug='test-question1-en-{}'.format(self.test_answer.pk),
         title='Test question1',
         answer='Test answer1.',
         question='Test question1.')
     self.english_parent_page.add_child(instance=self.english_answer_page)
     self.english_answer_page.save_revision().publish()
     self.english_answer_page2 = AnswerPage(
         answer_base=self.test_answer2,
         answer_id=self.test_answer2.pk,
         language='en',
         slug='test-question2-en-{}'.format(self.test_answer2.pk),
         title='Test question2',
         answer='Test answer2.',
         question='Test question2.')
     self.english_parent_page.add_child(instance=self.english_answer_page2)
     self.english_answer_page2.save_revision().publish()
     self.site = mommy.make(Site,
                            root_page=self.ROOT_PAGE,
                            hostname='localhost',
                            port=8000,
                            is_default_site=True)
     self.sharing_site = mommy.make(SharingSite,
                                    site=self.site,
                                    hostname='preview.localhost',
                                    port=8000)
Beispiel #3
0
 def test_create_answer_id_spanish(self):
     """Test that Spanish page creation generates an Ask ID and pages."""
     request = HttpRequest
     request.user = self.user
     test_page = AnswerPage(
         slug='spanish-page-1', title='Spanish page 1', language='es')
     self.spanish_landing_page.add_child(instance=test_page)
     test_page.save()
     create_answer_id(request, test_page)
     self.assertEqual(test_page.slug, 'spanish-page-1-es-{}'.format(
         Answer.objects.order_by('pk').last().pk))
     self.assertIsNotNone(test_page.answer_base)
     self.assertIsNotNone(test_page.answer_base.english_page)
     self.assertIsNotNone(test_page.answer_base.spanish_page)
Beispiel #4
0
 def test_create_answer_id_english(self):
     """Test that English page creation generates an Ask ID and pages."""
     request = HttpRequest
     request.user = self.user
     test_page = AnswerPage(slug='test-page', title='Test page')
     self.english_landing_page.add_child(instance=test_page)
     test_page.save()
     create_answer_id(request, test_page)
     self.assertEqual(
         test_page.slug,
         'test-page-en-{}'.format(Answer.objects.order_by('pk').last().pk))
     self.assertIsNotNone(test_page.answer_base)
     self.assertIsNotNone(test_page.answer_base.english_page)
     self.assertIsNotNone(test_page.answer_base.spanish_page)
 def create_sister_page(new_page, answer_base):
     sister_map = {
         'es': {
             'language': 'en',
             'parent': Page.objects.get(slug='ask-cfpb').specific,
             'title_prefix': 'English draft of',
         },
         'en': {
             'language': 'es',
             'parent': Page.objects.get(slug='obtener-respuestas').specific,
             'title_prefix': 'Spanish draft of',
         }
     }
     sister_values = sister_map[new_page.language]
     sister_page = AnswerPage(
         live=False,
         language=sister_values['language'],
         title="{} {}-{}-{}".format(
             sister_values['title_prefix'],
             new_page.title,
             sister_values['language'],
             answer_base.pk),
         answer_base=answer_base,
     )
     sister_values['parent'].add_child(instance=sister_page)
     return sister_page
Beispiel #6
0
class AnswerPagePreviewCase(TestCase):
    def setUp(self):
        from v1.models import HomePage
        from ask_cfpb.models import Answer
        self.ROOT_PAGE = HomePage.objects.get(slug='cfgov')
        self.english_parent_page = get_or_create_page(apps,
                                                      'ask_cfpb',
                                                      'AnswerLandingPage',
                                                      'Ask CFPB',
                                                      ENGLISH_PARENT_SLUG,
                                                      self.ROOT_PAGE,
                                                      language='en',
                                                      live=True)
        self.spanish_parent_page = get_or_create_page(apps,
                                                      'ask_cfpb',
                                                      'AnswerLandingPage',
                                                      'Obtener respuestas',
                                                      SPANISH_PARENT_SLUG,
                                                      self.ROOT_PAGE,
                                                      language='es',
                                                      live=True)
        self.test_answer = mommy.make(Answer,
                                      answer="Test answer1.",
                                      question="Test question1.",
                                      slug='test-question1')
        self.test_answer2 = mommy.make(Answer,
                                       answer="Test answer2.",
                                       question="Test question2.",
                                       slug='test-question2')
        self.english_answer_page = AnswerPage(
            answer_base=self.test_answer,
            answer_id=self.test_answer.pk,
            language='en',
            slug='test-question1-en-{}'.format(self.test_answer.pk),
            title='Test question1',
            answer='Test answer1.',
            question='Test question1.')
        self.english_parent_page.add_child(instance=self.english_answer_page)
        self.english_answer_page.save_revision().publish()
        self.english_answer_page2 = AnswerPage(
            answer_base=self.test_answer2,
            answer_id=self.test_answer2.pk,
            language='en',
            slug='test-question2-en-{}'.format(self.test_answer2.pk),
            title='Test question2',
            answer='Test answer2.',
            question='Test question2.')
        self.english_parent_page.add_child(instance=self.english_answer_page2)
        self.english_answer_page2.save_revision().publish()
        self.site = mommy.make(Site,
                               root_page=self.ROOT_PAGE,
                               hostname='localhost',
                               port=8000,
                               is_default_site=True)
        self.sharing_site = mommy.make(SharingSite,
                                       site=self.site,
                                       hostname='preview.localhost',
                                       port=8000)

    @mock.patch('ask_cfpb.views.ServeView.serve_latest_revision')
    def test_preview_page(self, mock_serve):
        from ask_cfpb.views import view_answer
        test_request = HttpRequest()
        test_request.META['SERVER_NAME'] = 'preview.localhost'
        test_request.META['SERVER_PORT'] = 8000
        view_answer(test_request, 'test-question1', 'en', self.test_answer.pk)
        self.assertEqual(mock_serve.call_count, 1)

    def test_answer_page_not_live(self):
        from ask_cfpb.views import view_answer
        page = self.test_answer.english_page
        page.unpublish()
        test_request = HttpRequest()
        with self.assertRaises(Http404):
            view_answer(test_request, 'test-question', 'en',
                        self.test_answer.pk)

    def test_page_redirected(self):
        page = self.english_answer_page
        page.get_latest_revision().publish()
        page.redirect_to_page = self.english_answer_page2
        page.save()
        page.save_revision().publish()
        response = self.client.get(page.url)
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.url, self.english_answer_page2.url)
Beispiel #7
0
class AnswerPagePreviewTestCase(TestCase):
    def setUp(self):
        from ask_cfpb.models import Answer
        from v1.models import HomePage

        self.ROOT_PAGE = HomePage.objects.get(slug="cfgov")
        self.english_parent_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerLandingPage",
            "Ask CFPB",
            ENGLISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language="en",
            live=True,
        )
        self.spanish_parent_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerLandingPage",
            "Obtener respuestas",
            SPANISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language="es",
            live=True,
        )
        self.test_answer = baker.make(Answer)
        self.test_answer2 = baker.make(Answer)
        self.english_answer_page = AnswerPage(
            answer_base=self.test_answer,
            language="en",
            slug="test-question1-en-{}".format(self.test_answer.pk),
            title="Test question1",
            answer_content="Test answer1.",
            question="Test question1.",
        )
        self.english_parent_page.add_child(instance=self.english_answer_page)
        self.english_answer_page.save_revision().publish()
        self.english_answer_page2 = AnswerPage(
            answer_base=self.test_answer2,
            language="en",
            slug="test-question2-en-{}".format(self.test_answer2.pk),
            title="Test question2",
            answer_content="Test answer2.",
            question="Test question2.",
        )
        self.english_parent_page.add_child(instance=self.english_answer_page2)
        self.english_answer_page2.save_revision().publish()
        self.site = baker.make(
            Site,
            root_page=self.ROOT_PAGE,
            hostname="localhost",
            port=8000,
            is_default_site=True,
        )
        self.sharing_site = baker.make(
            SharingSite,
            site=self.site,
            hostname="preview.localhost",
            port=8000,
        )

    @mock.patch("ask_cfpb.views.ServeView.serve")
    def test_preview_page(self, mock_serve):
        from ask_cfpb.views import view_answer

        test_request = HttpRequest()
        test_request.META["SERVER_NAME"] = "preview.localhost"
        test_request.META["SERVER_PORT"] = 8000
        view_answer(test_request, "test-question1", "en", self.test_answer.pk)
        self.assertEqual(mock_serve.call_count, 1)

    def test_answer_page_not_live(self):
        from ask_cfpb.views import view_answer

        page = self.test_answer.english_page
        page.unpublish()
        test_request = HttpRequest()
        with self.assertRaises(Http404):
            view_answer(test_request, "test-question", "en",
                        self.test_answer.pk)

    def test_page_redirected(self):
        page = self.english_answer_page
        page.get_latest_revision().publish()
        page.redirect_to_page = self.english_answer_page2
        page.save()
        page.save_revision().publish()
        response = self.client.get(page.url)
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.url, self.english_answer_page2.url)
Beispiel #8
0
 def setUp(self):
     from v1.models import HomePage
     from ask_cfpb.models import Answer
     self.ROOT_PAGE = HomePage.objects.get(slug='cfgov')
     self.english_parent_page = get_or_create_page(
         apps,
         'ask_cfpb',
         'AnswerLandingPage',
         'Ask CFPB',
         ENGLISH_PARENT_SLUG,
         self.ROOT_PAGE,
         language='en',
         live=True)
     self.spanish_parent_page = get_or_create_page(
         apps,
         'ask_cfpb',
         'AnswerLandingPage',
         'Obtener respuestas',
         SPANISH_PARENT_SLUG,
         self.ROOT_PAGE,
         language='es',
         live=True)
     self.test_answer = mommy.make(
         Answer,
         answer="Test answer1.",
         question="Test question1.",
         slug='test-question1')
     self.test_answer2 = mommy.make(
         Answer,
         answer="Test answer2.",
         question="Test question2.",
         slug='test-question2')
     self.english_answer_page = AnswerPage(
         answer_base=self.test_answer,
         answer_id=self.test_answer.pk,
         language='en',
         slug='test-question1-en-{}'.format(self.test_answer.pk),
         title='Test question1',
         answer='Test answer1.',
         question='Test question1.')
     self.english_parent_page.add_child(instance=self.english_answer_page)
     self.english_answer_page.save_revision().publish()
     self.english_answer_page2 = AnswerPage(
         answer_base=self.test_answer2,
         answer_id=self.test_answer2.pk,
         language='en',
         slug='test-question2-en-{}'.format(self.test_answer2.pk),
         title='Test question2',
         answer='Test answer2.',
         question='Test question2.')
     self.english_parent_page.add_child(instance=self.english_answer_page2)
     self.english_answer_page2.save_revision().publish()
     self.site = mommy.make(
         Site,
         root_page=self.ROOT_PAGE,
         hostname='localhost',
         port=8000,
         is_default_site=True)
     self.sharing_site = mommy.make(
         SharingSite,
         site=self.site,
         hostname='preview.localhost',
         port=8000)
Beispiel #9
0
class AnswerPagePreviewCase(TestCase):

    def setUp(self):
        from v1.models import HomePage
        from ask_cfpb.models import Answer
        self.ROOT_PAGE = HomePage.objects.get(slug='cfgov')
        self.english_parent_page = get_or_create_page(
            apps,
            'ask_cfpb',
            'AnswerLandingPage',
            'Ask CFPB',
            ENGLISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language='en',
            live=True)
        self.spanish_parent_page = get_or_create_page(
            apps,
            'ask_cfpb',
            'AnswerLandingPage',
            'Obtener respuestas',
            SPANISH_PARENT_SLUG,
            self.ROOT_PAGE,
            language='es',
            live=True)
        self.test_answer = mommy.make(
            Answer,
            answer="Test answer1.",
            question="Test question1.",
            slug='test-question1')
        self.test_answer2 = mommy.make(
            Answer,
            answer="Test answer2.",
            question="Test question2.",
            slug='test-question2')
        self.english_answer_page = AnswerPage(
            answer_base=self.test_answer,
            answer_id=self.test_answer.pk,
            language='en',
            slug='test-question1-en-{}'.format(self.test_answer.pk),
            title='Test question1',
            answer='Test answer1.',
            question='Test question1.')
        self.english_parent_page.add_child(instance=self.english_answer_page)
        self.english_answer_page.save_revision().publish()
        self.english_answer_page2 = AnswerPage(
            answer_base=self.test_answer2,
            answer_id=self.test_answer2.pk,
            language='en',
            slug='test-question2-en-{}'.format(self.test_answer2.pk),
            title='Test question2',
            answer='Test answer2.',
            question='Test question2.')
        self.english_parent_page.add_child(instance=self.english_answer_page2)
        self.english_answer_page2.save_revision().publish()
        self.site = mommy.make(
            Site,
            root_page=self.ROOT_PAGE,
            hostname='localhost',
            port=8000,
            is_default_site=True)
        self.sharing_site = mommy.make(
            SharingSite,
            site=self.site,
            hostname='preview.localhost',
            port=8000)

    @mock.patch('ask_cfpb.views.ServeView.serve_latest_revision')
    def test_preview_page(self, mock_serve):
        from ask_cfpb.views import view_answer
        test_request = HttpRequest()
        test_request.META['SERVER_NAME'] = 'preview.localhost'
        test_request.META['SERVER_PORT'] = 8000
        view_answer(
            test_request, 'test-question1', 'en', self.test_answer.pk)
        self.assertEqual(mock_serve.call_count, 1)

    def test_answer_page_not_live(self):
        from ask_cfpb.views import view_answer
        page = self.test_answer.english_page
        page.unpublish()
        test_request = HttpRequest()
        with self.assertRaises(Http404):
            view_answer(
                test_request,
                'test-question',
                'en',
                self.test_answer.pk)

    def test_page_redirected(self):
        page = self.english_answer_page
        page.get_latest_revision().publish()
        page.redirect_to_page = self.english_answer_page2
        page.save()
        page.save_revision().publish()
        response = self.client.get(page.url)
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response.url, self.english_answer_page2.url)