Esempio n. 1
0
    def test_BlogObject_computed_props_raise(self):
        """Computed properties that depend on unimplemented ones raise

        computed properties in question:
            * output_path
            * url

        To prevent repetition, these properties should depend on a single
        path_part property/method that computes the path part of the url
        (http://siteurl.com/[path/part.html]) and the part of the file
        path below the output root (blog dir/output root/[path/part.html]).

        In turn this should depend on the class setting the _path_template_key
        class variable. Since only subclasses set this, BlogObject should
        raise NotImplementedError (see test_BlogObject_key_props_raise)
        when these properties are accessed.

        The BlogObject is given a self.settings attribute in order to
        suppress unrelated to exceptions. (Subclasses are required to
        have self.settings.)
        """
        bo = BlogObject()

        settings = majestic.load_settings(
            files=[TEST_BLOG_DIR.joinpath('settings.json')], local=False)
        bo._settings = settings  # Suppress exceptions about settings

        for prop in ['url', 'output_path']:
            with self.assertRaises(NotImplementedError):
                getattr(bo, prop)
Esempio n. 2
0
    def setUp(self):
        """Set dummy values for use in testing"""
        self.title = "Here’s a — test! — dummy title: (with lots o' symbols)"
        self.slug = 'test-slug-with-no-relation-to-title'
        self.meta = {'tags': ['a', 'b']}
        self.body = (
            # http://slipsum.com
            "You see? It's curious. Ted did figure it out - time"
            "travel. And when we get back, we gonna tell everyone. How"
            "it's possible, how it's done, what the dangers are."
            "\n\n"
            "The lysine contingency - it's intended to prevent the"
            "spread of the animals is case they ever got off the"
            "island. Dr. Wu inserted a gene that makes a single faulty"
            "enzyme in protein metabolism.")
        settings_path = TEST_BLOG_DIR.joinpath('settings.json')
        self.settings = majestic.load_settings(files=[settings_path],
                                               local=False)

        # Avoid index.html trimming mismatch in url tests
        self.settings['paths']['post path template'] = (
            '{content.date:%Y/%m}/{content.slug}.html')

        # Override timezone for testing purposes
        self.settings['dates']['timezone'] = 'Europe/London'
        self.tz = pytz.timezone('Europe/London')
        self.naive_date = datetime(2015, 8, 22, 9, 46)
        self.aware_date = self.tz.localize(self.naive_date)
        self.date_string = '2015-08-22 09:46'
Esempio n. 3
0
 def setUp(self):
     os.chdir(str(TEST_BLOG_DIR))
     settings_path = TEST_BLOG_DIR.joinpath('settings.json')
     self.settings = load_settings(files=[settings_path], local=False)
     loader = jinja2.FileSystemLoader([
         self.settings['paths']['templates root'],  # user
         str(MAJESTIC_DIR.joinpath('default_templates'))  # defaults
     ])
     self.jinja_env = jinja2.Environment(loader=loader)
Esempio n. 4
0
    def setUp(self):
        self.settings = majestic.load_settings(local=False)

        self.test_output_dir = TESTS_DIR.joinpath('output-root')
        self.settings['paths']['output root'] = str(self.test_output_dir)

        self.templates_root = TESTS_DIR.joinpath('test-templates')
        self.settings['paths']['templates root'] = str(self.templates_root)

        self.env = majestic.jinja_environment(
            user_templates=self.templates_root, settings=self.settings)
Esempio n. 5
0
 def setUp(self):
     settings_path = TEST_BLOG_DIR.joinpath('settings.json')
     self.settings = load_settings(files=[settings_path], local=False)
     starting_date = datetime(2015, 9, 22, 19)
     self.posts = [
         Post(title='post {}'.format(i),
              body='Here’s some text!',
              date=starting_date - timedelta(i),
              settings=self.settings) for i in range(40)
     ]
     random.shuffle(self.posts)  # Ensure not sorted
Esempio n. 6
0
 def setUp(self):
     os.chdir(str(TEST_BLOG_DIR))
     self.settings = load_settings()
     ext_dir_name = self.settings['paths']['extensions root']
     self.ext_dir = TEST_BLOG_DIR.joinpath(ext_dir_name)
     self.posts = [
         Post(title='test',
              body='test',
              date=datetime.now(),
              settings=self.settings)
     ]
     self.pages = [Page(title='test', body='test', settings=self.settings)]
Esempio n. 7
0
    def setUp(self):
        settings_path = TEST_BLOG_DIR.joinpath('settings.json')
        self.settings = load_settings(files=[settings_path], local=False)
        self.settings['index']['posts per page'] = 2
        path_template = 'page-{content.page_number}.html'
        self.settings['paths']['index pages path template'] = path_template
        self.settings['site']['url'] = 'http://example.com'

        dates = [datetime(2015, 1, 1) + timedelta(i) for i in range(5)]
        titles = ['A', 'B', 'C', 'D', 'E']
        bodies = ['A', 'B', 'C', 'D', 'E']
        self.posts = [
            Post(title=t, body=b, date=d, settings=self.settings)
            for t, b, d in zip(titles, bodies, dates)
        ]
Esempio n. 8
0
    def setUp(self):
        settings_path = TEST_BLOG_DIR.joinpath('settings.json')
        self.settings = majestic.load_settings(files=[settings_path],
                                               local=False)

        self.pages_path = TEST_BLOG_DIR.joinpath('pages')
        self.posts_path = TEST_BLOG_DIR.joinpath('posts')
        lib_post_names = '''\
1917-11-07 Годовщина Великой Октябрьской социалистической революции.md
1949-10-01 国庆节.mkd
1959-01-01 Triunfo de la Revolución.mdown
1975-04-30 Ngày Thống nhất.markdown
1979-07-19 Liberation Day.mkdown'''.splitlines()
        self.lib_posts = [
            self.posts_path.joinpath(post) for post in lib_post_names
        ]
