diff --git a/scoap3/articles/tests/test_article_views.py b/scoap3/articles/tests/test_article_views.py index aa5fad738..5f634828d 100644 --- a/scoap3/articles/tests/test_article_views.py +++ b/scoap3/articles/tests/test_article_views.py @@ -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 ): diff --git a/scoap3/tasks.py b/scoap3/tasks.py index 30e44181c..9a245efee 100644 --- a/scoap3/tasks.py +++ b/scoap3/tasks.py @@ -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: