summaryrefslogtreecommitdiffstats
path: root/python/tests/harvest_datacite.py
diff options
context:
space:
mode:
authorMartin Czygan <martin@archive.org>2019-12-26 23:52:39 +0000
committerMartin Czygan <martin@archive.org>2019-12-26 23:52:39 +0000
commitad39a2a347b356fe9bb7dd96d79e2fdbf4844b9c (patch)
treececab3300e67be677694cfc87bdccd6871babe6c /python/tests/harvest_datacite.py
parent035ac1480f3d3c69d771b7793e973d38ce1c561a (diff)
parent6afc3e8d0e01cba781928dbc2bcb53d3c3ff71fd (diff)
downloadfatcat-ad39a2a347b356fe9bb7dd96d79e2fdbf4844b9c.tar.gz
fatcat-ad39a2a347b356fe9bb7dd96d79e2fdbf4844b9c.zip
Merge branch 'martin-datacite-daily-harvest' into 'master'
Datacite daily harvest See merge request webgroup/fatcat!6
Diffstat (limited to 'python/tests/harvest_datacite.py')
-rw-r--r--python/tests/harvest_datacite.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/python/tests/harvest_datacite.py b/python/tests/harvest_datacite.py
new file mode 100644
index 00000000..926d67ba
--- /dev/null
+++ b/python/tests/harvest_datacite.py
@@ -0,0 +1,45 @@
+
+import json
+import pytest
+import datetime
+import responses
+from fatcat_tools.harvest import *
+
+
+@responses.activate
+def test_datacite_harvest_date(mocker):
+
+ # mock out the harvest state object so it doesn't try to actually connect
+ # to Kafka
+ mocker.patch('fatcat_tools.harvest.harvest_common.HarvestState.initialize_from_kafka')
+
+ # mock day request to crossref API
+ with open('tests/files/datacite_api.json', 'r') as f:
+ crossref_resp = json.loads(f.readline())
+ responses.add(responses.GET, 'https://api.datacite.org/dois',
+ json=crossref_resp, status=200)
+
+ harvester = HarvestDataciteWorker(
+ kafka_hosts="dummy",
+ produce_topic="dummy-produce-topic",
+ state_topic="dummy-state-topic",
+ contact_email="test@fatcat.wiki",
+ )
+
+ harvester.producer = mocker.Mock()
+
+ harvester.fetch_date(datetime.date(2019, 2, 3))
+
+ assert len(responses.calls) == 1
+
+ # ensure email was included in User-Agent
+ assert "mailto:test@fatcat.wiki" in responses.calls[0].request.headers['User-Agent']
+
+ # check that correct date param was passed as expected
+ assert "query=updated%3A%5B2019-02-03T00%3A00%3A00.000Z+TO+2019-02-03T23%3A59%3A59.999Z%5D" in responses.calls[0].request.url
+
+ # check that we published the expected number of DOI objects were published
+ # to the (mock) kafka topic
+ assert harvester.producer.produce.call_count == 1
+ assert harvester.producer.flush.call_count == 1
+ assert harvester.producer.poll.called_once_with(0)