Skip to content

Commit

Permalink
tests: add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed Apr 19, 2024
1 parent bfe6a4b commit 0c5d4a2
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework.test import APITestCase

from core import settings
from process.models import Collection, CollectionNote

base_url = f"/api/{settings.API_VERSION}/collections/"

Expand All @@ -18,6 +19,11 @@ def test_swagger_ui(self):

self.assertEqual(response.status_code, 200)

def test_redoc(self):
response = self.client.get("/api/schema/redoc/")

self.assertEqual(response.status_code, 200)

def test_collection_list_ok(self):
response = self.client.get(f"{base_url}?format=json")
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -45,11 +51,11 @@ def test_collection_metadata_ok(self):
},
)

def test_new_400(self):
def test_create_400(self):
response = self.client.post(f"{base_url}", {})
self.assertEqual(response.status_code, 400)

def test_new_ok(self):
def test_create_ok(self):
response = self.client.post(f"{base_url}", {"source_id": "test", "data_version": "2024-04-18 00:00:00"})
self.assertEqual(response.status_code, 200)

Expand All @@ -65,6 +71,54 @@ def test_new_ok(self):
response.content, {"collection_id": 5, "upgraded_collection_id": 6, "compiled_collection_id": 7}
)

def test_close_400(self):
def test_close_404(self):
response = self.client.post(f"{base_url}100/close/", {})
self.assertEqual(response.status_code, 404)

def test_close_ok(self):
response = self.client.post(f"{base_url}1/close/", {})
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 202)

def test_close_ok_full(self):
data = {"stats": {"kingfisher_process_expected_files_count": 1}, "reason": "finished"}

collection_id = 1

response = self.client.post(f"{base_url}{collection_id}/close/", data, format="json")
self.assertEqual(response.status_code, 202)

collection = Collection.objects.get(id=collection_id)
upgraded_collection = collection.get_upgraded_collection()

for c in [collection, upgraded_collection]:
self.assertEqual(c.expected_files_count, data["stats"]["kingfisher_process_expected_files_count"])
self.assertIsNotNone(c.store_end_at)

notes_reason = CollectionNote.objects.filter(
collection_id__in=[collection_id, upgraded_collection.id], note=f"Spider close reason: {data['reason']}"
)

self.assertEqual(len(notes_reason), 2)

notes_reason_stats = CollectionNote.objects.filter(
collection_id__in=[collection_id, upgraded_collection.id], note="Spider stats", data=data["stats"]
)

self.assertEqual(len(notes_reason_stats), 2)

def test_destroy_404(self):
response = self.client.delete(f"{base_url}100/")
self.assertEqual(response.status_code, 404)

def test_destroy_ok(self):
response = self.client.delete(f"{base_url}1/")
self.assertEqual(response.status_code, 202)

def test_retrieve_404(self):
response = self.client.get(f"{base_url}tree/2/")
self.assertEqual(response.status_code, 404)

def test_retrieve_ok(self):
response = self.client.get(f"/api/{settings.API_VERSION}/tree/1/")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 3)

0 comments on commit 0c5d4a2

Please sign in to comment.