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_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_nothing_in_queue(self):
     test_couch_queue = backend.PythonQueue("test_couch_queue")
     couch_worker = backend.CouchWorker(test_couch_queue, self.r, self.d)
     response = couch_worker.run()
     expected = None
     assert_equals(response, expected)