Skip to content

Commit 0c3d309

Browse files
authored
fix: PT59628-1312-R4632 (#2448)
* fix: PT59628-1312-R4632 * fix test * Add dashboard test * Simplify
1 parent e1fa00b commit 0c3d309

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

portal/forms/organisation.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import re
12
from builtins import object
23

34
from common.models import School
45
from django import forms
56
from django.core.exceptions import ObjectDoesNotExist
6-
from django.core.validators import EmailValidator
77
from django_countries.widgets import CountrySelectWidget
88

99

@@ -167,16 +167,10 @@ def clean(self):
167167

168168
def clean_name(self):
169169
name = self.cleaned_data.get("name", None)
170-
validator = EmailValidator()
171170

172-
if name:
173-
try:
174-
validator(name)
175-
is_email = True
176-
except forms.ValidationError:
177-
is_email = False
178-
179-
if is_email:
180-
raise forms.ValidationError("Please make sure your organisation name is valid")
171+
if re.match(re.compile("^[\w\.' ]+$"), name) is None:
172+
raise forms.ValidationError(
173+
"School names cannot contain special characters except full stops and apostrophes."
174+
)
181175

182176
return name

portal/tests/pageObjects/portal/teach/dashboard_page.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ def change_organisation_details(self, details):
5252
self.browser.find_element(By.ID, "update_details_button").click()
5353
return self
5454

55-
def has_edit_failed(self):
56-
self.wait_for_element_by_id("edit_form")
57-
errorlist = self.browser.find_element(By.ID, "edit_form").find_element(By.CLASS_NAME, "errorlist").text
58-
error = "There is already a school or club registered with that name"
59-
return error in errorlist
60-
6155
def create_class(self, name, classmate_progress, teacher_id=None):
6256
self.browser.find_element(By.ID, "id_class_name").send_keys(name)
6357
if classmate_progress:

portal/tests/pageObjects/portal/teach/onboarding_organisation_page.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def __init__(self, browser):
1313

1414
assert self.on_correct_page("onboarding_organisation_page")
1515

16-
def create_organisation(self, name, password, country="GB"):
17-
self._create_organisation(name, password, country)
16+
def create_organisation(self, name, country="GB"):
17+
self._create_organisation(name, country)
1818

1919
return onboarding_classes_page.OnboardingClassesPage(self.browser)
2020

21-
def create_organisation_failure(self, name, password, country="GB"):
22-
self._create_organisation(name, password, country)
21+
def create_organisation_failure(self, name, country="GB"):
22+
self._create_organisation(name, country)
2323

2424
return self
2525

@@ -28,7 +28,7 @@ def create_organisation_empty(self):
2828

2929
return self
3030

31-
def _create_organisation(self, name, password, country):
31+
def _create_organisation(self, name, country):
3232
self.browser.find_element(By.ID, "id_name").send_keys(name)
3333
country_element = self.browser.find_element(By.ID, "id_country")
3434
select = Select(country_element)
@@ -47,10 +47,3 @@ def has_creation_failed(self):
4747
)
4848
error = "There is already a school or club registered with that name and postcode"
4949
return error in errors
50-
51-
def was_postcode_invalid(self):
52-
errors = (
53-
self.browser.find_element(By.ID, "form-create-organisation").find_element(By.CLASS_NAME, "errorlist").text
54-
)
55-
error = "Please enter a valid postcode or ZIP code"
56-
return error in errors

portal/tests/test_organisation.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from portal.tests.pageObjects.portal.base_page import BasePage
1717
from portal.tests.pageObjects.portal.home_page import HomePage
1818
from portal.tests.test_invite_teacher import FADE_TIME
19-
2019
from .base_test import BaseTest
2120
from .utils.messages import is_organisation_created_message_showing
2221

@@ -28,8 +27,22 @@ def test_create(self):
2827
self.selenium.get(self.live_server_url)
2928
page = HomePage(self.selenium).go_to_teacher_login_page().login_no_school(email, password)
3029

31-
page, name = create_organisation(page, password)
32-
assert is_organisation_created_message_showing(self.selenium, name)
30+
school_name = "My School"
31+
page.create_organisation(school_name)
32+
assert is_organisation_created_message_showing(self.selenium, school_name)
33+
34+
def test_create_invalid_name(self):
35+
email, password = signup_teacher_directly()
36+
37+
self.selenium.get(self.live_server_url)
38+
page = HomePage(self.selenium).go_to_teacher_login_page().login_no_school(email, password)
39+
40+
invalid_school_name = "<a>My School</a"
41+
page.create_organisation_failure(invalid_school_name)
42+
assert page.was_form_invalid(
43+
"form-create-organisation",
44+
"School names cannot contain special characters except full stops and apostrophes.",
45+
)
3346

3447
def test_kick(self):
3548
email_1, password_1 = signup_teacher_directly()
@@ -171,11 +184,30 @@ def test_edit_details(self):
171184

172185
assert page.check_organisation_details({"name": school.name})
173186

174-
new_name = "new " + school.name
187+
new_name = f"new {school.name}"
175188

176189
page.change_organisation_details({"name": new_name})
177190
assert page.check_organisation_details({"name": new_name})
178191

192+
def test_edit_details_invalid_name(self):
193+
email, password = signup_teacher_directly()
194+
school = create_organisation_directly(email)
195+
_, _, access_code = create_class_directly(email)
196+
create_school_student_directly(access_code)
197+
198+
self.selenium.get(self.live_server_url)
199+
page = HomePage(self.selenium).go_to_teacher_login_page().login(email, password)
200+
201+
assert page.check_organisation_details({"name": school.name})
202+
203+
new_name = f"<a>{school.name}</a>"
204+
205+
page.change_organisation_details({"name": new_name})
206+
207+
assert page.was_form_invalid(
208+
"edit_form", "School names cannot contain special characters except full stops and apostrophes."
209+
)
210+
179211
def test_edit_clash(self):
180212
email_1, _ = signup_teacher_directly()
181213
email_2, password_2 = signup_teacher_directly()
@@ -193,4 +225,4 @@ def test_edit_clash(self):
193225

194226
page = page.change_organisation_details({"name": school1.name})
195227

196-
assert page.has_edit_failed()
228+
assert page.was_form_invalid("edit_form", "There is already a school or club registered with that name")

portal/tests/test_teacher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ def test_onboarding_complete(self):
772772
.login_no_school(email, password)
773773
)
774774

775-
page = page.create_organisation("Test school", "W1", "GB")
775+
page = page.create_organisation("Test school")
776776
page = page.create_class("Test class", True)
777777
page = (
778778
page.type_student_name("Test Student")

0 commit comments

Comments
 (0)