From 8513659f6bc28e3a9ea5e1209913d6a46d1808ca Mon Sep 17 00:00:00 2001 From: duker33 Date: Wed, 13 Feb 2019 13:50:09 +0300 Subject: [PATCH] #240 Add test for attribute access --- pages/display.py | 8 +++++--- tests/pages/test_display.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/pages/test_display.py diff --git a/pages/display.py b/pages/display.py index c06c1fd..378894d 100644 --- a/pages/display.py +++ b/pages/display.py @@ -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: diff --git a/tests/pages/test_display.py b/tests/pages/test_display.py new file mode 100644 index 0000000..9d338aa --- /dev/null +++ b/tests/pages/test_display.py @@ -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