示例#1
0
class GeneralTests(unittest.TestCase):
    """Tests for reading and associating input files"""
    def setUp(self):
        self.fixture_dir = join(dirname(abspath(__file__)), 'fixtures',
                                'general')
        self.settings = dict(project_dir=self.fixture_dir,
                             input_dir=self.fixture_dir,
                             output_dir=self.fixture_dir,
                             date_format='%Y-%m-%d')
        self.site = Site(self.settings)
        self.site._parse(self.site._read_input())

    def test_filter_public(self):
        """
        Test that non-public articles are filtered out.
        """
        self.assertEqual(len(self.site.articles), 2)
        public_articles = filter(self.site._is_public, self.site.articles)
        self.assertEqual(len(public_articles), 1)

    def test_sort(self):
        """
        Test that articles are sorted by date.
        """
        self.site._sort_articles()
        self.assertEquals(self.site.articles[0].headers['date'],
                          datetime(2009, 2, 2, 0, 0))
        self.assertEquals(self.site.articles[1].headers['date'],
                          datetime(2009, 1, 1, 0, 0))
示例#2
0
class GeneralTests(unittest.TestCase):
    """Tests for reading and associating input files"""

    def setUp(self):
        self.fixture_dir = join(
            dirname(abspath(__file__)), 'fixtures', 'general')
        self.settings = dict(project_dir=self.fixture_dir,
                             input_dir=self.fixture_dir,
                             output_dir=self.fixture_dir,
                             date_format='%Y-%m-%d')
        self.site = Site(self.settings)
        self.site._parse(self.site._read_input())

    def test_filter_public(self):
        """
        Test that non-public articles are filtered out.
        """
        self.assertEqual(len(self.site.articles), 2)
        public_articles = filter(self.site._is_public, self.site.articles)
        self.assertEqual(len(public_articles), 1)

    def test_sort(self):
        """
        Test that articles are sorted by date.
        """
        self.site._sort_articles()
        self.assertEquals(self.site.articles[0].headers['date'],
                          datetime(2009, 2, 2, 0, 0))
        self.assertEquals(self.site.articles[1].headers['date'],
                          datetime(2009, 1, 1, 0, 0))
示例#3
0
 def test_empty_input_dir(self):
     """
     Given an empty or nonexisting input directory test that 
     an empty dict is returned.
     """
     settings = self.settings
     settings['input_dir'] = join(self.fixture_dir, 'DFGHJK')
     site = Site(self.settings)
     self.assertEqual({}, site._read_input())
示例#4
0
 def test_hidden_files_and_directories(self):
     """
     Given an input directory that has hidden files and directories.
     The returned data shouldn't include them.
     """
     settings = self.settings
     settings['input_dir'] = join(self.fixture_dir, 'hidden')
     site = Site(self.settings)
     self.assertEqual({}, site._read_input())
示例#5
0
    def test_associate_in_same_dir(self):
        """
        Given an input directory that has an article with media
        files in a subdirectory. The files should be associated.
        """
        settings = self.settings
        settings['input_dir'] = join(self.fixture_dir, 'same_dir')
        site = Site(self.settings)
        result = site._read_input()
        article_dir = join(settings['input_dir'], 'some-article')

        expected_articles = [join(article_dir, 'index.rst')]
        expected_media = [join(article_dir, 'media')]
        expected = (expected_articles, expected_media)

        self.assertEqual(result[article_dir], expected)
示例#6
0
    def test_not_associate_in_root_input_dir(self):
        """
        Given an input directory that has articles and media files
        in the top level directory. The files should not be associated.
        """
        settings = self.settings
        settings['input_dir'] = join(self.fixture_dir, 'no_root_assoc')
        site = Site(self.settings)
        result = site._read_input()

        expected_articles = [join(settings['input_dir'], 'article.rst')]
        expected_media = [join(settings['input_dir'], f)
                          for f in ('media1', 'media2')]
        expected = (expected_articles, expected_media)

        self.assertEqual(result[settings['input_dir']], expected)
