Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Fix getting attribute from relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
charlax committed Jan 21, 2014
1 parent ad92ccf commit ad7a331
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion charlatan/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def get_instance(self, path=None, include_relationships=True, fields=None):

setattr(instance, attr, value)

return instance
if path:
return getattr(instance, path)
else:
return instance

def get_class(self):
"""Return class object for this instance."""
Expand Down
9 changes: 9 additions & 0 deletions charlatan/tests/data/relationships.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ relationship_alone:
fields:
name: "red"
model: charlatan.tests.fixtures.models:Color

toaster:
fields:
color: red
slots: 3
model: charlatan.tests.fixtures.simple_models:Toaster

toaster_colors:
fields: [!rel toaster.color]
15 changes: 15 additions & 0 deletions charlatan/tests/test_relationships.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from charlatan import testcase, testing, FixturesManager


class TestRelationhips(testing.TestCase, testcase.FixturesManagerMixin):

def setUp(self):
self.fixtures_manager = FixturesManager()
self.fixtures_manager.load(
'./charlatan/tests/data/relationships.yaml')
self.init_fixtures()

def test_get_attr_from_rel(self):
"""Verify we can get an attribute from a relationship."""
fixture = self.get_fixture("toaster_colors")
self.assertEqual(fixture, ['red'])

0 comments on commit ad7a331

Please sign in to comment.