diff --git a/atst/forms/poc.py b/atst/forms/poc.py index 02ef76ab..d55fce7b 100644 --- a/atst/forms/poc.py +++ b/atst/forms/poc.py @@ -9,6 +9,8 @@ class POCForm(ValidatedForm): def validate(self, *args, **kwargs): if self.am_poc.data == "yes": + # Prepend Optional validators so that the validation chain + # halts if no data exists. self.fname_poc.validators.insert(0, Optional()) self.lname_poc.validators.insert(0, Optional()) self.email_poc.validators.insert(0, Optional()) diff --git a/tests/routes/test_request_new.py b/tests/routes/test_request_new.py index 217882c4..3efc4360 100644 --- a/tests/routes/test_request_new.py +++ b/tests/routes/test_request_new.py @@ -125,22 +125,21 @@ def test_not_am_poc_requires_poc_info_to_be_completed(client, user_session): "/requests/new/3/{}".format(request.id), headers={"Content-Type": "application/x-www-form-urlencoded"}, data="am_poc=no", + follow_redirects=True ) assert ERROR_CLASS in response.data.decode() -# def test_not_am_poc_allows_user_to_fill_in_poc_info(client, user_session): -# creator = UserFactory.create() -# user_session(creator) -# request = RequestFactory.create(creator=creator, body={}) -# client.post( -# "/requests/new/3/{}".format(request.id), -# headers={"Content-Type": "application/x-www-form-urlencoded"}, -# data="am_poc=yes", -# ) - -# assert "Location" not in response.headers -# request = Requests.get(request.id) +def test_not_am_poc_allows_user_to_fill_in_poc_info(client, user_session): + creator = UserFactory.create() + user_session(creator) + request = RequestFactory.create(creator=creator, body={}) + response = client.post( + "/requests/new/3/{}".format(request.id), + headers={"Content-Type": "application/x-www-form-urlencoded"}, + data="am_poc=no&fname_poc=test&lname_poc=user&email_poc=test.user@mail.com&dodid_poc=1234567890", + ) + assert ERROR_CLASS not in response.data.decode() def test_can_review_data(user_session, client):