-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
110 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,27 @@ | ||
import json | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
from django.test.client import Client | ||
from rest_framework.authtoken.models import Token | ||
from django.urls import reverse | ||
|
||
pytestmark = pytest.mark.django_db | ||
User = get_user_model() | ||
|
||
|
||
@pytest.fixture | ||
def admin_user_token(user): | ||
client = Client() | ||
password = "admin" | ||
my_admin = User.objects.create_superuser("admin", "[email protected]", password) | ||
client.login(username=my_admin.username, password="admin") | ||
user_token = Token.objects.create(user=user) | ||
return {"client": client, "user_token": user_token} | ||
|
||
|
||
@pytest.fixture | ||
def license_id(admin_user_token): | ||
license = {"url": "https://creativecommons.org/about/cclicenses/", "name": "cc"} | ||
response = admin_user_token["client"].post( | ||
"/api/license/", | ||
data=license, | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {admin_user_token['user_token']}", | ||
) | ||
return json.loads(response.content.decode("utf-8"))["id"] | ||
|
||
|
||
def test_article_post_and_delete(admin_user_token, license_id): | ||
response = admin_user_token["client"].get( | ||
"/api/license/", | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {admin_user_token['user_token']}", | ||
) | ||
@pytest.mark.django_db | ||
def test_article_post_and_delete(client, user, license): | ||
client.force_login(user) | ||
article = { | ||
"reception_date": "2023-07-11", | ||
"acceptance_date": "2023-07-11", | ||
"publication_date": "2023-07-11", | ||
"first_online_date": "2023-07-11", | ||
"title": "string", | ||
"subtitle": "string", | ||
"abstract": "string", | ||
"related_licenses": [license_id], | ||
"related_materials": [], | ||
"_files": [], | ||
"related_licenses": [license.id], | ||
} | ||
url = "http://localhost:8000/api/articles/" | ||
response = admin_user_token["client"].post( | ||
url, | ||
response = client.post( | ||
reverse("api:article-list"), | ||
data=article, | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {admin_user_token['user_token']}", | ||
) | ||
article_id = json.loads(response.content.decode("utf-8"))["id"] | ||
assert response.status_code == 201 | ||
opensearch_url = f"http://localhost:8000/search/article/{article_id}/" | ||
response = admin_user_token["client"].get( | ||
opensearch_url, | ||
data=article, | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {admin_user_token['user_token']}", | ||
) | ||
|
||
article_id = json.loads(response.content)["id"] | ||
article_detail_url = reverse("api:article-detail", kwargs={"pk": article_id}) | ||
|
||
response = client.get(article_detail_url) | ||
assert response.status_code == 200 | ||
url_delete_article = f"http://localhost:8000/api/articles/{article_id}/" | ||
response = admin_user_token["client"].delete( | ||
url_delete_article, | ||
data=article, | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {admin_user_token['user_token']}", | ||
) | ||
|
||
response = client.delete(article_detail_url) | ||
assert response.status_code == 204 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
|
||
class TestArticleViewSet: | ||
def test_get_article(self, api_client): | ||
def test_get_article(self, client): | ||
url = reverse("api:article-list") | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
|
||
class TestArticleIdentifierViewSet: | ||
def test_get_article_identifier(self, api_client): | ||
def test_get_article_identifier(self, client): | ||
url = reverse("api:articleidentifier-list") | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
url = reverse("api:articleidentifier-detail", kwargs={"pk": 0}) | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_404_NOT_FOUND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.authtoken.models import Token | ||
from rest_framework.test import APIClient | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
|
||
def test_search_article(user, api_client): | ||
user_token = Token.objects.create(user=user) | ||
response = api_client.get( | ||
"/search/article", | ||
content_type="application/json", | ||
HTTP_AUTHORIZATION=f"Token {user_token}", | ||
follow=True, | ||
) | ||
|
||
@pytest.mark.django_db | ||
@pytest.mark.usefixtures("rebuild_opensearch_index") | ||
def test_article_search(user, client): | ||
client.force_login(user) | ||
response = client.get(reverse("search:article-list")) | ||
assert response.status_code == status.HTTP_200_OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
|
||
class TestAuthorViewSet: | ||
def test_get_article(self, api_client): | ||
def test_get_article(self, client): | ||
url = reverse("api:author-list") | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
|
||
class TestAuthorIdentifierViewSet: | ||
def test_get_article_identifier(self, api_client): | ||
def test_get_article_identifier(self, client): | ||
url = reverse("api:authoridentifier-list") | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
url = reverse("api:authoridentifier-detail", kwargs={"pk": 0}) | ||
response = api_client.get(url) | ||
response = client.get(url) | ||
assert response.status_code == status.HTTP_404_NOT_FOUND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from factory import Faker | ||
from factory.django import DjangoModelFactory | ||
|
||
from scoap3.misc.models import License | ||
|
||
|
||
class LicenseFactory(DjangoModelFactory): | ||
url = Faker("url") | ||
name = Faker("domain_word") | ||
|
||
class Meta: | ||
model = License | ||
django_get_or_create = ["url"] |
Oops, something went wrong.