예제 #1
0
파일: blank.py 프로젝트: purrfectt/drupan
 def run(self):
     """run the plugin"""
     for name in self.generate:
         new = Entity(self.config)
         new.meta["title"] = name
         new.meta["layout"] = self.generate[name]
         self.site.entities.append(new)
예제 #2
0
파일: blank.py 프로젝트: cotsog/drupan
 def run(self):
     """run the plugin"""
     for name in self.generate:
         new = Entity(self.config)
         new.meta["title"] = name
         new.meta["layout"] = self.generate[name]
         self.site.entities.append(new)
예제 #3
0
    def test_generate_tags(self):
        """should create two tags"""
        entity = Entity(self.config)
        entity.meta["tags"] = ["foo", "bar"]

        self.plugin.generate_tags(entity)

        self.assertTrue("foo" in self.plugin.tags)
        self.assertTrue("bar" in self.plugin.tags)
예제 #4
0
 def as_list(cls, config):
     entities = list()
     for ent in cls.objects.exclude(published_at__isnull=True):
         meta = {
             "title": ent.title,
             "layout": "post",
             "date": ent.published_at
         }
         entity = DrupanEntity(config)
         entity.meta = meta
         entity.raw = ent.content.strip()
         entities.append(entity)
     return entities
예제 #5
0
    def setUp(self):
        self.e1 = Entity({})
        self.e1.meta["title"] = "foo"
        self.e1.meta["layout"] = "post"

        self.e2 = Entity({})
        self.e2.meta["title"] = "bar"
        self.e2.meta["layout"] = "post"
        self.e2.tag = "asdf"

        self.site = Site()
        self.site.entities.append(self.e1)
        self.site.entities.append(self.e2)
예제 #6
0
def setup_content(engine):
    for stored in Entity.objects.filter(draft=False):
        entity = DrupanEntity(engine.config)

        meta = stored.meta_fields
        meta["layout"] = stored.layout
        meta["date"] = stored.created
        meta["title"] = stored.name

        entity.meta = meta
        entity.raw = stored.content

        engine.site.entities.append(entity)
예제 #7
0
    def parse_file(self, raw):
        """
        create an entity from a read file

        Arguments:
            raw: input
        """
        (header, separator, content) = raw.partition("---")
        meta = yaml.load(header)

        entity = Entity(self.config)
        entity.meta = meta
        entity.raw = content.strip()

        self.site.entities.append(entity)
예제 #8
0
    def parse_file(self, raw):
        """
        create an entity from a read file

        Arguments:
            raw: input
        """
        (header, seperator, content) = raw.partition("---")
        meta = yaml.load(header)

        entity = Entity(self.config)
        entity.meta = meta
        entity.raw = content.strip()

        self.site.entities.append(entity)
예제 #9
0
    def setUp(self):
        self.config = Config()
        self.config.options = {"markdown": {"extras": "."}}

        self.site = Site()

        self.entity = Entity(self.config)
        self.entity.raw = "foobar"
예제 #10
0
파일: tags.py 프로젝트: purrfectt/drupan
    def create_entity(self, tag):
        """
        Create a new entity for a tag if it does not exist

        Arguments:
            tag: tag name
        """
        lower = tag.lower()

        if lower in self.tags:
            return

        entity = Entity(self.config)
        entity.meta["title"] = tag
        entity.meta["layout"] = "tag"
        entity.entities = list()

        self.tags[lower] = entity
예제 #11
0
    def setUp(self):
        config = Config()
        config.options = {
            "jinja": {
                "template": "foo",
            }
        }

        self.entity = Entity(config)

        site = Site()
        site.entities.append(self.entity)

        self.render = Render(site, config)
예제 #12
0
    def test_generate_tags_two_entities(self):
        """should create one tag with two entities"""
        entity1 = Entity(self.config)
        entity1.meta["tags"] = ["foo"]
        entity2 = Entity(self.config)
        entity2.meta["tags"] = ["foo"]

        self.plugin.generate_tags(entity1)
        self.plugin.generate_tags(entity2)

        self.assertEqual(len(self.plugin.tags["foo"].entities), 2)
예제 #13
0
    def test_run(self):
        """should create two entities and add it to the sites entities"""
        entity1 = Entity(self.config)
        entity1.meta["tags"] = ["foo"]
        entity2 = Entity(self.config)
        entity2.meta["tags"] = ["bar"]

        self.site.entities.append(entity1)
        self.site.entities.append(entity2)

        plugin = Plugin(self.site, self.config)
        plugin.run()

        self.assertEqual(len(self.site.entities), 4)
예제 #14
0
 def setUp(self):
     self.config = Config()
     self.entity = Entity(self.config)
