Ejemplo n.º 1
0
class ArticleTests(TestCase):
    def setUp(self):
        self.test_author = AuthorFactory(name='xyz', slug="xyz")
        self.test_article_author = ArticleAuthors(author=self.test_author, sort_order=0)
        self.article = ArticleFactory(title="english_article", authors=(self.test_article_author,), language='en')

    def test_article_to_string_should_be_equal_to_the_title(self):
        self.assertEqual(self.article.title, str(self.article))
        self.assertEqual(str(self.article), 'english_article')

    def test_article_get_absolute_url_returns_the_path_to_the_article(self):
        self.assertRegexpMatches(self.article.get_absolute_url(), '/articles/english_article/?$')

    def test_get_context_of_article_should_have_english_article(self):
        request = MagicMock()
        request.get_host.return_value = 'localhost'
        response = self.article.get_context(request)
        assert response['article'].title == 'english_article'

    def test_get_context_return_site_for_what_is_set_by_request(self):
        request = MagicMock()
        request.get_host.return_value = 'localhost'
        response = self.article.get_context(request)
        self.assertEqual(str(response['site']), 'localhost [default]')

    def test_multiple_authors_can_be_added_to_a_article(self):
        author= AuthorFactory(name='Test')
        article_author = ArticleAuthors(author=author, sort_order=1)
        article = ArticleFactory(title="Multiple Author Article", authors=(self.test_article_author,article_author,))
        self.assertEqual(len(article.authors.all()),2)
        self.assertEqual(article.authors.all()[1].author.name,'Test')
Ejemplo n.º 2
0
 def setUp(self):
     self.client = Client()
     self.category = CategoryFactory()
     self.test_author1 = AuthorFactory(name='xyz', slug="xyz")
     self.test_article_author1 = ArticleAuthors(author=self.test_author1,
                                                sort_order=0)
     self.test_article_author1b = ArticleAuthors(author=self.test_author1,
                                                 sort_order=0)
     self.test_author2 = AuthorFactory(name='abc', slug="abc")
     self.test_article_author2 = ArticleAuthors(author=self.test_author2,
                                                sort_order=1)
     self.test_article_author2b = ArticleAuthors(author=self.test_author2,
                                                 sort_order=1)
     self.english_article = ArticleFactory(
         title="english_article",
         authors=(self.test_article_author1, ),
         language='en',
         first_published_at='2011-10-24 12:43')
     self.hindi_article = ArticleFactory(
         title="hindi_article",
         authors=(self.test_article_author1b, self.test_article_author2),
         language='hi',
         first_published_at='2011-10-25 12:43')
     self.dummy_article = ArticleFactory(
         title="dummy_article",
         authors=(self.test_article_author2b, ),
         language='en',
         first_published_at='2011-10-23 12:43')
Ejemplo n.º 3
0
 def setUp(self):
     self.client = Client()
     self.author = AuthorFactory(name='test', slug="test")
     self.article_author = ArticleAuthors(author=self.author, sort_order=0)
     self.article = ArticleFactory(title="test article",
                                   authors=(self.article_author, ),
                                   language='en')
     self.article = ArticleFactory(title="test modular article",
                                   show_modular_content=True)
Ejemplo n.º 4
0
 def setUp(self):
     client = Client()
     self.test_author = AuthorFactory(name='xyz', slug="xyz")
     self.english_article = ArticleFactory(
         title="english_article",
         first_published_at='2017-4-24 12:43',
         language='en')
     self.hindi_article = ArticleFactory(
         title="hindi_article",
         first_published_at='2017-4-25 12:43',
         language='hi')
Ejemplo n.º 5
0
 def setUp(self):
     self.client = Client()
     self.test_author = AuthorFactory(name='xyz', slug="xyz")
     self.test_article_author = ArticleAuthors(author=self.test_author,
                                               sort_order=0)
     self.article = ArticleFactory(title="english_article",
                                   authors=(self.test_article_author, ),
                                   language='en')
