Skip to content

Commit

Permalink
fix published flag status in frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
raghur committed Apr 30, 2018
1 parent 428d4da commit d9cac36
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions blogger/blogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def getPosts(self, postId=None, query=None, labels="", url=None,
request = service.posts().list(
blogId=self.blogId,
labels=labels,
view="AUTHOR",
maxResults=maxResults)
count = 0
while request:
Expand Down
11 changes: 8 additions & 3 deletions blogger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def getFilenameFromPostUrl(url, format):
return os.path.splitext(filename)[0] + "." + format


def getFrontMatter(item, docFormat, legacy=False):
def getFrontMatter(item, docFormat, legacy=False, bare=False):
frontmatter = dict()
if legacy:
frontmatter["Title"] = item["title"]
frontmatter["PostId"] = item["id"]
if "labels" in item:
frontmatter["Labels"] = item["labels"]
frontmatter["Published"] = item["published"]
frontmatter["Published"] = item["status"] == "LIVE"
else:
frontmatter = dict()
frontmatter["title"] = item["title"]
Expand All @@ -72,9 +72,14 @@ def getFrontMatter(item, docFormat, legacy=False):
frontmatter["tags"] = item["labels"]
frontmatter["aliases"] = [item["url"]]
frontmatter["publishdate"] = item["published"]
frontmatter["draft"] = False
frontmatter["draft"] = item["status"] == 'DRAFT'
frontmatter["date"] = item["published"]
frontmatter["lastmod"] = item["updated"]
if bare:
if docFormat == "asciidoc":
return toml.dumps(frontmatter)
else:
return yaml.dump(frontmatter)
if format == "asciidoc":
return u"""+++
%s
Expand Down
6 changes: 4 additions & 2 deletions tests/test_getpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_should_get_blog_by_labels(self):
self.posts.list.assert_called_with(
blogId="1234",
labels="abc",
maxResults=4)
maxResults=4,
view="AUTHOR")

def test_should_default_search_by_labels(self):
req = self.posts.list.return_value
Expand All @@ -46,7 +47,8 @@ def test_should_default_search_by_labels(self):
self.posts.list.assert_called_with(
blogId=self.blogger.blogId,
labels="",
maxResults=None)
maxResults=None,
view="AUTHOR")
req.execute.assert_called()

def test_should_use_search_when_query_is_provided(self):
Expand Down
45 changes: 39 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from oauth2client.client import AccessTokenRefreshError
from datetime import datetime
import toml
import yaml


@patch('blogger.main.EasyBlogger')
Expand All @@ -14,20 +15,52 @@ class MainTests(TestCase):
"id": "100",
"title": "title",
"url": "url",
"published": datetime.today(),
"updated": datetime.today()
"published": "2018-04-30T14:59:13",
"status": "LIVE",
"updated": "2018-04-30T14:59:13"
}
]
}

def test_should_generate_toml_frontmatter(self, pypandocMock, blogObjClass):
def test_should_generate_yaml_frontmatter_for_markdown(self,
pypandocMock,
blogObjClass):
item = MainTests.posts["items"][0]
fm = getFrontMatter(item)
fm = getFrontMatter(item, "markdown", legacy=False, bare=True)
fmObj = yaml.load(fm)
assert fmObj["title"] == 'title'
assert fmObj["id"] == '100'
assert fmObj["aliases"][0] == 'url'

def test_should_generate_toml_frontmatter_for_asciidoc(self,
pypandocMock,
blogObjClass):
item = MainTests.posts["items"][0]
fm = getFrontMatter(item, "asciidoc", legacy=False, bare=True)
fmObj = toml.loads(fm)
assert fmObj["title"] == 'title'
assert fmObj["id"] == '100'
assert fmObj["aliases"][0] == 'url'

def test_should_generate_legacy_toml_frontmatter(self,
pypandocMock,
blogObjClass):
item = MainTests.posts["items"][0]
fm = getFrontMatter(item, "asciidoc", legacy=True, bare=True)
print(fm)
fmObj = toml.loads(fm)
assert fmObj["Title"] == 'title'
assert fmObj["PostId"] == '100'

def test_should_generate_legacy_yaml_frontmatter(self,
pypandocMock,
blogObjClass):
item = MainTests.posts["items"][0]
fm = getFrontMatter(item, "markdown", legacy=True, bare=True)
fmObj = yaml.load(fm)
assert fmObj["Title"] == 'title'
assert fmObj["PostId"] == '100'

def test_should_process_files_for_update(self, pypandocMock, blogObjClass):
mo = mock_open(read_data="""
+++
Expand All @@ -45,7 +78,7 @@ def processItemSideEffect(*positionalArgs, **kwargs):
assert args.labels == ["l", "a", "c"]
assert args.command == "update"
assert args.format == "asciidoc"
assert args.publish == False
assert not args.publish
return DEFAULT

blogObj = blogObjClass.return_value
Expand Down Expand Up @@ -73,7 +106,7 @@ def processItemSideEffect(*positionalArgs, **kwargs):
assert args.labels == ["l", "a", "c"]
assert args.command == "post"
assert args.format == "asciidoc"
assert args.publish == False
assert not args.publish
return DEFAULT

blogObj = blogObjClass.return_value
Expand Down

0 comments on commit d9cac36

Please sign in to comment.