Skip to content

Commit

Permalink
Fix returning error if GP details are missing
Browse files Browse the repository at this point in the history
By attaching it to gp_practice_ods_code it's visible for both form usage and the CSV upload.
  • Loading branch information
mbarton committed Sep 19, 2024
1 parent f98d445 commit 1bbacbd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project/npda/forms/patient_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def clean(self):
)

if gp_practice_ods_code is None and gp_practice_postcode is None:
self.add_error(None, ValidationError("'GP Practice ODS code' and 'GP Practice postcode' cannot both be empty"))
self.add_error("gp_practice_ods_code", ValidationError("'GP Practice ODS code' and 'GP Practice postcode' cannot both be empty"))

if gp_practice_postcode:
try:
Expand Down
4 changes: 2 additions & 2 deletions project/npda/tests/form_tests/test_patient_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def test_missing_gp_details():
form = PatientForm({})

errors = form.errors.as_data()
assert("__all__" in errors)
assert("gp_practice_ods_code" in errors)

error_message = errors["__all__"][0].messages[0]
error_message = errors["gp_practice_ods_code"][0].messages[0]
assert(error_message == "'GP Practice ODS code' and 'GP Practice postcode' cannot both be empty")


Expand Down
7 changes: 3 additions & 4 deletions project/npda/tests/test_csv_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,9 @@ def test_missing_gp_ods_code(test_user, single_row_valid_df):

patient = Patient.objects.first()

assert("__all__" in patient.errors)

# TODO MRB: should we make this error more obvious that you can only set ODS code in the spreadsheet?
error_message = patient.errors["__all__"][0]['message']
assert("gp_practice_ods_code" in patient.errors)

error_message = patient.errors["gp_practice_ods_code"][0]['message']
# TODO MRB: why does this have entity encoding issues?
assert(error_message == "'GP Practice ODS code' and 'GP Practice postcode' cannot both be empty")

Expand Down

0 comments on commit 1bbacbd

Please sign in to comment.