class ArticleServiceTest(TestCase): def create_article(self, title="Test Title", content="Test Content", promoted="t", user_id=randint(1, 100), description="Test Description", status=2): return Article.objects.create(title=title, content=content, promoted=promoted, user_id=user_id, description=description, status=status) def create_categories(self, title="category1"): return ArticleCategory.objects.create(title=title) def setUp(self): for i in range(1, 5): self.create_article(title="Title%s" % i) self.articleService = ArticleService() self.promoted_article_list = self.articleService.get_promoted_articles() def get_promoted_field_from_article_list(self): return lambda x: x.promoted def iterate_promoted_article_list(self): return iter(self.articleService.get_promoted_articles()) def get_list_of_promoted_fields_from_article_model_list(self): return map(self.get_promoted_field_from_article_list(), self.iterate_promoted_article_list()) def test_promoted_articles_fetched_only(self): filter(self.assertTrue, self.get_list_of_promoted_fields_from_article_model_list()) def test_promoted_articles_count_is_3(self): self.assertEquals(self.promoted_article_list.__len__(), 3) def test_get_policy_edits_category(self): self.create_categories(title="Perspectives") category = self.articleService.get_perspectives_category() self.assertIn("perspectives", reduce(get_title, category).title.lower())
class ArticleCategoryServiceTest(TestCase): def create_article(self, title="Test Title", content="Test Content", promoted="t", user_id=randint(1, 100), description="Test Description", status=2): return Article.objects.create(title=title, content=content, promoted=promoted, user_id=user_id, description=description, status=status) def create_categories(self, title="category1"): return ArticleCategory.objects.create(title=title) def add_categories(self, article): for article_category in self.article_categories: article.article_categories.add(article_category) return article def setUp(self): self.articles = [] self.article_categories = [] for i in range(1, 5): self.articles.append(self.create_article(title="Title%s" % i, promoted='f')) self.article_categories.append(self.create_categories(title="category%s" % i)) self.article_without_categories = self.create_article(title="No Category Article", promoted='f') self.articles = map(self.add_categories, self.articles) self.articleService = ArticleService() self.categories = self.articleService.get_all_article_categories() self.article_in_category = self.articleService.get_all_articles_in_category(self.article_categories[0]) def test_get_all_categories(self): self.assertEquals(4, len(self.categories)) def test_get_articles_in_category(self): self.assertEquals(4, len(self.article_in_category)) def test_no_articles_returned_when_no_category_is_assigned(self): self.assertNotIn(self.article_without_categories, self.article_in_category)
class ArticleDetail: def __init__(self): self.article_service = ArticleService() self.pdf_generator = PDFGenerator() self.style_article_pdf = StyleArticlePDF() def article_detail(self, request, slug, template="article/article_detail.html"): articles = self.article_service.get_published_articles_with_related_articles(request) article = process_tag_or_categories_or_article(slug, articles) page = get_page(request) article_map = get_article_map(True) if article_is_a_perspective(article): request.path_info = '/policy-edits/' page = get_page(request) return render(request, template, {"article": article, "page": page, 'form': MapFormForSideBar(initial={'map': article_map}), "latest_commented_articles": self.article_service.get_latest_unique_commented_on_articles()}) def build_response(self, article_title): response = HttpResponse(content_type=PDF_CONTENT_TYPE) response['Content-Disposition'] = urllib.quote(self.pdf_generator.generate_pdf_filename(article_title)) return response def build_pdf_content(self, article): return self.style_article_pdf.sytle_pdf_content(article) def article_download(self, request, slug): article = process_tag_or_categories_or_article(slug, self.article_service.get_published_articles_with_related_articles( request)) response = self.pdf_generator.generate_pdf_from_html(html=self.build_pdf_content(article), file=self.build_response(article_title=article.slug)) return response
def setUp(self): self.articles = [] self.article_categories = [] for i in range(1, 5): self.articles.append(self.create_article(title="Title%s" % i, promoted='f')) self.article_categories.append(self.create_categories(title="category%s" % i)) self.article_without_categories = self.create_article(title="No Category Article", promoted='f') self.articles = map(self.add_categories, self.articles) self.articleService = ArticleService() self.categories = self.articleService.get_all_article_categories() self.article_in_category = self.articleService.get_all_articles_in_category(self.article_categories[0])
def setUp(self): for i in range(1, 5): self.create_article(title="Title%s" % i) self.articleService = ArticleService() self.promoted_article_list = self.articleService.get_promoted_articles()
def __init__(self): self.article_service = ArticleService() self.pdf_generator = PDFGenerator() self.style_article_pdf = StyleArticlePDF()
def article_categories(*args): article_service = ArticleService() return list(article_service.get_all_article_categories())