Closed dragon-fire-fly closed 1 year ago
The code in forms.py was amended to use the get
method, returning the title, if present, else None. If None is returned, the code raises a validation error.
def validate_project_name(data):
"""Checks that a project name is not already taken and does not
contain profanities"""
if isinstance(data, str):
project_name = data
else:
project_name = data.cleaned_data.get("title", None)
if not project_name:
raise ValidationError("No title given")
else:
if data.instance:
if data.instance.title == project_name:
return
Which file is being tested? app_home/views.py
What is being tested? test =>
def test_create_project_post_invalid():
The 'create project' post method is being tested with an invalid title being given.Describe the test failure The custom form validation is failing because it expects "title" to be present in order to check for duplicates and profanities.
Screenshots
Additional context in forms.py