Exemplo n.º 1
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"])
Exemplo n.º 2
0
    def test_article_importable(self):
        content = constants.ARTICLE_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["image"]["id"]
        image = Image.objects.create(
            title=content["image"]["title"],
            file=get_test_image_file(),
        )

        foreign_social_media_image_id = content["social_media_image"]["id"]
        social_media_image = Image.objects.create(
            title=content["social_media_image"]["title"],
            file=get_test_image_file(),
        )

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

        class_ = ArticlePage

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

        self.check_article_and_footer_fields(page, content, record_keeper)
Exemplo n.º 3
0
 def setUp(self):
     self.fake_base_url = "http://localhost:8000"
     self.mk_main()
     self.record_keeper = importers.RecordKeeper()
     self.importer = importers.ImageImporter(
         self.site.pk, self.fake_base_url,
         record_keeper=self.record_keeper)
Exemplo n.º 4
0
    def test_section_importable(self):
        content = constants.SECTION_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["image"]["id"]
        image = Image.objects.create(
            title=content["image"]["title"],
            file=get_test_image_file(),
        )

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

        class_ = SectionPage

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

        self.assertEqual(page.title, content["title"])
        self.assertEqual(page.description, content["description"])
        self.assertEqual(page.extra_style_hints, content["extra_style_hints"])
        self.assertEqual(page.monday_rotation, content["monday_rotation"])
        self.assertEqual(page.tuesday_rotation, content["tuesday_rotation"])
        self.assertEqual(page.wednesday_rotation,
                         content["wednesday_rotation"])
        self.assertEqual(page.thursday_rotation, content["thursday_rotation"])
        self.assertEqual(page.friday_rotation, content["friday_rotation"])
        self.assertEqual(page.saturday_rotation, content["saturday_rotation"])
        self.assertEqual(page.sunday_rotation, content["sunday_rotation"])
        self.assertEqual(page.content_rotation_start_date,
                         content["content_rotation_start_date"])
        self.assertEqual(page.content_rotation_end_date,
                         content["content_rotation_end_date"])

        # NESTED FIELDS
        self.assertTrue(hasattr(page.time, "stream_data"))
        self.assertEqual(page.time.stream_data, content["time"])

        # Check that image has been added
        self.assertTrue(page.image)
        self.assertEqual(page.image.title, content["image"]["title"])
Exemplo n.º 5
0
    def test_article_body_not_importable(self):
        content = constants.ARTICLE_PAGE_RESPONSE_STREAM_FIELDS
        content_copy = dict(content)

        record_keeper = importers.RecordKeeper()

        class_ = ArticlePage

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

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

        self.assertTrue(content["id"] in record_keeper.article_bodies)
        self.assertEqual(record_keeper.article_bodies[content["id"]],
                         content["body"])
Exemplo n.º 6
0
    def test_image_not_imported_logs_error(self):
        content = constants.ARTICLE_WITH_ONLY_IMAGE_RESPONSE
        content_copy = dict(content)

        # Break the assumptions that the images have already
        # been imported thus the record keeper has mapped
        # the relationship

        record_keeper = importers.RecordKeeper()
        logger = importers.Logger()

        class_ = ArticlePage

        ArticlePage.create_page(content_copy,
                                class_,
                                record_keeper=record_keeper,
                                logger=logger)

        self.assertTrue(len(logger.record), 1)
        error_log = logger.record[0]
        self.assertEqual(error_log["log_type"], ERROR)
Exemplo n.º 7
0
 def setUp(self):
     self.record_keeper = importers.RecordKeeper()