add some tests and views
This commit is contained in:
+3
-1
@@ -17,6 +17,7 @@ from .models import (
|
||||
UserGrades,
|
||||
UserProfile,
|
||||
Supervisor,
|
||||
ExamCollection,
|
||||
Site
|
||||
)
|
||||
|
||||
@@ -37,4 +38,5 @@ admin.site.register(CidUserGroup)
|
||||
admin.site.register(UserProfile)
|
||||
admin.site.register(UserGrades)
|
||||
admin.site.register(Supervisor)
|
||||
admin.site.register(Modality)
|
||||
admin.site.register(Modality)
|
||||
admin.site.register(ExamCollection)
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.1.4 on 2024-01-29 10:11
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('generic', '0011_examcollection'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='examcollection',
|
||||
name='author',
|
||||
field=models.ManyToManyField(blank=True, help_text='Author/Manager(s) of the exam collection', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
@@ -1523,3 +1523,23 @@ class ExamCollection(models.Model):
|
||||
|
||||
date = models.DateField(blank=True,null=True)
|
||||
|
||||
author = models.ManyToManyField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
blank=True,
|
||||
help_text="Author/Manager(s) of the exam collection",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} [{self.date}]"
|
||||
|
||||
def get_author_objects(self):
|
||||
"""Returns a comma seperated text list of authors"""
|
||||
authors = [i for i in self.author.all()]
|
||||
return authors
|
||||
|
||||
def get_authors(self):
|
||||
"""Returns a comma seperated text list of authors"""
|
||||
authors = ", ".join([i.username for i in self.author.all()])
|
||||
if not authors:
|
||||
return "None"
|
||||
return authors
|
||||
@@ -22,7 +22,8 @@
|
||||
<a href="{% url 'generic:cid_group_view' %}">Cid Groups</a> /
|
||||
<a href="{% url 'generic:user_group_view' %}">User Groups</a> /
|
||||
<a href="{% url 'accounts_list' %}">Manage Users</a> /
|
||||
<a href="{% url 'generic:supervisor' %}">Manage Supervisors</a>
|
||||
<a href="{% url 'generic:supervisor' %}">Manage Supervisors</a> /
|
||||
<a href="{% url 'generic:exam_collection_list' %}">Collections</a>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{% extends 'generic/base.html' %}
|
||||
|
||||
|
||||
{% block navigation %}
|
||||
{{block.super}}
|
||||
<br/>Test
|
||||
{% comment %} <a href="{% url 'generic:cid_group_detail' cidusergroup.pk %}">Collections</a> / {% endcomment %}
|
||||
|
||||
{% endblock %}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{% extends 'generic/examcollection_base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{{ object.name }} [{{object.date}}] </h1>
|
||||
|
||||
{{object.anatomy_exams}}
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
|
||||
{% endblock %}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
{% extends 'generic/examcollection_base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>Exam Collections</h1>
|
||||
<ul class="collections">
|
||||
{% for collection in object_list %}
|
||||
<li class="collection"><a href="{% url 'generic:exam_collection_detail' collection.pk %}">{{ collection.name }} [{{ collection.date}}] (Authors: {{ collection.get_authors }})</a></li>
|
||||
{% empty %}
|
||||
<li>No exam collections yet.</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
|
||||
{% endblock %}
|
||||
+33
-1
@@ -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
|
||||
@@ -162,6 +162,16 @@ urlpatterns = [
|
||||
views.SupervisorDelete.as_view(),
|
||||
name="supervisor_delete",
|
||||
),
|
||||
path(
|
||||
"exam_collection/",
|
||||
views.ExamCollectionList.as_view(),
|
||||
name="exam_collection_list",
|
||||
),
|
||||
path(
|
||||
"exam_collection/<int:pk>/",
|
||||
views.ExamCollectionDetail.as_view(),
|
||||
name="exam_collection_detail",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ from .models import (
|
||||
CidUser,
|
||||
CidUserGroup,
|
||||
ExamBase,
|
||||
ExamCollection,
|
||||
ExamUserStatus,
|
||||
Examination,
|
||||
QuestionNote,
|
||||
@@ -3255,6 +3256,11 @@ class SupervisorCreate(CidManagerRequiredMixin, CreateView):
|
||||
class SupervisorList(CidManagerRequiredMixin, ListView):
|
||||
model = Supervisor
|
||||
|
||||
class ExamCollectionList(ListView):
|
||||
model = ExamCollection
|
||||
|
||||
class ExamCollectionDetail(DetailView, AuthorRequiredMixin):
|
||||
model = ExamCollection
|
||||
|
||||
class ExaminationView(SuperuserRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = Examination
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import json
|
||||
import pytest
|
||||
|
||||
# from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
|
||||
from rich.pretty import pprint
|
||||
@@ -361,4 +359,7 @@ def test_cookies(db, client):
|
||||
|
||||
# Check our 2 cookies are displayed (we would have to add them for this to work)
|
||||
#assert "csrftoken" in [i.text for i in soup.find_all("th")]
|
||||
#assert "sessionid" in [i.text for i in soup.find_all("th")]
|
||||
#assert "sessionid" in [i.text for i in soup.find_all("th")]
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user