Skip to content
This repository has been archived by the owner on Feb 27, 2020. It is now read-only.

Commit

Permalink
Replaced MyModel._meta.specialization with
Browse files Browse the repository at this point in the history
MyModel.model_specialization in client classes. 
Added a test for the new feature.
  • Loading branch information
franciscoruiz committed Mar 29, 2011
1 parent 8c597cf commit 4d56077
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
5 changes: 2 additions & 3 deletions djeneralize/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ def get_as_specialization(self, final_specialization=True):
if not final_specialization:
# We need to find the path which is only one-step down from the
# current level of specialization.
path = find_next_path_down(
self._meta.specialization, path, PATH_SEPERATOR
)
path = find_next_path_down(self.__class__.model_specialization,
path, PATH_SEPERATOR)

return self._meta.specializations[path].objects.get(pk=self.pk)

Expand Down
4 changes: 2 additions & 2 deletions djeneralize/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def iterator(self):
# Coerce the specialization to only be the direct child of the
# general model (self.model):
specialization = find_next_path_down(
self.model._meta.specialization, specialization,
self.model.model_specialization, specialization,
PATH_SEPERATOR
)

Expand Down Expand Up @@ -127,7 +127,7 @@ def get(self, *args, **kwargs):
# Coerce the specialization to only be the direct child of the
# general model (self.model):
specialization = find_next_path_down(
self.model._meta.specialization, specialization, PATH_SEPERATOR
self.model.model_specialization, specialization, PATH_SEPERATOR
)

try:
Expand Down
42 changes: 29 additions & 13 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def test_specializations_general(self):
ok_(FountainPen in specializations_classes)
ok_(BallPointPen in specializations_classes)

ok_(Pen._meta.specialization in specializations_keys)
ok_(Pencil._meta.specialization in specializations_keys)
ok_(FountainPen._meta.specialization in specializations_keys)
ok_(BallPointPen._meta.specialization in specializations_keys)
ok_(Pen.model_specialization in specializations_keys)
ok_(Pencil.model_specialization in specializations_keys)
ok_(FountainPen.model_specialization in specializations_keys)
ok_(BallPointPen.model_specialization in specializations_keys)


def test_sub_specialization(self):
Expand All @@ -73,10 +73,10 @@ def test_sub_specialization(self):
ok_(FountainPen in specializations_classes)
ok_(BallPointPen in specializations_classes)

assert_false(Pen._meta.specialization in specializations_keys)
assert_false(Pencil._meta.specialization in specializations_keys)
ok_(FountainPen._meta.specialization in specializations_keys)
ok_(BallPointPen._meta.specialization in specializations_keys)
assert_false(Pen.model_specialization in specializations_keys)
assert_false(Pencil.model_specialization in specializations_keys)
ok_(FountainPen.model_specialization in specializations_keys)
ok_(BallPointPen.model_specialization in specializations_keys)

eq_(BallPointPen._meta.specializations, {})

Expand All @@ -87,11 +87,11 @@ def test_path_specialization(self):
"""

eq_(WritingImplement._meta.specialization, '/')
eq_(Pen._meta.specialization, '/pen/')
eq_(Pencil._meta.specialization, '/pencil/')
eq_(FountainPen._meta.specialization, '/pen/fountain_pen/')
eq_(BallPointPen._meta.specialization, '/pen/ballpoint_pen/')
eq_(WritingImplement.model_specialization, '/')
eq_(Pen.model_specialization, '/pen/')
eq_(Pencil.model_specialization, '/pencil/')
eq_(FountainPen.model_specialization, '/pen/fountain_pen/')
eq_(BallPointPen.model_specialization, '/pen/ballpoint_pen/')

@raises(TypeError)
def test_missing_meta(self):
Expand Down Expand Up @@ -159,6 +159,22 @@ def test_non_root(self):
eq_(find_next_path_down(non_root, full_path, '/'), '/home/barry/')


class TestDefaultSpecialization(FixtureTestCase):

This comment has been minimized.

Copy link
@gnarea

gnarea Mar 29, 2011

Contributor

I think we don't need to subclass Fixture for that, as there's no DB access there.

This comment has been minimized.

Copy link
@franciscoruiz

franciscoruiz Mar 29, 2011

Author Member

Test suites are reorganized in 238f3e6.

"""
Test for automatic setting of the default specialization type at creation
time on BaseGeneralizedModel
"""

def test_match(self):
"""
Ensure that the default specialization type is set correctly
"""
pencil = FountainPen()
eq_(pencil.specialization_type, FountainPen.model_specialization)


class TestGetAsSpecialization(FixtureTestCase):
"""Tests for the get_as_specialization method on general models"""

Expand Down

0 comments on commit 4d56077

Please sign in to comment.