Skip to content

Commit

Permalink
#240 Add test for attribute access
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Feb 14, 2019
1 parent 8a9da46 commit 8513659
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pages/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class Fields:
# Fields stored in DB. See class `pages.models.PageTemplate`
STORED = ['name', 'h1', 'keywords', 'description', 'title', 'seo_text']

def __init__(self, page_view: 'Page'):
self.page_view = page_view
def __init__(self, page_display: 'Page'):
self.page_display = page_display

def __getattr__(self, item):
if item in self.STORED:
return self.page_view.render(item)
return self.page_display.render(item)
else:
return super().__getattribute__(item)


class Page:
Expand Down
13 changes: 13 additions & 0 deletions tests/pages/test_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.test import TestCase

from pages import display


class TestFields(TestCase):
fixtures = []

def test_attribute_error(self):
# noinspection PyTypeChecker
page = display.Page(None, {})
with self.assertRaises(AttributeError):
_ = page.fields.bad_attr

0 comments on commit 8513659

Please sign in to comment.