.
This commit is contained in:
+71
-18
@@ -21,9 +21,10 @@ from generic.models import CidUser, CidUserGroup
|
|||||||
|
|
||||||
APP_NAME = "anatomy"
|
APP_NAME = "anatomy"
|
||||||
|
|
||||||
|
|
||||||
def create_cid_user_and_groups(db):
|
def create_cid_user_and_groups(db):
|
||||||
group1 = CidUserGroup.objects.create(name="Group1")
|
group1 = CidUserGroup.objects.create(name="Group1")
|
||||||
group2= CidUserGroup.objects.create(name="Group2")
|
group2 = CidUserGroup.objects.create(name="Group2")
|
||||||
|
|
||||||
cid_user_1000 = CidUser.objects.create(cid=1000, passcode="ABCD", group=group1)
|
cid_user_1000 = CidUser.objects.create(cid=1000, passcode="ABCD", group=group1)
|
||||||
cid_user_1001 = CidUser.objects.create(cid=1001, passcode="EFGH", group=group1)
|
cid_user_1001 = CidUser.objects.create(cid=1001, passcode="EFGH", group=group1)
|
||||||
@@ -33,10 +34,10 @@ def create_cid_user_and_groups(db):
|
|||||||
assert cid_user_1001.cid == 1001
|
assert cid_user_1001.cid == 1001
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_exam(db):
|
def create_exam(db):
|
||||||
exam: Exam = AnatomyExamViews.Exam.objects.create(name="Cid Exam", exam_mode=True, active=True)
|
exam: Exam = AnatomyExamViews.Exam.objects.create(
|
||||||
|
name="Cid Exam", exam_mode=True, active=True
|
||||||
|
)
|
||||||
|
|
||||||
group1: CidUserGroup = CidUserGroup.objects.get(name="Group1")
|
group1: CidUserGroup = CidUserGroup.objects.get(name="Group1")
|
||||||
|
|
||||||
@@ -50,12 +51,14 @@ def create_exam(db):
|
|||||||
|
|
||||||
return exam
|
return exam
|
||||||
|
|
||||||
|
|
||||||
def create_structures(db):
|
def create_structures(db):
|
||||||
structure = Structure.objects.create(structure="test structure")
|
structure = Structure.objects.create(structure="test structure")
|
||||||
structure.save()
|
structure.save()
|
||||||
structure = Structure.objects.create(structure="test structure 2")
|
structure = Structure.objects.create(structure="test structure 2")
|
||||||
structure.save()
|
structure.save()
|
||||||
|
|
||||||
|
|
||||||
def create_question_types(db):
|
def create_question_types(db):
|
||||||
question_type = QuestionType.objects.create(text="test question type")
|
question_type = QuestionType.objects.create(text="test question type")
|
||||||
question_type.save()
|
question_type.save()
|
||||||
@@ -66,17 +69,20 @@ def create_question_types(db):
|
|||||||
def create_question(exam):
|
def create_question(exam):
|
||||||
# Just assign random stuff
|
# Just assign random stuff
|
||||||
|
|
||||||
image = tempfile.NamedTemporaryFile(dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False)
|
image = tempfile.NamedTemporaryFile(
|
||||||
|
dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False
|
||||||
|
)
|
||||||
|
|
||||||
print(image.name)
|
|
||||||
print(image.file)
|
|
||||||
|
|
||||||
print(os.listdir(settings.MEDIA_ROOT))
|
question: Question = Question.objects.create(
|
||||||
|
question_type=QuestionType.objects.first(),
|
||||||
question: Question = Question.objects.create(question_type=QuestionType.objects.first(), structure=Structure.objects.first(), image=image.name)
|
structure=Structure.objects.first(),
|
||||||
|
image=image.name,
|
||||||
|
)
|
||||||
question.exams.set([exam])
|
question.exams.set([exam])
|
||||||
return question
|
return question
|
||||||
|
|
||||||
|
|
||||||
def test_exams(db, client):
|
def test_exams(db, client):
|
||||||
create_cid_user_and_groups(db)
|
create_cid_user_and_groups(db)
|
||||||
exam = create_exam(db)
|
exam = create_exam(db)
|
||||||
@@ -96,22 +102,33 @@ def test_exams(db, client):
|
|||||||
|
|
||||||
for cid_user in [cid_user_1001]:
|
for cid_user in [cid_user_1001]:
|
||||||
# Test active exams sections works as intended
|
# Test active exams sections works as intended
|
||||||
active_exams_cid = client.get(reverse(f"active_exams_cid", kwargs={"cid":cid_user.cid, "passcode":cid_user.passcode}))
|
active_exams_cid = client.get(
|
||||||
|
reverse(
|
||||||
|
f"active_exams_cid",
|
||||||
|
kwargs={"cid": cid_user.cid, "passcode": cid_user.passcode},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
assert active_exams_cid.status_code == 200
|
assert active_exams_cid.status_code == 200
|
||||||
assert len(json.loads(active_exams_cid.content)["exams"]) == 1
|
assert len(json.loads(active_exams_cid.content)["exams"]) == 1
|
||||||
|
|
||||||
active_exams_cid = client.get(reverse(f"active_exams_cid", kwargs={"cid":1001, "passcode":"EFGH"}))
|
active_exams_cid = client.get(
|
||||||
|
reverse(f"active_exams_cid", kwargs={"cid": 1001, "passcode": "EFGH"})
|
||||||
|
)
|
||||||
|
|
||||||
assert active_exams_cid.status_code == 200
|
assert active_exams_cid.status_code == 200
|
||||||
assert len(json.loads(active_exams_cid.content)["exams"]) == 1
|
assert len(json.loads(active_exams_cid.content)["exams"]) == 1
|
||||||
|
|
||||||
no_active_exams_cid = client.get(reverse(f"active_exams_cid", kwargs={"cid":2001, "passcode":"EGFH"}))
|
no_active_exams_cid = client.get(
|
||||||
|
reverse(f"active_exams_cid", kwargs={"cid": 2001, "passcode": "EGFH"})
|
||||||
|
)
|
||||||
|
|
||||||
assert no_active_exams_cid.status_code == 401
|
assert no_active_exams_cid.status_code == 401
|
||||||
assert json.loads(no_active_exams_cid.content)["status"] == "invalid"
|
assert json.loads(no_active_exams_cid.content)["status"] == "invalid"
|
||||||
|
|
||||||
invalid_passcode = client.get(reverse(f"active_exams_cid", kwargs={"cid":1001, "passcode":"ABCD"}))
|
invalid_passcode = client.get(
|
||||||
|
reverse(f"active_exams_cid", kwargs={"cid": 1001, "passcode": "ABCD"})
|
||||||
|
)
|
||||||
assert invalid_passcode.status_code == 401
|
assert invalid_passcode.status_code == 401
|
||||||
assert json.loads(invalid_passcode.content)["status"] == "invalid"
|
assert json.loads(invalid_passcode.content)["status"] == "invalid"
|
||||||
|
|
||||||
@@ -124,12 +141,48 @@ def test_exams(db, client):
|
|||||||
res = client.get(exam_metadata["url"])
|
res = client.get(exam_metadata["url"])
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
exam_json = json.loads(res.content)
|
exam_json = json.loads(res.content)
|
||||||
print("---", exam_json["questions"].values())
|
|
||||||
|
|
||||||
|
|
||||||
assert question1.get_question_json(answers=False) in exam_json["questions"].values()
|
|
||||||
|
|
||||||
|
assert (
|
||||||
|
question1.get_question_json(answers=False)
|
||||||
|
in exam_json["questions"].values()
|
||||||
|
)
|
||||||
|
|
||||||
assert len(exam_json["questions"]) == 3
|
assert len(exam_json["questions"]) == 3
|
||||||
|
|
||||||
|
exam.active = False
|
||||||
|
exam.save()
|
||||||
|
|
||||||
|
res = client.get(exam_metadata["url"])
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
exam.active = True
|
||||||
|
exam.save()
|
||||||
|
|
||||||
|
post_json = {
|
||||||
|
"eid": f"anatomy/{exam.pk}",
|
||||||
|
"cid": cid_user_1001.cid,
|
||||||
|
"start_time": "1659618141.731",
|
||||||
|
"answers": [[]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test submission
|
||||||
|
# Start with 0 answers
|
||||||
|
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
|
||||||
|
|
||||||
|
print(res.status_code)
|
||||||
|
json_res = json.loads(res.content)
|
||||||
|
|
||||||
|
assert json_res["success"] == True
|
||||||
|
assert json_res["question_count"] == 0
|
||||||
|
|
||||||
|
post_json = {
|
||||||
|
"eid": f"anatomy/{exam.pk+10}",
|
||||||
|
"cid": cid_user_1001.cid,
|
||||||
|
"start_time": "1659618141.731",
|
||||||
|
"answers": [[]]
|
||||||
|
}
|
||||||
|
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
|
||||||
|
json_res = json.loads(res.content)
|
||||||
|
assert json_res["success"] == False
|
||||||
|
|
||||||
|
# Test that we ca
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<a href="{% url 'generic:cid_group_create' %}">Create new group</a>
|
<a href="{% url 'generic:cid_group_create' %}">Create new group</a>
|
||||||
</p>
|
</p>
|
||||||
{% for group in groups %}
|
{% for group in groups %}
|
||||||
<p>{{group.name}}
|
<p><a href="{% url 'generic:cid_group_detail' group.pk %}">{{group.name}}</a>
|
||||||
<button class="small-url-button" data-url="{% url 'generic:group_email' pk=group.pk %}
|
<button class="small-url-button" data-url="{% url 'generic:group_email' pk=group.pk %}
|
||||||
">Email candidate details</button>
|
">Email candidate details</button>
|
||||||
<button class="small-url-button" data-url="{% url 'generic:group_email_resend' pk=group.pk %}
|
<button class="small-url-button" data-url="{% url 'generic:group_email_resend' pk=group.pk %}
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
{% extends 'generic/base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Group: {{group.name}}</h2>
|
||||||
|
<ul>
|
||||||
|
{% for user in users %}
|
||||||
|
<li>{{user.email}} / CID: {{user.cid}} / Passcode: {{user.passcode}}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr><th>Email</th><th>CID</th><th>Passcode</th></tr>
|
||||||
|
</thead>
|
||||||
|
{% for user in users %}
|
||||||
|
<tr><td>{{user.email}}</td><td>{{user.cid}}</td><td>{{user.passcode}}</td></tr>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
td, th { padding-left: 10px }
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
@@ -43,6 +43,7 @@ urlpatterns = [
|
|||||||
path("cids/manage/exams", views.CidUserExamView.as_view(), name="manage_cid_exams"),
|
path("cids/manage/exams", views.CidUserExamView.as_view(), name="manage_cid_exams"),
|
||||||
path("cids/group/", views.cid_group_view, name="cid_group_view"),
|
path("cids/group/", views.cid_group_view, name="cid_group_view"),
|
||||||
path("cids/group/all", views.cid_group_view_all, name="cid_group_view_all"),
|
path("cids/group/all", views.cid_group_view_all, name="cid_group_view_all"),
|
||||||
|
path("cids/group/<int:group_id>/", views.cid_group_view_detail, name="cid_group_detail"),
|
||||||
path("cids/group/<int:pk>/email", views.group_email, name="group_email"),
|
path("cids/group/<int:pk>/email", views.group_email, name="group_email"),
|
||||||
path(
|
path(
|
||||||
"cids/group/<int:pk>/email_results",
|
"cids/group/<int:pk>/email_results",
|
||||||
|
|||||||
@@ -2086,6 +2086,17 @@ def cid_group_view(request):
|
|||||||
{"groups": groups},
|
{"groups": groups},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@user_is_cid_user_manager
|
||||||
|
def cid_group_view_detail(request, group_id):
|
||||||
|
group = get_object_or_404(CidUserGroup, pk=group_id)
|
||||||
|
|
||||||
|
users = group.ciduser_set.filter(active=True)
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"generic/cid_group_view_detail.html",
|
||||||
|
{"group": group, "users": users},
|
||||||
|
)
|
||||||
|
|
||||||
@user_is_cid_user_manager
|
@user_is_cid_user_manager
|
||||||
def cid_group_view_all(request):
|
def cid_group_view_all(request):
|
||||||
|
|||||||
+5
-1
@@ -2,7 +2,7 @@ import secrets
|
|||||||
from atlas.models import CaseCollection, CidReportAnswer
|
from atlas.models import CaseCollection, CidReportAnswer
|
||||||
from generic.decorators import user_is_cid_user_manager
|
from generic.decorators import user_is_cid_user_manager
|
||||||
from generic.views import CidManagerRequiredMixin, get_question_and_content_type
|
from generic.views import CidManagerRequiredMixin, get_question_and_content_type
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django import forms
|
from django import forms
|
||||||
@@ -279,8 +279,10 @@ def active_exams_unbased(request, cid=None, passcode=None):
|
|||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def exam_submit(request):
|
def exam_submit(request):
|
||||||
if request.is_ajax and request.method == "POST":
|
if request.is_ajax and request.method == "POST":
|
||||||
|
print(request.POST)
|
||||||
exam_type, exam_id = request.POST.get("eid").split("/")
|
exam_type, exam_id = request.POST.get("eid").split("/")
|
||||||
|
|
||||||
|
try:
|
||||||
if exam_type == "anatomy":
|
if exam_type == "anatomy":
|
||||||
return AnatomyExamViews.postExamAnswers(request)
|
return AnatomyExamViews.postExamAnswers(request)
|
||||||
elif exam_type == "rapid":
|
elif exam_type == "rapid":
|
||||||
@@ -288,6 +290,8 @@ def exam_submit(request):
|
|||||||
elif exam_type == "long":
|
elif exam_type == "long":
|
||||||
return LongsExamViews.postExamAnswers(request)
|
return LongsExamViews.postExamAnswers(request)
|
||||||
return JsonResponse({"success": False, "error": "Invalid exam type"})
|
return JsonResponse({"success": False, "error": "Invalid exam type"})
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||||
|
|
||||||
# postExamAnswers
|
# postExamAnswers
|
||||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||||
|
|||||||
Reference in New Issue
Block a user