def test_create_new_banner_relations(self):
        self.yourmind = self.mk_section(
            SectionIndexPage.objects.child_of(self.main).first(),
            title='Your mind')
        self.yourmind2 = self.mk_section(
            SectionIndexPage.objects.child_of(
                self.main2).first(), title='Your mind')
        first_main_article = self.mk_article(
            parent=self.yourmind, title='first_main_article')
        first_main_banner = BannerPage(
            title='first_main_banner', slug='firstmainbanner',
            banner_link_page=first_main_article)
        self.banner_index = BannerIndexPage.objects.child_of(
            self.main).first()
        self.banner_index.add_child(instance=first_main_banner)
        first_main_banner.save_revision().publish()
        second_main_article = self.mk_article(
            parent=self.yourmind2, title='first_main_article')
        second_main_article.slug = first_main_article.slug
        second_main_article.save_revision().publish()
        second_main_banner = BannerPage(
            title='second_main_banner', slug='secondmainbanner',
            banner_link_page=first_main_article)
        self.banner_index2 = BannerIndexPage.objects.child_of(
            self.main2).first()
        self.banner_index2.add_child(instance=second_main_banner)
        second_main_banner.save_revision().publish()

        out = StringIO()
        call_command('create_new_banner_link_page_relations', stdout=out)
        second_main_banner = BannerPage.objects.get(pk=second_main_banner.pk)
        self.assertEqual(
            second_main_banner.banner_link_page.pk, second_main_article.pk)
 def mk_banners(self, parent, count=2, **kwargs):
     banners = []
     for i in range(count):
         data = {}
         data.update({
             'title': 'Test Banner {}'.format(i),
         })
         data.update(kwargs)
         data.update({'slug': generate_slug(data['title'])})
         banner = BannerPage(**data)
         parent.add_child(instance=banner)
         banner.save_revision().publish()
         banners.append(banner)
     return banners
Exemple #3
0
 def test_main_returns_bannerpages(self):
     banner = BannerPage(title='test banner')
     self.banner_index.add_child(instance=banner)
     banner.save_revision().publish()
     banner = BannerPage(title='test banner 2')
     self.banner_index.add_child(instance=banner)
     banner.save_revision().publish()
     self.assertEqual(self.main.bannerpages().count(), 2)
Exemple #4
0
    def test_banner_importable(self):
        content = constants.BANNER_PAGE_RESPONSE
        content_copy = dict(content)

        # Validate Assumptions
        #   The images have already been imported
        #   The record keeper has mapped the relationship

        foreign_image_id = content["banner"]["id"]
        image = Image.objects.create(
            title=content["banner"]["title"],
            file=get_test_image_file(),
        )

        record_keeper = importers.RecordKeeper()
        record_keeper.record_image_relation(foreign_image_id, image.id)

        class_ = BannerPage

        page = BannerPage.create_page(content_copy,
                                      class_,
                                      record_keeper=record_keeper)

        self.assertEqual(page.title, content["title"])
        self.assertEqual(page.external_link, content["external_link"])

        # check that banner link has been created
        self.assertEqual(
            (record_keeper.foreign_to_foreign_map["banner_link_page"][
                content["id"]]), content["banner_link_page"]["id"])

        # check that banner image has been attached
        self.assertTrue(page.banner)
        self.assertEqual(page.banner, image)
        self.assertEqual(page.banner.title, content["banner"]["title"])
Exemple #5
0
 def mk_banners(self, parent, count=2, **kwargs):
     banners = []
     for i in range(count):
         data = {}
         data.update({
             'title': 'Test Banner {}'.format(i),
         })
         data.update(kwargs)
         data.update({
             'slug': generate_slug(data['title'])
         })
         banner = BannerPage(**data)
         parent.add_child(instance=banner)
         banner.save_revision().publish()
         banners.append(banner)
     return banners
Exemple #6
0
    def test_banner_importable(self):
        content = constants.BANNER_PAGE_RESPONSE
        content_copy = dict(content)

        # Validate Assumptions
        #   The images have already been imported
        #   The record keeper has mapped the relationship

        foreign_image_id = content["banner"]["id"]
        image = Image.objects.create(
            title=content["banner"]["title"],
            file=get_test_image_file(),
        )

        record_keeper = importers.RecordKeeper()
        record_keeper.record_image_relation(foreign_image_id, image.id)

        class_ = BannerPage

        page = BannerPage.create_page(
            content_copy, class_, record_keeper=record_keeper)

        self.assertEqual(page.title, content["title"])
        self.assertEqual(page.external_link, content["external_link"])

        # check that banner link has been created
        self.assertEqual(
            (record_keeper.foreign_to_foreign_map["banner_link_page"]
                [content["id"]]),
            content["banner_link_page"]["id"])

        # check that banner image has been attached
        self.assertTrue(page.banner)
        self.assertEqual(page.banner, image)
        self.assertEqual(page.banner.title, content["banner"]["title"])
    def test_hide_on_freebasics_banner(self):
        template_settings = deepcopy(settings.TEMPLATES)
        template_settings[0]['DIRS'] = [
            join(settings.PROJECT_ROOT, 'templates', 'springster')
        ]

        with self.settings(TEMPLATES=template_settings):
            banner = BannerPage(title='test banner',
                                hide_banner_on_freebasics=True)
            self.banner_index.add_child(instance=banner)
            banner.save_revision().publish()
            client = Client(
                HTTP_VIA='Internet.org',
                HTTP_X_IORG_FBS='true',
                HTTP_USER_AGENT='Mozilla/5.0 (Linux; Android 5.1;'
                ' VFD 100 Build/LMY47I; wv) AppleWebKit/537.36'
                ' (KHTML, like Gecko) Version/4.0 Chrome/50.0.2661.86'
                ' Mobile Safari/537[FBAN/InternetOrgApp; FBAV/7.0;]',
                HTTP_HOST=self.main.get_site().hostname)
            response = client.get('/')
            self.assertNotContains(response, 'test banner')
Exemple #8
0
 def test_main_returns_bannerpages(self):
     banner = BannerPage(title='test banner')
     self.banner_index.add_child(instance=banner)
     banner.save_revision().publish()
     banner = BannerPage(title='test banner 2')
     self.banner_index.add_child(instance=banner)
     banner.save_revision().publish()
     self.assertEqual(self.main.bannerpages().count(), 2)
    def test_bannerpages_with_position_out_of_range(self):
        banner = BannerPage(title='test banner')
        self.banner_index.add_child(instance=banner)
        banner.save_revision().publish()
        banner2 = BannerPage(title='test banner 2')
        self.banner_index.add_child(instance=banner2)
        banner2.save_revision().publish()
        banner3 = BannerPage(title='test banner 3')
        self.banner_index.add_child(instance=banner3)
        banner3.save_revision().publish()
        self.assertEqual(self.main.bannerpages().count(), 3)

        request = self.factory.get('/')
        request.site = self.site

        self.assertEqual(
            bannerpages({
                'locale_code': 'en',
                'request': request
            }, position=4), None)