コード例 #1
0
class ArticleListPresenterTest(TestCase):

    """
    Presenter interface to a list of articles.

    """

    def setUp(self):
        self.articles = article.loader.find(join(dirname(__file__), "fixtures", "articles"))

        self.presenter = ArticleListPresenter(self.articles)

    def test_latest_article(self):
        """
        Can get the latest article.
        """
        latest = self.presenter.latest()

        self.assertEqual(date(2001, 1, 1), latest.created_date)

    def test_by_slug(self):
        """
        Can get an article by slug.
        """
        article = self.presenter.by_slug("old")

        self.assertEqual("old", article.slug)

    def test_by_slug_not_found(self):
        """
        Getting a slug for an article that is not found.
        """
        with self.assertRaises(NotFound):
            self.presenter.by_slug("notaslug")

    def test_latest_not_found(self):
        """
        If the list of articles is empty.
        """
        self.presenter.articles = []

        with self.assertRaises(NotFound):
            self.presenter.latest()

    def test_to_list(self):
        """
        Can get a list of articles.
        """
        self.assertEqual(3, len(self.presenter.to_list()))
コード例 #2
0
    def setUp(self):
        self.articles = article.loader.find(join(dirname(__file__), "fixtures", "articles"))

        self.presenter = ArticleListPresenter(self.articles)