Ejemplo n.º 6
0
 def test_articles_are_only_12_in_a_page_for_the_author_xyz(self):
     # Creating 14 articles
     for name in range(1, 15):
         ArticleFactory(title="article" + str(name), authors=(self.test_author1,))
     response_for_page_one = self.client.get('/authors/xyz/?lang=all')
     response_for_page_two = self.client.get('/authors/xyz/?page=2&lang=all')
     self.assertEqual(len(response_for_page_one.context_data['articles']), 12)
     self.assertEqual(len(response_for_page_two.context_data['articles']), 4)
Ejemplo n.º 7
0
 def test_articles_are_only_12_in_a_page(self):
     # Creating 14 articles
     for name in range(1, 15):
         ArticleFactory(title="article" + str(name), first_published_at='2017-4-25 12:43')
     response_for_page_one = self.client.get('/archive/2017/4/?lang=all')
     response_for_page_two = self.client.get('/archive/2017/4/?page=2&lang=all')
     self.assertEqual(len(response_for_page_one.context_data['articles']), 12)
     self.assertEqual(len(response_for_page_two.context_data['articles']), 4)
Ejemplo n.º 8
0
 def test_multiple_authors_can_be_added_to_a_article(self):
     author = AuthorFactory(name='Test')
     article = ArticleFactory(title="Multiple Author Article",
                              authors=(
                                  self.test_author,
                                  author,
                              ))
     self.assertEqual(len(article.authors.all()), 2)
     self.assertEqual(article.authors.all()[1].name, 'Test')
Ejemplo n.º 9
0
    def create_article(self,
                       title,
                       author,
                       category,
                       location,
                       image,
                       show_modular_content=False,
                       modular_content=None):
        if modular_content is not None:
            return ArticleFactory.create(
                title=title,
                authors=(author, ),
                categories=(category, ),
                locations=(location, ),
                featured_image=image,
                show_modular_content=show_modular_content,
                modular_content=modular_content)

        return ArticleFactory.create(title=title,
                                     authors=(author, ),
                                     categories=(category, ),
                                     locations=(location, ),
                                     featured_image=image,
                                     show_modular_content=show_modular_content)
Ejemplo n.º 10
0
 def test_article_cannot_be_stored_without_language(self):
     with self.assertRaisesRegexp(ValidationError,
                                  "This field cannot be blank"):
         ArticleFactory(title='Test', language='')
Ejemplo n.º 11
0
 def test_article_can_be_stored_without_content(self):
     article = ArticleFactory(title='Test', content='')
     self.assertEqual(article.title, 'Test')
Ejemplo n.º 12
0
 def test_no_article_can_be_stored_without_a_title(self):
     with self.assertRaisesRegexp(
             ValidationError, "This field cannot be blank"
     ):  # Slug and title fields cannot be null.
         ArticleFactory(title="")
Ejemplo n.º 13
0
 def setUp(self):
     self.client = Client()
     self.author = AuthorFactory(name='test', slug="test")
     self.article = ArticleFactory(title="test article", authors=(self.author,), language='en')
Ejemplo n.º 14
0
 def create_article(self, title, author, category, location, image):
     return ArticleFactory.create(title=title,
                                  authors=(author, ),
                                  categories=(category, ),
                                  locations=(location, ),
                                  featured_image=image)
Ejemplo n.º 15
0
Archivo: tests.py Proyecto: malkum/pari
 def setUp(self):
     self.category = CategoryFactory()
     self.english_article = ArticleFactory(title="english_article", categories=(self.category,), language='en', first_published_at='2017-07-06 00:00')
     self.hindi_article = ArticleFactory(title="hindi_article", categories=(self.category,), language='hi', first_published_at='2017-07-08 00:01')
     self.client = Client()
Ejemplo n.º 16
0
 def setUp(self):
     self.test_author = AuthorFactory(name='xyz', slug="xyz")
     self.article = ArticleFactory(title="english_article",
                                   authors=(self.test_author, ),
                                   language='en')