Skip to content

Commit

Permalink
Require an open_graph config section for the open graph extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jan 23, 2017
1 parent 906e60a commit d139c7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions handroll/extensions/og.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2017, Matt Layman

from handroll.exceptions import AbortError
from handroll.extensions.base import Extension
from handroll.i18n import _


class OpenGraphExtension(Extension):
Expand All @@ -10,6 +12,10 @@ class OpenGraphExtension(Extension):
handle_pre_composition = True

def on_pre_composition(self, director):
if not self._config.parser.has_section('open_graph'):
raise AbortError(_(
'An open_graph section is missing in the configuration file.'))

self._resolver = director.resolver

def on_frontmatter_loaded(self, source_file, frontmatter):
Expand Down
8 changes: 8 additions & 0 deletions handroll/tests/test_open_graph_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from handroll import signals
from handroll.exceptions import AbortError
from handroll.extensions.og import OpenGraphExtension
from handroll.tests import TestCase

Expand All @@ -16,6 +17,7 @@ def tearDown(self):
signals.pre_composition.receivers.clear()

def _make_one(self, director):
director.config.parser.add_section('open_graph')
extension = OpenGraphExtension(director.config)
extension.on_pre_composition(director)
return extension
Expand Down Expand Up @@ -78,3 +80,9 @@ def test_convert_summary_double_to_single_quotes(self):
self.assertIn(
'<meta property="og:description" content="The \'summary\'" />',
frontmatter['open_graph_metadata'])

def test_has_open_graph_section(self):
director = self.factory.make_director()
extension = OpenGraphExtension(director.config)
with self.assertRaises(AbortError):
extension.on_pre_composition(director)

0 comments on commit d139c7f

Please sign in to comment.