Files
penracourses/generic/tests/test_exam_collection.py
T
2024-02-26 22:30:36 +00:00

35 lines
1.3 KiB
Python

from django.test import TestCase
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:examcollection_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:examcollection_detail", args=( 1, )))
assert response.status_code == 404
collection = ExamCollection.objects.create(name="test collection", date=datetime.date.today())
response = client.get(reverse("generic:examcollection_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:examcollection_detail", args=( collection.pk, )))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert collection.name in soup.find("h1").text