示例#7
0
    def test_associate_with_root_if_no_parent_article(self):
        """
        Given an input directory that has media files in a subdirectory.
        The media files have no article in the parent directories and should
        be associated with the root input dir.
        """
        settings = self.settings
        settings['input_dir'] = join(self.fixture_dir, 'no_parent_article')
        site = Site(self.settings)
        result = site._read_input()

        expected_articles = []
        expected_media = [join(settings['input_dir'], 'media',
                               'images', 'file')]
        expected = (expected_articles, expected_media)

        self.assertEqual(result[settings['input_dir']], expected)
示例#8
0
    def test_associate_with_article_in_parent_dir(self):
        """
        Given an input directory that has an article in a subdirectory.
        The article has media files in subdirectory. The media files should
        be associated with the article in the parent dir.
        """
        settings = self.settings
        settings['input_dir'] = join(self.fixture_dir, 'parent_dir')
        site = Site(self.settings)
        result = site._read_input()
        article_dir = join(settings['input_dir'], 'article')

        expected_articles = [join(article_dir, 'index.rst')]
        expected_media = [join(article_dir, 'media', 'mediafile')]
        expected = (expected_articles, expected_media)

        self.assertEqual(result[article_dir], expected)
示例#9
0
class ParseTests(unittest.TestCase):

    def setUp(self):
        project_dir = join(dirname(abspath(__file__)),
                           'fixtures', 'parse')
        self.settings = dict(project_dir=project_dir,
                             input_dir=join(project_dir, 'input'),
                             output_dir=join(project_dir, 'output'),
                             date_format='%Y-%m-%d')
        self.site = Site(self.settings)
        input_data = self.site._read_input()
        self.site._parse(input_data)

    def test_parse_drafts(self):
        """
        Articles with the draft status shouldn't be processed.
        """
        for article in self.site.articles:
            self.assertNotEqual(article.headers['status'], 'draft')

    def test_parse_future_dated(self):
        """
        Articles with a date in the future shouldn't be processed.
        """
        for article in self.site.articles:
            self.assert_(article.headers['date'] <= datetime.today())

    def test_parse_media_association(self):
        """
        Test that media is correctly associated to articles.

        This means that media in the input directory should not be
        associated to any articles.
        Media that is in the same directory as an article or has a parent
        directory with an article in it, should be associated.
        """
        self.assertEqual(self.site.media,
                         [join(self.settings['input_dir'], 'mediafile')])
        for article in self.site.articles:
            if article.headers['url'] == 'foo/bar.html':
                expected_media = [join(self.settings['input_dir'],
                                  'foo', 'mediafile')]
            else:
                expected_media = []
            self.assertEqual(article.media, expected_media)
示例#10
0
class ParseTests(unittest.TestCase):
    def setUp(self):
        project_dir = join(dirname(abspath(__file__)), 'fixtures', 'parse')
        self.settings = dict(project_dir=project_dir,
                             input_dir=join(project_dir, 'input'),
                             output_dir=join(project_dir, 'output'),
                             date_format='%Y-%m-%d')
        self.site = Site(self.settings)
        input_data = self.site._read_input()
        self.site._parse(input_data)

    def test_parse_drafts(self):
        """
        Articles with the draft status shouldn't be processed.
        """
        for article in self.site.articles:
            self.assertNotEqual(article.headers['status'], 'draft')

    def test_parse_future_dated(self):
        """
        Articles with a date in the future shouldn't be processed.
        """
        for article in self.site.articles:
            self.assert_(article.headers['date'] <= datetime.today())

    def test_parse_media_association(self):
        """
        Test that media is correctly associated to articles.

        This means that media in the input directory should not be
        associated to any articles.
        Media that is in the same directory as an article or has a parent
        directory with an article in it, should be associated.
        """
        self.assertEqual(self.site.media,
                         [join(self.settings['input_dir'], 'mediafile')])
        for article in self.site.articles:
            if article.headers['url'] == 'foo/bar.html':
                expected_media = [
                    join(self.settings['input_dir'], 'foo', 'mediafile')
                ]
            else:
                expected_media = []
            self.assertEqual(article.media, expected_media)