Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #27

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions tests/test_api/test_export.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
from django.contrib.auth.models import User
from django.test.client import Client
from django.urls import reverse

from rest_framework import status, test

import pytest

from import_export_extensions.models import ExportJob


@pytest.mark.django_db(transaction=True)
def test_export_api_creates_export_job(client: Client, superuser: User):
def test_export_api_creates_export_job(admin_api_client: test.APIClient):
"""Ensure export start API creates new export job."""
client.force_login(superuser)

response = client.post(
response = admin_api_client.post(
path=reverse("export-artist-start"),
data={
"file_format": "csv",
},
)
assert response.data["export_status"] == "CREATED"
assert ExportJob.objects.first()
assert response.status_code == status.HTTP_201_CREATED
assert response.data["export_status"] == ExportJob.ExportStatus.CREATED
assert ExportJob.objects.filter(id=response.data["id"]).exists()


@pytest.mark.django_db(transaction=True)
def test_export_api_detail(
client: Client,
admin_api_client: test.APIClient,
artist_export_job: ExportJob,
superuser: User,
):
"""Ensure export detail API shows current export job status."""
client.force_login(superuser)

response = client.get(
response = admin_api_client.get(
path=reverse(
"export-artist-detail",
kwargs={"pk": artist_export_job.id},
),
)

assert response.status_code == status.HTTP_200_OK
assert response.data["export_finished"]