def test_return_correct_length(self): self.document['key_1'] = 1 self.document['key_2'] = 2 other_document = MongoDictAdapter('other_id', database=self.db_name) other_document['other_key'] = 3 self.assertEquals(len(self.document), 2)
def test_iterating_through_keys_does_not_bring_keys_from_other_docs(self): self.document['key_1'] = 1 self.document['key_2'] = 2 other_document = MongoDictAdapter('other_id', database=self.db_name) other_document['other_key'] = 3 keys = [k for k in self.document] self.assertIn('key_1', keys) self.assertIn('key_2', keys) self.assertNotIn('key_3', keys) self.assertEquals(['key_1', 'key_2'], self.document.keys())
def test_clear_should_not_remove_keys_for_other_docs(self): self.document['key_1'] = 1 self.document['key_2'] = 2 other_document = MongoDictAdapter('other_id', database=self.db_name) other_document['other_key'] = 3 self.document.clear() with self.assertRaises(KeyError): self.document['key_1'] self.document['key_2'] self.assertEqual(other_document['other_key'], 3)
def run(self, document_id): """ This method is called by Celery, and should not be overridden. It will call the `process` method with a dictionary containing all the document information and will update de database with results. """ document = MongoDictAdapter(doc_id=document_id, host=config.MONGODB_CONFIG['host'], port=config.MONGODB_CONFIG['port'], database=config.MONGODB_CONFIG['database']) # Create a dictionary out of our document. We could simply pass # it on to the process method, but for now we won't let the user # manipulate the MongoDict directly. dic = {k: v for k, v in document.iteritems()} result = self.process(dic) document.update(result) return document_id
def setUp(self): app.conf.update(CELERY_ALWAYS_EAGER=True) self.fake_id = '1234' self.document = MongoDictAdapter(self.fake_id, database=self.db_name) self.db = pymongo.Connection()[self.db_name]
def setUp(self): self.fake_id = '1234' self.document = MongoDictAdapter(self.fake_id, database=self.db_name) self.db = pymongo.Connection()[self.db_name]