Skip to content

Commit 6dc02a5

Browse files
committed
merge all commits into a single commit
Signed-off-by: John LaGrone <[email protected]>
1 parent 0657a07 commit 6dc02a5

File tree

5 files changed

+596
-597
lines changed

5 files changed

+596
-597
lines changed

coldfront/core/publication/tests/tests.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import bibtexparser.bibdatabase
1010
import bibtexparser.bparser
11-
import doi2bib
1211
from django.test import TestCase
1312

1413
import coldfront.core.publication
@@ -153,8 +152,7 @@ def mock_get_bib(unique_id):
153152
if unique_id == self._unique_id:
154153
return sentinel.status, sentinel.bib_str
155154

156-
crossref = Mock(spec_set=doi2bib.crossref)
157-
crossref.get_bib.side_effect = mock_get_bib
155+
mocked_get_bib = Mock(side_effect=mock_get_bib)
158156

159157
def mock_parse(thing_to_parse):
160158
# ensure bib_str from get_bib() is used
@@ -170,7 +168,7 @@ def mock_parse(thing_to_parse):
170168
as_text = Mock(spec_set=bibtexparser.bibdatabase.as_text)
171169
as_text.side_effect = lambda bib_entry: "as_text({})".format(bib_entry)
172170

173-
self.crossref = crossref
171+
self.mocked_get_bib = mocked_get_bib
174172
self.bibtexparser_cls = bibtexparser_cls
175173
self.as_text = as_text
176174

@@ -183,7 +181,7 @@ def dotpath(qualname):
183181
with contextlib.ExitStack() as stack:
184182
patches = [
185183
patch(dotpath("BibTexParser"), new=self.bibtexparser_cls),
186-
patch(dotpath("crossref"), new=self.crossref),
184+
patch(dotpath("get_bib"), new=self.mocked_get_bib),
187185
patch(dotpath("as_text"), new=self.as_text),
188186
]
189187
for p in patches:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: (C) ColdFront Authors
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
import requests
6+
7+
8+
def get_bib(doi_number):
9+
api_url = "http://api.crossref.org/works/{}/transform/application/x-bibtex"
10+
api_url = api_url.format(doi_number)
11+
req = requests.get(api_url)
12+
valid = True
13+
if req.status_code != 200:
14+
valid = False
15+
bib_entry = str(req.content, encoding="utf-8")
16+
17+
return valid, bib_entry

coldfront/core/publication/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from django.urls import reverse
1919
from django.views.generic import TemplateView, View
2020
from django.views.generic.edit import FormView
21-
from doi2bib import crossref
2221

2322
from coldfront.core.project.models import Project
2423
from coldfront.core.publication.forms import (
@@ -29,6 +28,7 @@
2928
PublicationSearchForm,
3029
)
3130
from coldfront.core.publication.models import Publication, PublicationSource
31+
from coldfront.core.publication.utils import get_bib
3232

3333
MANUAL_SOURCE = "manual"
3434

@@ -103,7 +103,7 @@ def _search_id(self, unique_id):
103103
for source in PublicationSource.objects.all():
104104
if source.name == "doi":
105105
try:
106-
status, bib_str = crossref.get_bib(unique_id)
106+
status, bib_str = get_bib(unique_id)
107107
bp = BibTexParser(interpolate_strings=False)
108108
bib_database = bp.parse(bib_str)
109109
bib_json = bib_database.entries[0]
@@ -486,7 +486,7 @@ def post(self, request, *args, **kwargs):
486486
)
487487
print("id is" + publication_obj.display_uid())
488488
publication_obj.display_uid()
489-
status, bib_str = crossref.get_bib(publication_obj.display_uid())
489+
status, bib_str = get_bib(publication_obj.display_uid())
490490
bp = BibTexParser(interpolate_strings=False)
491491
bp.parse(bib_str)
492492
bib_text += bib_str

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
2525
]
2626
dependencies = [
27+
"bibtexparser==1.4.3",
2728
"crispy-bootstrap4>=2024.10",
2829
"django>4.2,<5",
2930
"django-crispy-forms>=2.3",
@@ -36,13 +37,14 @@ dependencies = [
3637
"django-split-settings>=1.3.2",
3738
"django-su>=1.0.0",
3839
"djangorestframework>=3.16.0",
39-
"doi2bib>=0.4.0",
4040
"fontawesome-free>=5.15.4",
4141
"formencode>=2.1.1",
4242
"gunicorn>=23.0.0",
4343
"humanize>=4.12.2",
4444
"python-dateutil>=2.9.0.post0",
4545
"redis>=5.2.1",
46+
"requests==2.32.3",
47+
"urllib3==2.5.0",
4648
]
4749

4850
[project.urls]

0 commit comments

Comments
 (0)