Permalink
Browse files

100% de testes no módulo ``utils.sync.dataloader``

  • Loading branch information...
1 parent d30d8c0 commit b25b51fe239a6de6de3e957db6f049a3b78d98e5 @gustavofonseca committed Mar 7, 2013
Showing with 47 additions and 7 deletions.
  1. +4 −4 opac/utils/sync/dataloader.py
  2. +1 −1 opac/utils/tasks.py
  3. +42 −2 opac/utils/tests/tests_dataloader.py
@@ -7,16 +7,16 @@
class Marreta(object):
- def __init__(self, mongoconn_lib=mongomodels.MongoConnector,
- pymongo_lib=pymongo,
+ def __init__(self, mongoconn_dep=mongomodels.MongoConnector,
+ pymongo_dep=pymongo,
settings=settings):
mongo_uri = getattr(settings, 'MONGO_URI', None)
if not mongo_uri:
raise ValueError('missing config to mongodb')
- self._mongoconn = mongoconn_lib(mongodb_driver=pymongo_lib,
+ self._mongoconn = mongoconn_dep(mongodb_driver=pymongo_dep,
mongo_uri=mongo_uri)
def rebuild_collection(self, collection, new_data):
@@ -39,7 +39,7 @@ def rebuild_collection(self, collection, new_data):
return None
- def update_collection(self, collection, new_data):
+ def update_journals(self, new_data, collection='journals'):
col = self._mongoconn.db[collection]
for data in new_data:
View
@@ -54,7 +54,7 @@ def update_catalog(managerapi_dep=datacollector.SciELOManagerAPI):
transformed_journals_data = journal_ppl.run(journals_data)
marreta = dataloader.Marreta(settings=settings)
- marreta.update_collection('journals', transformed_journals_data)
+ marreta.update_journals('journals', transformed_journals_data)
sync.last_seq = changes.last_seq
sync.status = 'finished'
@@ -1,4 +1,3 @@
-import unittest
import mocker
@@ -32,7 +31,48 @@ def test_rebuild_database(self):
self.mocker.replay()
- m = self._makeOne(pymongo_lib=mock_pymongo)
+ m = self._makeOne(pymongo_dep=mock_pymongo)
data = [{'title': "the hitchhiker's guide to the galaxy"}]
self.assertIsNone(m.rebuild_collection('journals', data))
+
+ def test_update_journals(self):
+ mock_mongo_conn = self.mocker.mock()
+ mock_mongo_db = self.mocker.mock()
+ mock_mongo_col = self.mocker.mock()
+
+ mock_mongo_conn(mongodb_driver=mocker.ANY, mongo_uri=mocker.ANY)
+ self.mocker.result(mock_mongo_conn)
+
+ mock_mongo_conn.db
+ self.mocker.result(mock_mongo_db)
+
+ mock_mongo_db['journals']
+ self.mocker.result(mock_mongo_col)
+
+ mock_mongo_col.update({'id': 1},
+ {
+ 'title': "the hitchhiker's guide to the galaxy",
+ 'id': 1,
+ },
+ w=1,
+ upsert=True)
+ self.mocker.result('spam_objectId')
+
+ self.mocker.replay()
+
+ m = self._makeOne(mongoconn_dep=mock_mongo_conn)
+
+ data = [{'title': "the hitchhiker's guide to the galaxy", 'id': 1}]
+ self.assertIsNone(m.update_journals(data))
+
+ def test_missing_settings_MONGO_URI_raises_exception(self):
+ mock_settings = self.mocker.mock()
+
+ mock_settings.MONGO_URI
+ self.mocker.result(None)
+
+ self.mocker.replay()
+
+ self.assertRaises(ValueError,
+ lambda: self._makeOne(settings=mock_settings))

0 comments on commit b25b51f

Please sign in to comment.