add some tests and views

This commit is contained in:
Ross
2024-01-29 10:52:02 +00:00
parent 04dcb74e67
commit cfb90be686
11 changed files with 142 additions and 6 deletions
+33 -1
View File
@@ -1,3 +1,35 @@
from django.test import TestCase
# Create your tests here.
import pytest
from django.urls import reverse
from bs4 import BeautifulSoup
from generic.models import ExamCollection
import datetime
class TestExamCollections:
def test_list_url(self, db, client):
# Test with no content
response = client.get(reverse("generic:exam_collection_list"))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert "No exam collections yet" in soup.text
# No content yet so this should fail
response = client.get(reverse("generic:exam_collection_detail", args=( 1, )))
assert response.status_code == 404
collection = ExamCollection.objects.create(name="test collection", date=datetime.date.today())
response = client.get(reverse("generic:exam_collection_list"))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert collection.name in soup.find("li", class_="collection").text
response = client.get(reverse("generic:exam_collection_detail", args=( collection.pk, )))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert collection.name in soup.find("h1").text