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

Commit

Permalink
added test to check _p_changed setting on load, fixed _v_name setting…
Browse files Browse the repository at this point in the history
… in _locate
  • Loading branch information
Adam Groszer committed Mar 5, 2013
1 parent 88e24db commit b813b6a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/mongopersist/zope/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _locate(self, obj, doc):
# Helper method that is only used when locating items that are already
# in the container and are simply loaded from Mongo.
if obj.__name__ is None:
obj.__name__ = doc[self._m_mapping_key]
obj._v_name__ = doc[self._m_mapping_key]
if obj.__parent__ is None:
obj._v_parent = self

Expand Down
63 changes: 61 additions & 2 deletions src/mongopersist/zope/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ZODB.DemoStorage
import persistent
import pymongo
import random
import re
import transaction
import zope.component
Expand Down Expand Up @@ -217,7 +218,7 @@ def doctest_MongoContained_mixed():
When the container is stored in the ZODB or another persistence mechanism,
a mixed usage of proxy attributes and getter/setter functions is the best
appraoch.
approach.
>>> class Mixers(btree.BTreeContainer):
... def __init__(self, name):
Expand Down Expand Up @@ -486,7 +487,7 @@ def doctest_MongoContainer_constructor():
def doctest_MongoContainer_m_parent_key_value():
r"""MongoContainer: _m_parent_key_value()
This method is used to extract the parent refernce for the item.
This method is used to extract the parent reference for the item.
>>> c = container.MongoContainer('person')
Expand Down Expand Up @@ -1062,6 +1063,64 @@ def doctest_Realworldish():
"""


class People(container.AllItemsMongoContainer):
_p_mongo_collection = 'people'
_m_collection = 'person'


class Address(persistent.Persistent):
_p_mongo_collection = 'address'

def __init__(self, city):
self.city = city


class PeoplePerson(persistent.Persistent, container.MongoContained):
_p_mongo_collection = 'person'
_p_mongo_store_type = True

def __init__(self, name, age):
self.name = name
self.age = age
self.address = Address('Boston %i' %age)

def __repr__(self):
return '<%s %s @ %i [%s]>' %(
self.__class__.__name__, self.name, self.age, self.__name__)


def doctest_load_does_not_set_p_changed():
"""We need to guarantee that _p_changed is not True on obj load
Let's add some objects:
>>> transaction.commit()
>>> dm.root['people'] = people = People()
>>> x = transaction.begin()
>>> for idx in xrange(2):
... people[None] = PeoplePerson('Mr Number %.5i' %idx, random.randint(0, 100))
>>> transaction.commit()
>>> objs = [o for o in people.values()]
>>> len(objs)
2
>>> [o._p_changed for o in objs]
[False, False]
>>> [o._p_changed for o in people.values()]
[False, False]
>>> transaction.commit()
>>> x = transaction.begin()
>>> [o._p_changed for o in people.values()]
[False, False]
>>> [o._p_changed for o in people.values()]
[False, False]
"""

checker = renormalizing.RENormalizing([
(re.compile(r'datetime.datetime(.*)'),
'datetime.datetime(2011, 10, 1, 9, 45)'),
Expand Down

0 comments on commit b813b6a

Please sign in to comment.