예제 #15
0
class TestEntity(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.entity = Entity(self.config)

    def test_slug_generation(self):
        """should return a valid slug"""
        expected = "foo-bar"
        title = "-FoO--BaR---"
        self.entity.meta["title"] = title

        self.assertEqual(self.entity.slug, expected)

    def test_slug_storage(self):
        """should return foo, not bar"""
        title = "-FoO--BaR---"
        self.entity.meta["title"] = title
        self.entity._slug = "baz"

        self.assertEqual(self.entity.slug, "baz")

    def test_slug_no_title(self):
        """should return None"""
        self.assertEqual(self.entity.slug, "")

    def test_created_generation(self):
        """should return a datetime instance"""
        self.entity.meta["date"] = datetime.datetime(2014, 1, 30, 14, 56)
        dt = self.entity.created

        self.assertEqual(type(dt), datetime.datetime)
        self.assertEqual(dt.year, 2014)
        self.assertEqual(dt.month, 1)
        self.assertEqual(dt.day, 30)
        self.assertEqual(dt.hour, 14)
        self.assertEqual(dt.minute, 56)

    def test_created_no_date(self):
        """should use datetime.now() as created date"""
        self.assertEqual(type(self.entity.created), datetime.datetime)

    def test_created_storage(self):
        """should return foo"""
        self.entity.meta["date"] = datetime.datetime(2014, 1, 30, 14, 56)
        self.entity._created = "foo"
        dt = self.entity.created

        self.assertEqual(dt, "foo")

    def test_updated_generation(self):
        """should return a datetime instance"""
        self.entity.meta["updated"] = datetime.datetime(2014, 1, 30, 14, 56)
        dt = self.entity.updated

        self.assertEqual(type(dt), datetime.datetime)
        self.assertEqual(dt.year, 2014)
        self.assertEqual(dt.month, 1)
        self.assertEqual(dt.day, 30)
        self.assertEqual(dt.hour, 14)
        self.assertEqual(dt.minute, 56)

    def test_updated_storage(self):
        """should return foo"""
        self.entity.meta["updated"] = datetime.datetime(2014, 1, 30, 14, 56)
        self.entity._updated = "foo"
        dt = self.entity.updated

        self.assertEqual(dt, "foo")

    def test_updated_not_existing(self):
        """should return a datetime instance"""
        self.entity.meta["date"] = datetime.datetime(2014, 1, 30, 14, 56)
        dt = self.entity.updated

        self.assertEqual(type(dt), datetime.datetime)
        self.assertEqual(dt.year, 2014)
        self.assertEqual(dt.month, 1)
        self.assertEqual(dt.day, 30)
        self.assertEqual(dt.hour, 14)
        self.assertEqual(dt.minute, 56)
        self.assertEqual(dt, self.entity._updated)

    def test_get_url_value(self):
        """should return 'foo', 'bar' and 2014"""
        self.entity.meta["date"] = datetime.datetime(2014, 1, 30, 14, 56)
        self.entity.meta["foo"] = "foo"
        self.entity.bar = "bar"

        self.assertEqual(self.entity.get_url_value("%foo"), "foo")
        self.assertEqual(self.entity.get_url_value("%bar"), "bar")
        self.assertEqual(self.entity.get_url_value("%year"), "2014")

    def test_url_meta(self):
        """should return /foo/bar/"""
        self.entity.meta["foo"] = "foo"
        self.entity.bar = "bar"
        self.entity.meta["url"] = "%foo/%bar"

        self.assertEqual(self.entity.url, "/foo/bar/")

    def test_url_config_layout(self):
        """should return /foo/2014/1/"""
        self.entity.meta["foo"] = "foo"
        self.entity.meta["date"] = datetime.datetime(2014, 1, 30, 14, 56)
        self.entity.meta["layout"] = "post"
        self.config.url_scheme["post"] = "/%foo/%year/%month/"

        self.assertEqual(self.entity.url, "/foo/2014/1/")

    def test_path(self):
        """should return foo/bar"""
        self.entity.meta["foo"] = "foo"
        self.entity.meta["bar"] = "bar"
        self.entity.meta["layout"] = "post"

        self.config.url_scheme["post"] = "/%foo/%bar/"
        self.assertEqual(self.entity.path, "foo/bar")

        self.entity._url = None
        self.config.url_scheme["post"] = "/%foo/%bar"
        self.assertEqual(self.entity.path, "foo/bar")

        self.entity._url = None
        self.config.url_scheme["post"] = "%foo/%bar/"
        self.assertEqual(self.entity.path, "foo/bar")

    def test_path_slash(self):
        """should return ''"""
        self.entity.meta["layout"] = "post"
        self.config.url_scheme["post"] = "/"
        self.assertEqual(self.entity.path, "")

    def test_url_no_layout(self):
        """should return None"""
        self.assertEqual(self.entity.url, None)

    def test_path_no_url(self):
        """should return None"""
        self.assertEqual(self.entity.path, None)

    def test_date(self):
        """should return a valid date"""
        self.assertEqual(type(self.entity.date), datetime.datetime)

        self.entity.meta["date"] = datetime.date.today()
        self.assertEqual(type(self.entity.date), datetime.date)

    def test_meta_properties(self):
        """should return title and tags"""
        self.entity.meta["title"] = "foo"
        self.entity.meta["tags"] = ["foo", "bar"]

        self.assertEqual(self.entity.title, "foo")
        self.assertEqual(type(self.entity.tags), list)

    def test_file_path(self):
        """should return path with index.html appended"""
        self.entity._url = "/foo/"
        self.assertEqual(self.entity.file_path, "foo/index.html")
예제 #16
0
 def test_generate_tags_no_tags(self):
     """should not raise a KeyError"""
     entity = Entity(self.config)
     self.plugin.generate_tags(entity)