def test_should_raise_error_if_duplicate_data_managers_are_used_on_the_same_document(
         self):
     self.doc['name'] = 'Saruman'
     transaction.commit()
     doc2 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     doc3 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     doc2['profession'] = 'wizard'
     doc3['profession'] = 'warlock'
     self.assertRaises(DuplicateDataManagersError, transaction.commit)
示例#2
0
	def test_save_should_be_ignored_on_transactional_document(self):
		session = SessionStub()
		doc = MongoDocument(session, colname)
		doc['name'] = 'Saruman'
		doc.save()
		self.assertNotEqual(doc.committed, doc.uncommitted)
		self.assertIn(doc, transaction.get()._resources)
示例#3
0
	def test_should_enter_transaction_when_data_deleted(self):
		session = SessionStub()
		doc = MongoDocument(session, colname)
		doc.committed = {'name': 'Saruman', 'profession': 'wizard'}
		doc.uncommitted = doc.committed.copy()
		del doc['profession']
		self.assertIn(doc, transaction.get()._resources)
 def test_data_equivalence_after_transaction_committed(self):
     self.doc['name'] = 'Saruman'
     transaction.commit()
     doc2 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     self.assertEqual(self.doc.uncommitted, self.doc.committed)
     self.assertEqual(self.doc.committed, doc2.committed)
 def test_data_equivalence_after_persisting(self):
     self.doc['name'] = 'Saruman'
     self.doc.save()
     doc2 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     self.assertEqual(self.doc.uncommitted, self.doc.committed)
     self.assertEqual(self.doc.committed, doc2.committed)
 def test_documents_should_be_persisted_on_calling_save_and_retrieved_correctly(
         self):
     self.doc['name'] = 'Saruman'
     self.doc.save()
     self.assertIn('_id', self.doc.committed)
     doc2 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     # should now both include mongodb _id
     self.assertEqual(self.doc.committed, doc2.committed)
 def test_should_correctly_persist_documents_in_multi_document_transaction(
         self):
     self.doc['firstname'] = 'Saruman'
     self.doc['lastname'] = 'theWhite'
     doc2 = MongoDocument(self.session, colname)
     doc2['firstname'] = 'Saruman'
     doc2['lastname'] = 'theGreen'
     transaction.commit()
     doc3 = MongoDocument(self.session,
                          colname,
                          retrieve={
                              'firstname': 'Saruman',
                              'lastname': 'theWhite'
                          })
     doc4 = MongoDocument(self.session,
                          colname,
                          retrieve={
                              'firstname': 'Saruman',
                              'lastname': 'theGreen'
                          })
     self.assertEqual(self.doc.committed, doc3.committed)
     self.assertEqual(doc2.committed, doc4.committed)
 def test_should_be_able_to_use_session_across_transactions(self):
     self.doc['name'] = 'Saruman'
     doc2 = MongoDocument(self.session, colname)
     # doc2 not part of this transaction since no data
     self.assertEqual(transaction.get()._resources, [self.doc])
     transaction.commit()
     doc2['name'] = 'Gandalf'
     # doc not part of this transaction since no changes
     self.assertEqual(transaction.get()._resources, [doc2])
     transaction.commit()
     self.doc['profession'] = 'wizard'
     doc2['profession'] = 'wizardToo'
     # both should be part of this transaction
     self.assertEqual(transaction.get()._resources, [self.doc, doc2])
     doc3 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     doc4 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Gandalf'})
     self.assertEqual(self.doc.committed, doc3.committed)
     self.assertEqual(doc2.committed, doc4.committed)
 def test_documents_should_be_persisted_only_after_transaction_committed(
         self):
     self.doc['name'] = 'Saruman'
     self.doc.save()
     self.assertRaises(DocumentNotFoundError,
                       MongoDocument,
                       self.session,
                       colname,
                       retrieve={'name': 'Saruman'})
     transaction.commit()
     doc2 = MongoDocument(self.session,
                          colname,
                          retrieve={'name': 'Saruman'})
     self.assertEqual(self.doc.committed, doc2.committed)
 def test_should_raise_error_if_retrieve_spec_does_not_find_unique_document(
         self):
     self.doc['firstname'] = 'Saruman'
     self.doc['lastname'] = 'theWhite'
     self.doc.save()
     doc2 = MongoDocument(self.session, colname)
     doc2['firstname'] = 'Saruman'
     doc2['lastname'] = 'theGreen'
     doc2.save()
     self.assertRaises(DocumentMatchNotUniqueError,
                       MongoDocument,
                       self.session,
                       colname,
                       retrieve={'firstname': 'Saruman'})
 def setUp(self):
     self.session = Session(dbname)
     self.doc = MongoDocument(self.session, colname)
 def setUp(self):
     self.session = Session(dbname, transactional=False)
     self.doc = MongoDocument(self.session, colname)
示例#13
0
	def test_transaction_on_closed_session_should_raise_error(self):
		session = SessionStub()
		session.active = False
		doc = MongoDocument(session, colname)
		self.assertRaises(SessionNotInitializedError, doc.__setitem__, 'name', 'Saruman')
示例#14
0
	def test_should_enter_transaction_when_deleted(self):
		session = SessionStub()
		doc = MongoDocument(session, colname)
		doc.delete()
		self.assertIn(doc, transaction.get()._resources)
示例#15
0
	def test_should_enter_transaction_when_contents_set(self):
		session = SessionStub()
		doc = MongoDocument(session, colname)
		doc.set({'name': 'Saruman'})
		self.assertIn(doc, transaction.get()._resources)
示例#16
0
	def test_should_enter_transaction_when_data_added(self):
		session = SessionStub()
		doc = MongoDocument(session, colname)
		doc['name'] = 'Saruman'
		self.assertIn(doc, transaction.get()._resources)