fix a load of test

This commit is contained in:
Ross
2023-11-27 12:08:45 +00:00
parent 95c136d3f3
commit 5cc57587aa
16 changed files with 209 additions and 67 deletions
+2 -2
View File
@@ -300,11 +300,11 @@ def test_exams(db, client):
search_exam = (
cid_scores_soup.find("div", {"id": "exam-assigned"})
.find("ul", {"class": exam.app_name})
.find_all("li", attrs={"data-exam-id": exam.pk})
.find("li", attrs={"data-exam-id": exam.pk})
)
assert search_exam
assert exam.name in str(search_exam)
assert "Active" in str(search_exam)
assert len(search_exam.find("button", {"class": "start-button"})) > 0
# assert "Active" in assigned_exams # check it is active
invalid_exam = cid_scores_soup.find_all(
+19 -14
View File
@@ -3,28 +3,33 @@
{% block navigation %}
{{block.super}}
<br/>
Group: {{group.name}}->
{% if group_type == "cid" %}
<br/>
Group: {{group.name}}->
{% if not group %}
<a href="{% url 'generic:cid_group_detail' cidusergroup.pk %}">Group</a> /
<a href="{% url 'generic:cid_group_update' cidusergroup.pk %}">Edit Users</a> /
<a href="{% url 'generic:cid_group_exams' cidusergroup.pk %}">Edit Exams</a> /
<a href="{% url 'generic:cid_group_delete' cidusergroup.pk %}">Delete</a>
<a href="{% url 'generic:cid_group_detail' cidusergroup.pk %}">Group</a> /
<a href="{% url 'generic:cid_group_update' cidusergroup.pk %}">Edit Users</a> /
<a href="{% url 'generic:cid_group_exams' cidusergroup.pk %}">Edit Exams</a> /
<a href="{% url 'generic:cid_group_delete' cidusergroup.pk %}">Delete</a>
{% else %}
<a href="{% url 'generic:cid_group_detail' group.pk %}">Group</a> /
<a href="{% url 'generic:cid_group_update' group.pk %}">Edit Users</a> /
<a href="{% url 'generic:cid_group_exams' group.pk %}">Edit Exams</a> /
<a href="{% url 'generic:cid_group_delete' group.pk %}">Delete</a>
<a href="{% url 'generic:cid_group_detail' group.pk %}">Group</a> /
<a href="{% url 'generic:cid_group_update' group.pk %}">Edit Users</a> /
<a href="{% url 'generic:cid_group_exams' group.pk %}">Edit Exams</a> /
<a href="{% url 'generic:cid_group_delete' group.pk %}">Delete</a>
{% endif %}
{% else %}
<a href="{% url 'generic:user_group_detail' group.pk %}">Group</a> /
<a href="{% url 'generic:user_group_update' group.pk %}">Edit Users</a> /
<a href="{% url 'generic:user_group_exams' group.pk %}">Edit Exams</a> /
<a href="{% url 'generic:user_group_delete' group.pk %}">Delete</a>
{% if group %}
<br/>
Group: {{group.name}}->
<a href="{% url 'generic:user_group_detail' group.pk %}">Group</a> /
<a href="{% url 'generic:user_group_update' group.pk %}">Edit Users</a> /
<a href="{% url 'generic:user_group_exams' group.pk %}">Edit Exams</a> /
<a href="{% url 'generic:user_group_delete' group.pk %}">Delete</a>
{% endif %}
{% endif %}
{% endblock %}
@@ -5,10 +5,10 @@
{% endblock %}
{% block js %}
<!--<script type="text/javascript" src="/admin/jsi18n/"></script>-->
{{form.media}}
{{form.media}}
<script type="text/javascript">
</script>
<script type="text/javascript">
</script>
<!-- {{ form.media }} -->
{% endblock %}
@@ -20,28 +20,31 @@
<h2>Add New Group</h2>
Use this form to create a CID user group.
{% endif %}
<form action="" method="post" enctype="multipart/form-data" id="condition-form">
{% csrf_token %}
<form action="" method="post" enctype="multipart/form-data" id="condition-form">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" class="submit-button" value="Submit" name="submit">
<table>
{{ form.as_table }}
</table>
<input type="submit" class="submit-button" value="Submit" name="submit">
<p>Users can be added to the group <a href="{% url 'generic:manage_cids' %}">here</a></p>
<h3>Users</h3>
{% if cidusergroup %}
<p>Users can be added to the group <a href="{% url 'generic:manage_cids' %}">here</a></p>
<ul>
{% for user in cidusergroup.ciduser_set.all %}
<li><a href="{% url 'generic:update_cid' user.pk %}">{{user.cid}}</a>: {{user.name}} [{{user.email}} {{user.last_name}}] {{user.userprofile.grade}}</li>
<h3>Users</h3>
{% empty %}
<li>Group currently has no users.</li>
{% endfor %}
</ul>
Count: {{cidusergroup.ciduser_set.count}}
<ul>
{% for user in cidusergroup.ciduser_set.all %}
<li><a href="{% url 'generic:update_cid' user.pk %}">{{user.cid}}</a>: {{user.name}} [{{user.email}} {{user.last_name}}] {{user.userprofile.grade}}</li>
</form>
{% empty %}
<li>Group currently has no users.</li>
{% endfor %}
</ul>
Count: {{cidusergroup.ciduser_set.count}}
{% endif %}
</form>
{% endblock %}
+3 -1
View File
@@ -44,6 +44,7 @@ def test_trainee_stuff(client, create_cid_manager, create_users):
print(UserProfile.objects.all().count())
assert UserProfile.objects.all().count() == 5
print(UserProfile.objects.filter(peninsula_trainee=True))
assert UserProfile.objects.filter(peninsula_trainee=True).count() == 4
response = client.get(reverse(f"trainees"))
@@ -59,9 +60,10 @@ def test_trainee_stuff(client, create_cid_manager, create_users):
response = client.get(reverse(f"trainees"))
assert response.status_code == 200
trainee_rows = BeautifulSoup(response.content, "html.parser").find(
trainee_rows = BeautifulSoup(response.content, "html.parser").find_all(
"tr", {"class": "trainee"}
)
print(trainee_rows)
assert (
len(trainee_rows) == UserProfile.objects.filter(peninsula_trainee=True).count()
+2 -2
View File
@@ -442,11 +442,11 @@ def test_exams(db, client):
search_exam = (
cid_scores_soup.find("div", {"id": "exam-assigned"})
.find("ul", {"class": exam.app_name})
.find_all("li", attrs={"data-exam-id": exam.pk})
.find("li", attrs={"data-exam-id": exam.pk})
)
assert search_exam
assert exam.name in str(search_exam)
assert "Active" in str(search_exam)
assert len(search_exam.find("button", {"class": "start-button"})) > 0
# assert "Active" in assigned_exams # check it is active
invalid_exam = cid_scores_soup.find_all(
+2 -2
View File
@@ -1057,7 +1057,7 @@ table .peninsula-trainee::before {
user-select: none;
}
.form-control {
.form-control, .form-control:focus, .form-control option {
background-color: unset;
color: unset
}
}
+2 -2
View File
@@ -340,11 +340,11 @@ class ExamTester:
search_exam = (
cid_scores_soup.find("div", {"id": "exam-assigned"})
.find("ul", {"class": self.exam.app_name.lower()})
.find_all("li", attrs={"data-exam-id": self.exam.pk})
.find("li", attrs={"data-exam-id": self.exam.pk})
)
assert search_exam
assert self.exam.name in str(search_exam)
assert "Active" in str(search_exam)
assert len(search_exam.find("button", {"class": "start-button"})) > 0
# assert "Active" in assigned_exams # check it is active
invalid_exam = cid_scores_soup.find_all(
+91
View File
@@ -0,0 +1,91 @@
from django.urls import reverse
from rich.pretty import pprint
from bs4 import BeautifulSoup
from django.contrib.auth.models import Group
import pytest
@pytest.fixture
def create_users(db, django_user_model):
user1 = django_user_model.objects.create_user(
"user1", "user1@user.com", "password"
)
user2 = django_user_model.objects.create_user(
"user2", "user2@user.com", "password"
)
#g = Group.objects.create(name="cid_user_manager")
#g.save()
#user.groups.add(g)
return user1, user2
@pytest.fixture
def create_cid_manager(db, django_user_model):
user = django_user_model.objects.create_user(
"cid_user", "cid@user.com", "password1234"
)
g = Group.objects.create(name="cid_user_manager")
g.save()
user.groups.add(g)
return user
def test_profile_access_and_management(db, client, create_users, create_cid_manager):
response = client.get(reverse(f"profile"))
# should redirect to login page
assert response.status_code == 302
assert "accounts/login/" in response.url
# Test login
client.login(username="user1", password="password")
response = client.get(reverse(f"profile"))
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert soup.find(id="username").text == "user1"
assert soup.find(id="email").text == "user1@user.com"
# Check the links to change password and update profile
password_url = soup.find(id="password-change")["href"]
print(password_url)
password_change_response = client.get(password_url)
assert password_change_response.status_code == 200
password_soup = BeautifulSoup(password_change_response.content, "html.parser")
assert "Old password" in password_soup.text
assert "New password" in password_soup.text
update_profile = soup.find(id="update-profile-link")["href"]
assert update_profile == reverse("account_profile_update", kwargs={"slug": "user1"})
# check we can't access another users profile
response_fail = client.get(reverse("account_profile_update", kwargs={"slug": "user2"}))
assert response_fail.status_code == 404
print(response_fail.content)
# And that we can access our own
update_profile_response = client.get(reverse("account_profile_update", kwargs={"slug": "user1"}))
assert update_profile_response.status_code == 200
assert "peninsula_trainee" not in BeautifulSoup(update_profile_response.content, "html.parser").text
update_response = client.post(reverse("account_profile_update", kwargs={"slug": "user1"}), {
"registration_number": 1234567
})
assert update_response.status_code == 302
# we reirect back to profile page on form submission
assert update_response.url == reverse("profile")
# check that the form has updated
update_profile_response = client.get(reverse("account_profile_update", kwargs={"slug": "user1"}))
assert BeautifulSoup(update_profile_response.content, "html.parser").find(id="id_registration_number")["value"]
+10 -3
View File
@@ -636,6 +636,8 @@ class UpdateUserProfileView(UpdateView):
if request.user.is_superuser or request.user.groups.filter(name="cid_user_manager").exists():
self.fields = ["supervisor", "grade", "registration_number", "peninsula_trainee"]
# Check permissions for the request.user here
elif request.user != self.get_object().user:
raise Http404
elif request.user.userprofile.peninsula_trainee:
self.fields = ["supervisor", "grade", "registration_number"]
@@ -645,9 +647,14 @@ class UpdateUserProfileView(UpdateView):
def get_success_url(self):
view_name = "account_profile"
# No need for reverse_lazy here, because it's called inside the method
return reverse(view_name, kwargs={"slug": self.object.username})
if self.request.user.is_superuser or self.request.user.groups.filter(name="cid_user_manager").exists():
view_name = "account_profile"
# No need for reverse_lazy here, because it's called inside the method
return reverse(view_name, kwargs={"slug": self.object.username})
else:
return reverse("profile")
# class UpdateUser(TemplateView):
#
+2 -2
View File
@@ -332,11 +332,11 @@ def test_exams(db, client):
search_exam = (
cid_scores_soup.find("div", {"id": "exam-assigned"})
.find("ul", {"class": exam.app_name})
.find_all("li", attrs={"data-exam-id": exam.pk})
.find("li", attrs={"data-exam-id": exam.pk})
)
assert search_exam
assert exam.name in str(search_exam)
assert "Active" in str(search_exam)
assert len(search_exam.find("button", {"class": "start-button"})) > 0
# assert "Active" in assigned_exams # check it is active
invalid_exam = cid_scores_soup.find_all(
+5 -1
View File
@@ -241,7 +241,10 @@ def test_cid_management(client, create_cid_manager, django_user_model):
for url in urls:
response = client.get(url)
assert response.status_code == 403
if response.status_code == 302:
assert "accounts/login/" in response.url
else:
assert response.status_code == 403
pass
@@ -250,6 +253,7 @@ def test_cid_management(client, create_cid_manager, django_user_model):
client.force_login(cid_manager)
for url in urls:
print(url)
response = client.get(url)
assert response.status_code == 200
+2 -2
View File
@@ -26,8 +26,8 @@
<table>
<tr><th>First name</th><th>Last name</th><th>Email</th><th>Grade</th><th>Supervisor</th><th>Supervisor email</th></tr>
<tr><td>name 1</td><td>last name 1</td><td>email1@email.com</td><td>grade 1</td><td>supervisor 1</td><td>Supervisor@email.com</td></tr>
<tr><td>name 2</td><td>last name 2</td><td>email2@email.com</td><td>grade 2</td><td>supervisor 2</td><td>Supervisor2@email.com</td></tr>
<tr><td>name 1</td><td>last name 1</td><td>email1@email.com</td><td>ST1</td><td>supervisor 1</td><td>Supervisor@email.com</td></tr>
<tr><td>name 2</td><td>last name 2</td><td>email2@email.com</td><td>ST2</td><td>supervisor 2</td><td>Supervisor2@email.com</td></tr>
</table>
+28 -6
View File
@@ -3,16 +3,38 @@
{% block content %}
<div class="">
<h2>CID: {{ cid }}</h2>
<div class="alert alert-dark" role="alert">
<details>
<summary>Help</summary>
<p>This page shows the exam(s) to which you have access.</p>
<p>When an exam is available to take it will have a "Start" button next to it.</p>
<p>Once you have submitted answers you will be able to view them from the Exam results section. (Please note: although your answers will be visible as soon as they are submitted, correct answers will only be available when the exam results have been published.)</p>
<p>If you have not submitted any answer for an exam it will not appear in the Exam Results section below. In this case you can still review the pubilshed results by following the "Results Published" link in the assigend exams section.</p>
</details>
</div>
<h3>Assigned exams</h3>
<div id="exam-assigned">
The following exams will be available to take when active.
{% for exam_type, exams in available_exams %}
<h4>{{exam_type|title}}</h4>
<ul class='{{exam_type|lower}}'>
{% for exam in exams %}
<li class="exam" data-exam-id="{{exam.pk}}"><a href="{{exam.get_take_url}}?cid={{cid}}&passcode={{passcode}}" target="_blank">{{exam.name}} {% if exam.active %}[Active]{% endif %}</a></li>
{% endfor %}
</ul>
{% if exams %}
<h4>{{exam_type|title}}</h4>
<ul class='{{exam_type|lower}}'>
{% for exam in exams %}
<li class="exam" data-exam-id="{{exam.pk}}">{{exam.name}}
{% if exam.active %}
<a href="{{exam.get_take_url}}?cid={{cid}}&passcode={{passcode}}" target="_blank" title="Click to take exam">
<button class="small-url-button start-button">Start</button>
</a>
{% endif %}
{% if exam.publish_results %}
<a href= "{% url exam_type|add:':exam_scores_cid_user' pk=exam.pk cid=cid passcode=passcode %}" title="Click to view results">
<button class="small-url-button results-button">Results Published</button>
</a>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</div>
+6 -6
View File
@@ -5,14 +5,14 @@
<div class="anatomy">
<h1>Profile</h1>
<div>
Username: {{ user.username }}
Username: <span id="username">{{ user.username }}</span>
</div>
<div>
Email: {{ user.email }}
Email: <span id="email">{{ user.email }}</span>
</div>
<div>
Name: {{ user.first_name }}
{{ user.last_name }}
Name: <span id="first-name">{{ user.first_name }}<span>
<span id="last-name">{{ user.last_name }}</span>
</div>
<div>
Grade: {{ user.userprofile.grade }}
@@ -54,11 +54,11 @@
</p>
<a href="{% url 'password_change'%}">Change password</a>
<a id="password-change" href="{% url 'password_change'%}">Change password</a>
{% if request.user|has_group:"cid_user_manager" %}
<a href="{% url 'account_update' user.username %}">Update user details</a>
{% endif %}
<a href="{% url 'account_profile_update' user.username %}">Update user profile</a>
<a id="update-profile-link" href="{% url 'account_profile_update' user.username %}">Update user profile</a>
</div>
{% endblock %}
+10 -2
View File
@@ -21,8 +21,16 @@
<ul class='{{exam_type|lower}}'>
{% for exam in exams %}
<li class="exam" data-exam-id="{{exam.pk}}">{{exam.name}}
{% if exam.active %}<a href="{{exam.get_take_url}}" target="_blank" title="Click to take exam"><button class="small-url-button">Start</button></a>{% endif %}
{% if exam.publish_results %}<a href= "{% url exam_type|lower|add:':exam_scores_user' pk=exam.pk %}" title="Click to view results"><button class="small-url-button">Results Published</button></a>{% endif %}
{% if exam.active %}
<a href="{{exam.get_take_url}}" target="_blank" title="Click to take exam">
<button class="small-url-button start-button">Start</button>
</a>
{% endif %}
{% if exam.publish_results %}
<a href= "{% url exam_type|lower|add:':exam_scores_user' pk=exam.pk %}" title="Click to view results">
<button class="small-url-button results-button">Results Published</button>
</a>
{% endif %}
</li>
{% endfor %}
</ul>
+1 -1
View File
@@ -4,7 +4,7 @@
{% block content %}
<h2>Editing user: {{object.username}}</h2>
This form allows you to edit additional user details.
This form allows you to edit your profile details. If your supervisor is not available on the system please contact: ross.kruger@nhs.net.
{% if request.user|has_group:"cid_user_manager" %}
Name and emails can be edited <a href="{% url 'account_update' object.username %}">here</a>