Skip to content

Commit

Permalink
Using non-primary column in hybrid tests
Browse files Browse the repository at this point in the history
The hybrid property tests modified the primary key with fromdict, which
shouldn't be possible(another separate bug).

Changed to using a non primary key hybrid property for testing.
  • Loading branch information
danielholmstrom committed May 10, 2014
1 parent 4104a41 commit 2e5820f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
18 changes: 10 additions & 8 deletions dictalchemy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,20 @@ class WithHybrid(Base):

__tablename__ = 'withhybrid'

_id = Column('id', Integer, primary_key=True)
id = Column('id', Integer, primary_key=True)

_value = Column('value', Integer)

@hybrid_property
def id(self):
return self._id
def value(self):
return self._value

@id.setter
def set_id(self, value):
self._id = value
@value.setter
def set_value(self, value):
self._value = value

def __init__(self, id):
self.id = id
def __init__(self, value):
self.value = value


class WithDefaultInclude(Base):
Expand Down
16 changes: 8 additions & 8 deletions dictalchemy/tests/test_asdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,24 @@ def test_multiple_child_follow_two_levels_with_arguments(self):
'child': {'name': c1c.name}}}

def test_hybrid_property(self):
assert WithHybrid(2).asdict(include=['id']) == {'id': 2}
assert WithHybrid(2).asdict(include=['value'])['value'] == 2

def test_default_include(self):
assert WithDefaultInclude(2).asdict() == {'id': 2, 'id_alias': 2}

def test_dictalchemy_include(self):
m = WithHybrid(2)
assert 'id' not in dict(m)
setattr(m, 'dictalchemy_include', ['id'])
assert 'id' in dict(m)
assert 'value' not in dict(m)
setattr(m, 'dictalchemy_include', ['value'])
assert 'value' in dict(m)

def test_dictalchemy_asdict_include_overrides(self):
m = WithHybrid(2)
assert 'id' not in dict(m)
setattr(m, 'dictalchemy_include', ['id'])
assert 'id' in dict(m)
assert 'value' not in dict(m)
setattr(m, 'dictalchemy_include', ['value'])
assert 'value' in dict(m)
setattr(m, 'dictalchemy_asdict_include', [])
assert 'id' not in dict(m)
assert 'value' not in dict(m)

def test_attribute_mapped_collection(self):
p = WithAttributeMappedCollection()
Expand Down
26 changes: 13 additions & 13 deletions dictalchemy/tests/test_fromdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ def test_exclude(self):

def test_include(self):
h = WithHybrid(1)
h.fromdict({'id': 17}, include=['id'])
assert h.id == 17
h.fromdict({'value': 17}, include=['value'])
assert h.value == 17

def test_dictalchemy_include(self):
m = WithHybrid(2)
m.fromdict({'id': 7})
assert m.id == 2
setattr(m, 'dictalchemy_include', ['id'])
m.fromdict({'id': 7})
assert m.id == 7
m.fromdict({'value': 7})
assert m.value == 2
setattr(m, 'dictalchemy_include', ['value'])
m.fromdict({'value': 7})
assert m.value == 7

def test_dictalchemy_asdict_include_overrides(self):
m = WithHybrid(2)
m.fromdict({'id': 7})
assert m.id == 2
setattr(m, 'dictalchemy_include', ['id'])
m.fromdict({'id': 7})
m.fromdict({'value': 7})
assert m.value == 2
setattr(m, 'dictalchemy_include', ['value'])
m.fromdict({'value': 7})
setattr(m, 'dictalchemy_fromdict_include', [])
m.fromdict({'id': 2})
assert m.id == 7
m.fromdict({'value': 2})
assert m.value == 7

def test_default_include(self):
h = WithDefaultInclude(1)
Expand Down

0 comments on commit 2e5820f

Please sign in to comment.