Ejemplo n.º 1
0
    def test_filter_by_source(self):
        source = DataSourceFactory()
        ArticleFactory.create_batch(2)
        ArticleFactory.create_batch(2, source=source, active=True)

        url = f"{reverse('home')}?source={source.id}"
        response = self.client.get(url)
        # Article
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 2)
Ejemplo n.º 2
0
    def test_view_filters_by_language(self):
        ArticleFactory(language="ru", active=True)
        ArticleFactory(language="en", active=True)

        response_ru = self.client.get("/", data={"language": "ru"})
        response_en = self.client.get("/", data={"language": "en"})
        response = self.client.get("/")

        self.assertEqual(response_ru.context_data['object_list'].count(), 1)
        self.assertEqual(response_en.context_data['object_list'].count(), 1)
        self.assertEqual(response.context_data['object_list'].count(), 2)
Ejemplo n.º 3
0
 def test_list(self):
     article1, article2 = ArticleFactory.create_batch(2)
     response = self.client.get(reverse("article_list"))
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(
         [article["id"] for article in response.data], [article1.id, article2.id]
     )
Ejemplo n.º 4
0
 def test_update(self):
     article = ArticleFactory(slug="my-slug")
     data = {"slug": "updated-slug"}
     url = reverse("article_detail", args=(article.id,))
     response = self.client.patch(url, data=data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     updated_article = Article.objects.get(id=article.id)
     self.assertEqual(updated_article.slug, "updated-slug")
Ejemplo n.º 5
0
 def test_full_validate_fills_language_field(self):
     article = ArticleFactory.build(
         text='Период: Дней: 30<br /><br />Бюджет: 30000 RUB<br /> Пишите в телеграм или на почту'
     )
     a = Article.objects.clean_create(
         **model_to_dict(article)
     )
     self.assertIsNotNone(a.language)
Ejemplo n.º 6
0
 def test_title_generated_upon_clean(self):
     article = ArticleFactory.build(
         title=None,
         source=DataSourceFactory()
     )
     article.full_clean()
     article.save()
     article.refresh_from_db()
     self.assertIsNotNone(article.title)
Ejemplo n.º 7
0
 def test_task_handles_duplicated_url(self, get_data_mock):
     ArticleFactory(url='https://hh.ru/vacancy/26546774')
     data = [{
         'url': 'https://hh.ru/vacancy/26546774',
         'source_datetime': datetime.datetime(2018, 7, 13, 10, 59, 54),
         'text':
         '<p>Вакансия компании: БОЛЬШАЯ ТРОЙКА</p><p>Создана: 13.07.2018</p><p>Регион: Москва</p><p>Предполагаемый уровень месячного дохода: от\xa0120\xa0000\xa0до\xa0180\xa0000\xa0руб.</p>',
         'title': 'Backend python/Django разработчик',
     }]
     get_data_mock.return_value = data
     AggregateContent().run()
Ejemplo n.º 8
0
 def test_filter(self):
     article1, article2, article3 = ArticleFactory.create_batch(3)
     # test filter with title
     for article in [article1, article2, article3]:
         response = self.client.get(reverse("article_list") + f"?title={article.title}")
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         self.assertEqual(
             [article["id"] for article in response.data], [article.id]
         )
     # test filter with the content
     response = self.client.get(reverse("article_list") + "?content=Lorem ipsum")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(
         [article["id"] for article in response.data], [article1.id, article2.id, article3.id]
     )
Ejemplo n.º 9
0
    def create_articles(self):
        titles = ['About', 'News', 'Program', 'Speakers', 'Sponsors']
        langs = list(Language.objects.all())

        for i, title in enumerate(titles):
            translator = UserFactory(raw_password='******',
                                     is_translator=True,
                                     is_staff=True)
            article = ArticleFactory(author=translator)
            Menu.objects.create(article=article, position=i)

            for lang in langs:
                TranslationFactory(article=article,
                                   lang=lang,
                                   author=translator,
                                   title=title,
                                   published=True)
Ejemplo n.º 10
0
    def test_order(self):
        article1, article2 = ArticleFactory.create_batch(2)

        # test ordering in ascendant order with title
        response = self.client.get(reverse("article_list") + f"?ordering=title")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            [article["id"] for article in response.data], [article1.id, article2.id]
        )

        # test ordering in descendant order with title
        response = self.client.get(reverse("article_list") + f"?ordering=-title")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            [article["id"] for article in response.data], [article2.id, article1.id]
        )

        # test ordering with created_at
        response = self.client.get(reverse("article_list") + f"?ordering=created_at")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            [article["id"] for article in response.data], [article1.id, article2.id]
        )
Ejemplo n.º 11
0
 def test_delete(self):
     article = ArticleFactory()
     url = reverse("article_detail", args=(article.id,))
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(Article.objects.count(), 0)
Ejemplo n.º 12
0
 def test_view_response_200(self):
     ArticleFactory.create_batch(5)
     response = self.client.get("/")
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 13
0
 def setUpTestData(cls):
     cls.articles = ArticleFactory.create_batch(1)
     cls.data_sources = DataSourceFactory.create_batch(1)
 def test_str(self):
     article = ArticleFactory(title="Test Title")
     self.assertEqual(str(article), "Test Title")
Ejemplo n.º 15
0
 def setUpTestData(cls):
     cls.articles = ArticleFactory.create_batch(10)
Ejemplo n.º 16
0
 def test_wrong_source_parameter_ignored(self):
     ArticleFactory.create_batch(2)
     url = f"{reverse('home')}?source=x"
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 17
0
 def setUpTestData(cls):
     ArticleFactory.create_batch(5, source=DataSourceFactory())
     ArticleFactory.create_batch(5, source=DataSourceFactory())
     ArticleFactory.create_batch(5, source=DataSourceFactory())