Ejemplo n.º 1
0
 def test_make_article_has_no_content_when_file_is_empty(self):
     save_file('/tmp/stuff/article_file.txt', '')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertEquals('stuff/article_file', article.info.fullname)
     self.assertEquals('stuff', article.info.category)
     self.assertEquals('article_file', article.info.slug)
     self.assertEquals('txt', article.info.extension)
     self.assertEquals('', article.content)
Ejemplo n.º 2
0
 def test_make_article_fills_basic_info(self):
     save_file('/tmp/stuff/article_file.txt', 'blah')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertEquals('stuff/article_file', article.info.fullname)
     self.assertEquals('stuff', article.info.category)
     self.assertEquals('article_file', article.info.slug)
     self.assertEquals('txt', article.info.extension)
     self.assertEquals('blah', article.content)
Ejemplo n.º 3
0
 def fetch_article_by_repofile(self, repofile):
     """Fetch single article info by repofile (path starting from root of
     repository). Returns None if no article exists with that name.
     """
     filename = os.path.join(self.root_dir, repofile)
     fullname = self._file2name(filename)
     if not self.exists(fullname):
         raise ArticleNotFoundError(fullname)
     article = make_article(fullname, filename, self.meta_types)
     return call_plugins_arg('on_article_fetch', article)
Ejemplo n.º 4
0
    def test_make_article_loads_date_types_as_int(self):
        article_text = """---
date: 2015-05-16 01:52:57.906737
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt',
                               meta_types={'date': 'iso8601'})
        self.assertTrue(isinstance(article.info.date, int))
Ejemplo n.º 5
0
    def test_make_article_loads_list_typed_metadata(self):
        article_text = """---
tags: tag1,tag2,tag3
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt',
                               meta_types={'tags': 'list'})
        self.assertTrue(article.info.tags, ['tag1', 'tag2', 'tag3'])
Ejemplo n.º 6
0
    def test_make_article_loads_simple_metadata(self):
        article_text = """---
title: this is a title
count: 76
foo: [5, 'dd']
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt')
        self.assertTrue(article.info.title, 'this is a title')
        self.assertTrue(article.info.count, 76)
        self.assertTrue(article.info.foo, [5, 'dd'])
Ejemplo n.º 7
0
 def test_make_article_loads_file_metadata(self):
     save_file('/tmp/stuff/article_file.txt', 'blah')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertTrue(isinstance(article.info.create_time, float))
     self.assertTrue(isinstance(article.info.modified_time, float))
Ejemplo n.º 8
0
 def _fetch_by_fullname(self, fullname):
     filename = self._fullname2file(fullname)
     if filename is None:
         raise ArticleNotFoundError(fullname)
     return make_article(fullname, filename, self.meta_types)