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)
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)
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)
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)
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"])
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"])