def test_add_to_couch_queue_if_nonzero_given_metrics(self): test_couch_queue = backend.PythonQueue("test_couch_queue") provider_worker = backend.ProviderWorker( mocks.ProviderMock("myfakeprovider"), None, None, None, {"a": test_couch_queue}, None, self.r) metrics_method_response = { 'dryad:package_views': (361, 'http://dx.doi.org/10.5061/dryad.7898'), 'dryad:total_downloads': (176, 'http://dx.doi.org/10.5061/dryad.7898'), 'dryad:most_downloaded_file': (65, 'http://dx.doi.org/10.5061/dryad.7898') } response = provider_worker.add_to_couch_queue_if_nonzero( "aaatiid", #start fake tiid with "a" so in first couch queue metrics_method_response, "metrics", "dummy") # test that it put it on the queue in_queue = test_couch_queue.pop() expected = { 'method_name': 'metrics', 'tiid': 'aaatiid', 'provider_name': 'myfakeprovider', 'analytics_credentials': 'dummy', 'new_content': metrics_method_response } print in_queue assert_equals(in_queue, expected) # check nothing in redis since it had a value response = self.r.get_num_providers_currently_updating("aaatiid") assert_equals(response, 0)
def test_run_metrics_in_queue(self): test_couch_queue = backend.PythonQueue("test_couch_queue") test_couch_queue_dict = {self.fake_item["_id"][0]: test_couch_queue} provider_worker = backend.ProviderWorker( mocks.ProviderMock("myfakeprovider"), None, None, None, test_couch_queue_dict, None, self.r) metrics_method_response = { 'dryad:package_views': (361, 'http://dx.doi.org/10.5061/dryad.7898'), 'dryad:total_downloads': (176, 'http://dx.doi.org/10.5061/dryad.7898'), 'dryad:most_downloaded_file': (65, 'http://dx.doi.org/10.5061/dryad.7898') } response = provider_worker.add_to_couch_queue_if_nonzero( self.fake_item["_id"], metrics_method_response, "metrics", "dummy") # save basic item beforehand item_obj = item_module.create_objects_from_item_doc(self.fake_item) self.db.session.add(item_obj) self.db.session.commit() # run couch_worker = backend.CouchWorker(test_couch_queue, self.r, self.d) couch_worker.run() # check couch_queue has value after response = item_module.get_item(self.fake_item["_id"], {}, self.r) print response expected = 361 assert_equals( response["metrics"]['dryad:package_views']['values']["raw"], expected)
def test_run_aliases_in_queue(self): test_couch_queue = backend.PythonQueue("test_couch_queue") test_couch_queue_dict = {self.fake_item["_id"][0]: test_couch_queue} provider_worker = backend.ProviderWorker( mocks.ProviderMock("myfakeprovider"), None, None, None, test_couch_queue_dict, None, self.r) response = provider_worker.add_to_couch_queue_if_nonzero( self.fake_item["_id"], {"doi": ["10.5061/dryad.3td2f"]}, "aliases", "dummy") # save basic item beforehand item_obj = item_module.create_objects_from_item_doc(self.fake_item) self.db.session.add(item_obj) self.db.session.commit() # run couch_worker = backend.CouchWorker(test_couch_queue, self.r, self.d) response = couch_worker.run() expected = None assert_equals(response, expected) # check couch_queue has value after response = item_module.get_item(self.fake_item["_id"], {}, self.r) print response expected = {'pmid': ['111'], 'doi': ['10.5061/dryad.3td2f']} assert_equals(response["aliases"], expected) # check has updated last_modified time now = datetime.datetime.utcnow().isoformat() assert_equals(response["last_modified"][0:10], now[0:10])
def test_add_to_couch_queue_if_nonzero(self): test_couch_queue = backend.PythonQueue("test_couch_queue") provider_worker = backend.ProviderWorker( mocks.ProviderMock("myfakeprovider"), None, None, None, {"a": test_couch_queue}, None, self.r) response = provider_worker.add_to_couch_queue_if_nonzero( "aaatiid", #start fake tiid with "a" so in first couch queue {"doi": ["10.5061/dryad.3td2f"]}, "aliases", "dummy") # test that it put it on the queue in_queue = test_couch_queue.pop() expected = ('aaatiid', {'doi': ['10.5061/dryad.3td2f']}, 'aliases') assert_equals(in_queue, expected)
def test_add_to_couch_queue_if_nonzero_given_empty_metrics_response(self): test_couch_queue = backend.PythonQueue("test_couch_queue") provider_worker = backend.ProviderWorker( mocks.ProviderMock("myfakeprovider"), None, None, None, {"a": test_couch_queue}, None, self.r) metrics_method_response = {} response = provider_worker.add_to_couch_queue_if_nonzero( "aaatiid", #start fake tiid with "a" so in first couch queue metrics_method_response, "metrics", "dummy") # test that it did not put it on the queue in_queue = test_couch_queue.pop() expected = None assert_equals(in_queue, expected) # check decremented in redis since the payload was null response = num_left = self.r.get_num_providers_left("aaatiid") assert_equals(response, -1)