Skip to content

Commit 1712d9b

Browse files
committed
Issue #25: Method removed, test coverage improved.
1 parent 9f419cd commit 1712d9b

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

domain_models/views.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,18 @@ def check_properties(mcs, attributes):
8989
:type attributes: dict
9090
"""
9191
include, exclude = mcs.get_prepared_include_exclude(attributes)
92-
93-
if include:
94-
intersections = mcs.get_intersections(attributes, include)
95-
attr = '__include__'
96-
elif exclude:
97-
intersections = mcs.get_intersections(attributes, exclude)
98-
attr = '__exclude__'
99-
else:
100-
return None
101-
92+
properties = mcs.get_properties(attributes)
93+
intersections = list(
94+
set(properties).intersection(include if include else exclude))
10295
if not intersections:
10396
return None
10497

98+
attr_name = '__include__' if include else '__exclude__'
99+
105100
raise AttributeError(
106101
"It is not allowed to mention already defined properties: "
107-
"{0} in {1} attributes.".format(", ".join(intersections), attr))
108-
109-
@classmethod
110-
def get_intersections(mcs, attributes, attr):
111-
"""Return intersection with defined properties if exists.
112-
113-
:type attributes: dict
114-
:type attr: list
115-
:rtype: list
116-
"""
117-
if not attr:
118-
return []
119-
properties = mcs.get_properties(attributes)
120-
return list(set(properties).intersection(attr))
102+
"{0} in {1} attributes.".format(", ".join(intersections),
103+
attr_name))
121104

122105

123106
@six.add_metaclass(ContextViewMetaClass)

tests/test_context_view.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ class WrongContext(views.ContextView):
156156
__model_cls__ = Profile
157157
__exclude__ = [Profile.name]
158158

159+
with self.assertRaises(AttributeError):
160+
class WrongContext(views.ContextView):
161+
__model_cls__ = Profile
162+
__include__ = (Profile.id, Profile.name)
163+
164+
@property
165+
def name(self):
166+
return "Any name"
167+
159168
with self.assertRaises(AttributeError):
160169
class WrongContext(views.ContextView):
161170
__model_cls__ = Profile

0 commit comments

Comments
 (0)