Example #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)
Example #2
0
    def test_BlogObject_set_output_path(self):
        """Can override the output_path property by setting it

        This tests the output_path setter and ensures that BlogObject
        is actually setting and checking the underlying variable and
        not just raising NotImplementError regardless.
        """
        bo = BlogObject()
        path = '/some/path/on/the/system'
        bo.output_path = path
        self.assertEqual(bo.output_path, path)
Example #3
0
    def test_BlogObject_set_url(self):
        """Can override the url property by setting it

        This tests the url setter and ensures that BlogObject is
        actually setting and checking the underlying variable and
        not just raising NotImplementError regardless.
        """
        bo = BlogObject()
        url = 'http://example.com/my-test-url.html'
        bo.url = url
        self.assertEqual(bo.url, url)
Example #4
0
    def test_BlogObject_url_trims_index(self):
        """URL property trims index.html from path_part

        This is necessary to have clean URLs internally if the path
        template writes the file as index.html in a subdirectory.
        """
        bo = BlogObject()
        base_url = 'http://example.com'
        self.settings['site']['url'] = base_url
        bo._settings = self.settings

        path_part = 'some_dir/index.html'
        bo.path_part = base_url + '/' + path_part
        self.assertEqual(bo.url, base_url + '/some_dir/')
Example #5
0
    def test_BlogObject_set_path_part(self):
        """Can override the path_part property by setting it

        Directly setting path_part makes it easier to directly
        override both the output_path and url properties, as
        they both retrieve the path part from that attribute.

        As path_part stores the constructed string at _path_part,
        users could override that but that should be an implementation
        detail.
        """
        bo = BlogObject()
        path_part = 'index.html'
        bo.path_part = path_part
        self.assertEqual(bo.path_part, path_part)
Example #6
0
    def test_BlogObject_no_arguments(self):
        """BlogObject should not require arguments to init

        The intention is that BlogObject only contains default method
        implementations to be inherited and has no content of its own.
        """
        self.assertIsInstance(BlogObject(), BlogObject)
Example #7
0
    def test_BlogObject_properties_exist(self):
        """BlogObject defines expected properties and methods

        Expected:
            * path_part
            * output_path
            * url
            * render_to_disk
        """
        attrs = ['path_part', 'output_path', 'url', 'render_to_disk']
        bo = BlogObject()
        for a in attrs:
            self.assertIn(a, dir(bo))
Example #8
0
    def test_BlogObject_key_props_raise(self):
        """BlogObject key properties should raise NotImplementedError

        key properties in question:
            * _path_template_key
            * _template_file_key

        The intention being that subclasses will define class variables
        that contain the strings needed to index into the settings.

        For example:
            class A(BlogObject):
                _path_template_key = 'a path template'
                _template_file_key = 'a template filename'
        """
        bo = BlogObject()
        for attr in ['_path_template_key', '_template_file_key']:
            with self.assertRaises(NotImplementedError):
                getattr(bo, attr)