def test_that_blog_article_page_should_have_the_first_blog_index_page_as_parent_if_none_is_specified(self): blog_index_page = BlogIndexPageFactory(title="First Index Page") BlogIndexPageFactory(title="Second Index Page") blog_article_page = BlogArticlePageFactory() self.assertEqual(blog_article_page.get_parent(), blog_index_page)
def test_that_generate_article_data_should_generate_valid_data_for_blog_article_page_object(self): EmployeeFactory() article_data = self.load_initial_data_command._generate_article_data(1, Employees.objects.all()) BlogArticlePageFactory(**article_data) self.assertEqual(len(article_data.items()), 4) self.assertEqual(article_data["author"], Employees.objects.all().first()) self.assertTrue(article_data["is_main_article"]) self.assertIsInstance(article_data["cover_photo"], Image) self.assertIsInstance(article_data["article_photo"], Image)
def test_that_generate_recommended_articles_should_generate_valid_stream_of_articles_for_recommended_articles_field( self, ): for _ in range(10): BlogArticlePageFactory() for article in BlogArticlePage.objects.all(): recommended_articles = self.load_initial_data_command._generate_recommended_articles(article.id) article.recommended_articles = recommended_articles self._assert_is_stream_value(recommended_articles, PageChooserBlock, "page") article.save()
def test_that_generate_list_of_article_ids_for_recommended_articles_should_return_a_list_of_unique_ids_excluding_provided_target_id( self, ): for _ in range(20): BlogArticlePageFactory() for article in BlogArticlePage.objects.all(): article_ids = self.load_initial_data_command._generate_list_of_article_ids_for_recommended_articles( article.id ) self.assertTrue(article.id not in article_ids) ids_occurrences = Counter(article_ids) for occurrences in ids_occurrences.values(): self.assertEqual(occurrences, 1)
def test_that_blog_article_page_factory_should_create_new_blog_index_page_if_none_exist(self): BlogArticlePageFactory() self.assertEqual(BlogIndexPage.objects.all().count(), 1)
def add_articles(self): employees = Employees.objects.all() for article_number in range(0, self.articles_limit): article_data = self._generate_article_data(article_number, employees) BlogArticlePageFactory(**article_data) self._add_recommendations_to_articles()