Skip to content

Commit

Permalink
articles: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Feb 26, 2024
1 parent 00502d2 commit eca5e9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 77 deletions.
49 changes: 1 addition & 48 deletions scoap3/articles/tests/test_article_views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")
Expand All @@ -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
)
35 changes: 6 additions & 29 deletions scoap3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit eca5e9e

Please sign in to comment.