def test_save(self): from lumin.node import ContextById # Insert item directly into collection self.request.db['test'].insert( {'_id': 'frobnitz'}, {'title': 'Frobnitz'} ) context = ContextById(self.request, 'frobnitz', 'test') context.data.update({'title': 'Frobbozz'}) context.save() history = context.history() self.assertEquals(history.count(), 0) self.assertRaises(StopIteration, next, history) self.assertTrue(context.data['mtime'])
def test_update(self): # Insert item directly into collection self.request.db['test'].insert( {'_id': 'frobnitz'}, {'title': 'Frobnitz'} ) from lumin.node import ContextById context = ContextById(self.request, 'frobnitz', 'test') result = context.update({'title': 'Frobbozz'}) self.assertEqual(result, None) self.assertEqual(context.data['title'], 'Frobbozz') data = next(self.request.db['test'].find({'_id': 'frobnitz'})) self.assertEqual(data['title'], context.data['title']) self.assertEqual(data['changed_by'], '') self.assertTrue(data['mtime'])
def test_context_with_data(self): """A context can be constructed directly from document data. """ from lumin.node import ContextById self.request.db['test'].insert( {'_id': 'frobnitz', 'title': 'Frobnitz'}) doc = self.request.db['test'].find_one({'_id': 'frobnitz'}) context = ContextById(self.request, 'frobnitz', 'test', data=doc) self.assertEqual( context.data, {'_id': 'frobnitz', 'title': 'Frobnitz'}) context.data['abc'] = 123 context.save() doc = self.request.db['test'].find_one({'_id': 'frobnitz'}) doc.pop('mtime') self.assertEqual( doc, dict(_id='frobnitz', title='Frobnitz', abc=123, changed_by=''))
def test_empty_default__acl__(self): self.request.db['test'].insert({'_id': 'frobnitz', 'title': ''}) from lumin.node import ContextById context = ContextById(self.request, 'frobnitz', 'test') self.assertEquals(context.__acl__, []) context.__acl__ = [[1, 2, 3]] self.assertEquals(context.__acl__, [[1, 2, 3]]) context.save() document = self.request.db['test'].find_one({'_id': 'frobnitz'}) self.failUnless(document.get('__acl__', None), [[1, 2, 3]]) del context.__acl__ self.assertEquals(context.__acl__, []) context.save() document = self.request.db['test'].find_one({'_id': 'frobnitz'}) self.failIf(document.get('__acl__', None))
def test_update_history(self): # Insert item directly into collection self.request.db['test'].insert({'_id': 'frobnitz', 'title': ''}) from lumin.node import ContextById context = ContextById(self.request, 'frobnitz', 'test') # Update 1 context.update({'title': 'Frobnitz'}) # Update 2 context.update({'title': 'Frobbozz'}) history = context.history() self.assertEqual(history.count(), 2) obj = next(history) self.assertEqual(obj['title'], 'Frobnitz') self.assertNotEqual(obj['mtime'], context.data['mtime']) #import pdb; pdb.set_trace() self.assertEqual(next(history)['title'], '') self.assertEqual(context.data['title'], 'Frobbozz')