Skip to content

Commit

Permalink
articles: update import method for abstracts
Browse files Browse the repository at this point in the history
Signed-off-by: pamfilos <[email protected]>
  • Loading branch information
pamfilos committed Nov 28, 2024
1 parent 05140fc commit 808091e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions scoap3/articles/tests/test_article_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ def test_update_article_from_workflow(self, client, user, shared_datadir):
assert len(expected_dois) == 1
assert "10.5506/APhysPolB.54.10-A3" in expected_dois

def test_create_article_from_workflow_without_abstract(
self, client, user, shared_datadir
):
client.force_login(user)
contents = (shared_datadir / "workflow_record.json").read_text()
data = json.loads(contents)

del data["abstracts"]
response = client.post(
reverse("api:article-workflow-import-list"),
data,
content_type="application/json",
)

assert response.status_code == status.HTTP_200_OK
assert "abstract" in response.data
assert response.data["abstract"] == ""

article_id = response.data["id"]
article = Article.objects.get(id=article_id)
assert article.abstract == ""

def test_create_article_from_workflow_without_publication_date(
self, client, user, shared_datadir
):
Expand Down
6 changes: 5 additions & 1 deletion scoap3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ def _create_article(data, licenses):
article_data = {
"title": data["titles"][0].get("title"),
"subtitle": data["titles"][0].get("subtitle", ""),
"abstract": data["abstracts"][0].get("value", ""),
}

try:
article_data["abstract"] = data["abstracts"][0].get("value", "")
except (KeyError, IndexError):
pass

doi_exists = False
doi_value = data.get("dois")[0].get("value")
if doi_value:
Expand Down

0 comments on commit 808091e

Please sign in to comment.