Esempio n. 9
0
    def setUp(self):
        os.chdir(TEST_BLOG_DIR)
        settings_path = TEST_BLOG_DIR.joinpath('settings.json')
        self.settings = load_settings(files=[settings_path], local=False)
        self.output_dir = Path(self.settings['paths']['output root'])
        self.number_of_posts = 5
        self.settings['feeds']['number of posts'] = self.number_of_posts

        starting_date = datetime(2015, 9, 22, 19)
        self.posts = [
            Post(title='post {}'.format(i),
                 body='Here’s some text! And [a relative URL](/about)',
                 date=starting_date - timedelta(i),
                 settings=self.settings) for i in range(40)
        ]
        random.shuffle(self.posts)  # Ensure not sorted
Esempio n. 10
0
 def setUp(self):
     os.chdir(TEST_BLOG_DIR)
     settings_path = TEST_BLOG_DIR.joinpath('settings.json')
     self.settings = load_settings(files=[settings_path], local=False)
     self.output_dir = Path(self.settings['paths']['output root'])
     self.files = [
         Post(title='',
              slug='post',
              date=datetime(2015, 1, 1),
              body='',
              settings=self.settings),
         Page(title='', slug='page', body='', settings=self.settings),
         Index(posts=[], settings=self.settings, page_number=1),
     ]
     # Make dummy files and directories
     for f in self.files:
         f.output_path.parent.mkdir(parents=True, exist_ok=True)
         f.output_path.touch()
Esempio n. 11
0
 def setUp(self):
     """Set dummy values for use in testing"""
     self.title = "Here’s a — test! — dummy title: (with lots o' symbols)"
     self.naive_date = datetime(2015, 8, 22, 9, 46)
     self.slug = 'test-slug-with-no-relation-to-title'
     self.meta = {'tags': ['a', 'b']}
     self.body = (
         # http://slipsum.com
         "You see? It's curious. Ted did figure it out - time"
         "travel. And when we get back, we gonna tell everyone. How"
         "it's possible, how it's done, what the dangers are."
         "\n\n"
         "The lysine contingency - it's intended to prevent the"
         "spread of the animals is case they ever got off the"
         "island. Dr. Wu inserted a gene that makes a single faulty"
         "enzyme in protein metabolism.")
     settings_path = TEST_BLOG_DIR.joinpath('settings.json')
     self.settings = majestic.load_settings(files=[settings_path],
                                            local=False)
     # Dummy source / output files for modification date tests
     self.oldest_file = Path(TEST_BLOG_DIR, 'test_file_oldest')
     self.middle_file = Path(TEST_BLOG_DIR, 'test_file_middle')
     self.newest_file = Path(TEST_BLOG_DIR, 'test_file_newest')
Esempio n. 12
0
 def setUp(self):
     self.settings = majestic.load_settings(local=False)
     md._reset_cached_markdown()
Esempio n. 13
0
 def setUp(self):
     self.blogdir = TESTS_DIR.joinpath('test-full')
     self.outputdir = self.blogdir.joinpath('output')
     os.chdir(str(self.blogdir))
     self.settings = majestic.load_settings()
     self.expected = {
         '.': {
             'dirs': ['2012', '2013', '2014', '2015'],
             'posts': [],
             'pages': ['info.html'],
             'index': ['index.html',
                       'page-2.html',
                       'page-3.html'],
             'archives': ['archives.html'],
             'feeds': ['rss.xml', 'feed.json'],
             'sitemap': ['sitemap.xml']
             },
         './2012': {
             'dirs': ['07', '08', '12'],
             'posts': []
             },
         './2012/07': {
             'dirs': [],
             'posts': ['pelican-now-has-a-blog-of-its-own.html']
             },
         './2012/08': {
             'dirs': [],
             'posts': ['pelican-3-0-released.html']
             },
         './2012/12': {
             'dirs': [],
             'posts': ['pelican-3-1-released.html']
             },
         './2013': {
             'dirs': ['04', '07', '09'],
             'posts': []
             },
         './2013/04': {
             'dirs': [],
             'posts': ['pelican-3.2-released.html',
                       'pelicans-unified-codebase.html']
             },
         './2013/07': {
             'dirs': [],
             'posts': ['using-pelican-with-heroku.html']
             },
         './2013/09': {
             'dirs': [],
             'posts': ['pelican-3.3-released.html']
             },
         './2014': {
             'dirs': ['02', '07', '11'],
             'posts': []
             },
         './2014/02': {
             'dirs': [],
             'posts': ['i18n-subsites-plugin-released.html']
             },
         './2014/07': {
             'dirs': [],
             'posts': ['pelican-3.4-released.html']
             },
         './2014/11': {
             'dirs': [],
             'posts': ['pelican-3.5-released.html']
             },
         './2015': {
             'dirs': ['06'],
             'posts': []
             },
         './2015/06': {
             'dirs': [],
             'posts': ['pelican-3.6-released.html']
             },
         }
Esempio n. 14
0
 def setUp(self):
     os.chdir(str(TESTS_DIR.joinpath('test-copy')))
     self.settings = load_settings()
     self.output_dir = Path(self.settings['paths']['output root'])