Permalink
Browse files

More tests

Made huge dent into ContextBySpec. at 84% coverage. Changed Node.py to help with error handling.
  • Loading branch information...
1 parent ed5b6fb commit ed63ceaf58d287645ef792d869a1fa74f2b37f93 Josh Finnie committed Nov 30, 2012
Showing with 213 additions and 71 deletions.
  1. +10 −6 lumin/node.py
  2. +203 −65 lumin/tests/test_node.py
View
@@ -33,17 +33,20 @@ def __init__(self, request):
class Collection(Factory):
- """Represents a collection context."""
+ """Represents a collection context.
+ :param duplicate_key_error: For testing purposes.
+ """
# Database collection name
collection = None
- def __init__(self, request, name=None):
+ def __init__(self, request, name=None, duplicate_key_error=DuplicateKeyError):
super(Collection, self).__init__(request)
name = self.collection = name if name is not None else self.collection
self._collection = request.db[name]
self._collection_history = request.db['%s.history' % name]
+ self.duplicate_key_error = duplicate_key_error
@property
def __name__(self):
@@ -84,7 +87,7 @@ def insert(self, doc, title_or_id, increment=True, seperator='-'):
try:
oid = self._collection.insert(doc, safe=True)
break
- except DuplicateKeyError:
+ except self.duplicate_key_error:
suffix += 1
_id_suffixed = seperator.join([_id, str(suffix)])
doc['_id'] = _id_suffixed
@@ -355,9 +358,10 @@ class ContextBySpec(Collection):
def __init__(self,
request,
_id=None,
- name=None, ## NB: collection name
+ name=None, # NB: collection name
data=None,
- spec={}):
+ spec={},
+ duplicate_key_error=DuplicateKeyError):
super(ContextBySpec, self).__init__(request, name)
## We can't limit to one or the other. Currently resource in
@@ -527,7 +531,7 @@ def insert(self, doc, title_or_id, increment=True, seperator='-'):
try:
self._collection.insert(doc, safe=True)
break
- except DuplicateKeyError as e:
+ except self.duplicate_key_error as e:
suffix += 1
__name___suffixed = seperator.join([_id, str(suffix)])
doc['__name__'] = __name___suffixed
Oops, something went wrong.

0 comments on commit ed63cea

Please sign in to comment.