Skip to content

Commit c5e7196

Browse files
committed
add test for checking if DOI is in HAL
1 parent 56200b4 commit c5e7196

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/push2HAL/libHAL.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
def getDataFromHAL(
3535
txtsearch=None,
3636
typeI=None,
37-
typeDB=None,
37+
typeDB="article",
3838
typeR="json",
3939
returnFields="title_s,author_s,halId_s,label_s,docid",
4040
url=dflt.HAL_API_SEARCH_URL,
@@ -76,6 +76,9 @@ def getDataFromHAL(
7676
elif typeI == "docId":
7777
Logger.debug("Searching for document's ID: {}".format(txtsearch))
7878
query = "halId_s:{}".format(txtsearch)
79+
elif typeI == "doi":
80+
Logger.debug("Searching for document's doi: {}".format(txtsearch))
81+
query = "doiId_id:{}".format(txtsearch)
7982
#
8083
Logger.debug("Return format: {}".format(typeR))
8184

@@ -100,6 +103,19 @@ def getDataFromHAL(
100103
return data
101104
return []
102105

106+
def checkDoiInHAL(doi):
107+
""" Check if DOI is already in HAL """
108+
# request
109+
dataFromHAL = getDataFromHAL(txtsearch=doi,
110+
typeI='doi',
111+
typeDB="article",
112+
typeR="json")
113+
return_code = False
114+
if dataFromHAL:
115+
if len(dataFromHAL) > 0:
116+
return_code = True
117+
return return_code
118+
103119

104120
def choose_from_results(
105121
results, forceSelection=False, maxNumber=dflt.DEFAULT_MAX_NUMBER_RESULTS

tests/libHAL_manu.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from push2HAL import libHAL
2+
3+
doi = '10.1007/s11831-017-9226-3'
4+
res = libHAL.checkDoiInHAL('10.1007/s11831-017-9226-3')
5+
print('{} in HAL: {}'.format(doi,res))
6+
7+
doi = '10.1007/XXXX'
8+
res = libHAL.checkDoiInHAL('10.1007/XXXX')
9+
print('{} in HAL: {}'.format(doi,res))

tests/test_libHAL.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from push2HAL import libHAL
3+
4+
def test_doiInHAL():
5+
res = libHAL.checkDoiInHAL('10.1007/s11831-017-9226-3')
6+
assert res == True
7+
8+
def test_doiNotInHAL():
9+
res = libHAL.checkDoiInHAL('10.1007/XXXX')
10+
assert res == False

0 commit comments

Comments
 (0)