From eca5e9e109010e663fd49f55a13771beabc213f8 Mon Sep 17 00:00:00 2001 From: Harris Tzovanakis Date: Mon, 26 Feb 2024 16:45:02 +0100 Subject: [PATCH] articles: fixes --- scoap3/articles/tests/test_article_views.py | 49 +-------------------- scoap3/tasks.py | 35 +++------------ 2 files changed, 7 insertions(+), 77 deletions(-) diff --git a/scoap3/articles/tests/test_article_views.py b/scoap3/articles/tests/test_article_views.py index a1e344951..dd1265b2f 100644 --- a/scoap3/articles/tests/test_article_views.py +++ b/scoap3/articles/tests/test_article_views.py @@ -1,14 +1,10 @@ import json -import os -from pathlib import Path import pytest -from django.test import TestCase from django.urls import reverse from rest_framework import status -from scoap3.articles.models import Article, ArticleIdentifier -from scoap3.users.tests.factories import UserFactory +from scoap3.articles.models import Article pytestmark = pytest.mark.django_db @@ -76,9 +72,6 @@ def test_update_article_from_workflow(self, client, user, shared_datadir): assert "10.5506/APhysPolB.54.10-A3" in expected_dois -pytestmark = pytest.mark.django_db - - class TestArticleIdentifierViewSet: def test_get_article_identifier(self, client): url = reverse("api:articleidentifier-list") @@ -88,43 +81,3 @@ def test_get_article_identifier(self, client): url = reverse("api:articleidentifier-detail", kwargs={"pk": 0}) response = client.get(url) assert response.status_code == status.HTTP_404_NOT_FOUND - - -pytestmark = pytest.mark.django_db - - -class TestTheSameArticleCreationTwice(TestCase): - @staticmethod - def shared_datadir(): - return os.path.join( - Path(__file__).parent.resolve(), "data", "record_failing_on_airflow.json" - ) - - def test_create_article_from_workflow(self): - user = UserFactory() - self.client.force_login(user) - with open(self.shared_datadir()) as file: - contents = file.read() - data = json.loads(contents) - response = self.client.post( - reverse("api:article-workflow-import-list"), - data, - content_type="application/json", - ) - assert response.status_code == status.HTTP_200_OK - - response = self.client.post( - reverse("api:article-workflow-import-list"), - data, - content_type="application/json", - ) - assert response.status_code == status.HTTP_200_OK - doi = data.get("dois")[0].get("value") - assert ( - len( - ArticleIdentifier.objects.filter( - identifier_type="DOI", identifier_value=doi - ) - ) - == 1 - ) diff --git a/scoap3/tasks.py b/scoap3/tasks.py index 53785eb68..535a82dc5 100644 --- a/scoap3/tasks.py +++ b/scoap3/tasks.py @@ -125,16 +125,8 @@ def _create_article_identifier(data, article): "identifier_type": "arXiv", "identifier_value": arxiv.get("value"), } - doi = data.get("dois")[0].get("value") - if ArticleIdentifier.objects.filter( - identifier_type="arXiv", article_id=article - ).exists(): - article_identifier = ArticleIdentifier.objects.get( - article_id=article, identifier_type="arXiv" - ) - article_identifier.__dict__.update(**article_identifier_data) - else: - ArticleIdentifier.objects.get_or_create(**article_identifier_data) + + ArticleIdentifier.objects.get_or_create(**article_identifier_data) def _create_copyright(data, article): @@ -145,11 +137,7 @@ def _create_copyright(data, article): "holder": copyright.get("holder", ""), "year": copyright.get("year"), } - if Copyright.objects.filter(article_id=article).exists(): - copyright = Copyright.objects.get(article_id=article) - copyright.__dict__.update(**copyright_data) - else: - Copyright.objects.get_or_create(**copyright_data) + Copyright.objects.get_or_create(**copyright_data) def _create_article_arxiv_category(data, article): @@ -162,15 +150,7 @@ def _create_article_arxiv_category(data, article): "category": arxiv_category, "primary": True if idx == 0 else False, } - if ArticleArxivCategory.objects.filter(article_id=article).exists(): - article_arxiv_category = ArticleArxivCategory.objects.get( - article_id=article - ) - article_arxiv_category.__dict__.update(**article_arxiv_category_data) - else: - ArticleArxivCategory.objects.get_or_create( - **article_arxiv_category_data - ) + ArticleArxivCategory.objects.get_or_create(**article_arxiv_category_data) def _create_publisher(data): @@ -198,11 +178,8 @@ def _create_publication_info(data, article, publishers): "journal_issue_date": publication_info.get("journal_issue_date"), "publisher_id": publishers[idx].id, } - if PublicationInfo.objects.filter(article_id=article).exists(): - publication_info = PublicationInfo.objects.get(article_id=article) - publication_info.__dict__.update(**publication_info_data) - else: - PublicationInfo.objects.get_or_create(**publication_info_data) + + PublicationInfo.objects.get_or_create(**publication_info_data) def _create_experimental_collaborations(data):