Beispiel #1
0
 def test_ContactSchema_trims_email(self):
     email = fake.email()
     body = get_mock_contact_body(email=f"  {email}  ")
     errors = contact_schema.validate(body)
     assert not errors
     dumped = contact_schema.dump(body)
     assert dumped["email"] == email
Beispiel #2
0
 def test_ContactSchema_trims_subject(self):
     subject = fake.sentence()
     body = get_mock_contact_body(subject=f"  {subject}  ")
     errors = contact_schema.validate(body)
     assert not errors
     dumped = contact_schema.dump(body)
     assert dumped["subject"] == subject
Beispiel #3
0
 def test_ContactSchema_trims_message(self):
     message = fake.sentence()
     body = get_mock_contact_body(message=f"  {message}  ")
     errors = contact_schema.validate(body)
     assert not errors
     dumped = contact_schema.dump(body)
     assert dumped["message"] == message
Beispiel #4
0
 def test_ContactSchema_subject_equal_to_max(self):
     subject = fake.pystr(
         min_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH,
         max_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH,
     )
     body = get_mock_contact_body(subject=subject)
     errors = contact_schema.validate(body)
     assert not errors
Beispiel #5
0
 def test_ContactSchema_blank_subject(self):
     body = get_mock_contact_body(subject=" ")
     errors = contact_schema.validate(body)
     assert errors == {
         "subject": [
             "Missing data for required field.",
         ],
     }
Beispiel #6
0
 def test_ContactSchema_message_equal_to_max(self):
     message = fake.pystr(
         min_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH,
         max_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH,
     )
     body = get_mock_contact_body(message=message)
     errors = contact_schema.validate(body)
     assert not errors
Beispiel #7
0
 def test_ContactSchema_blank_message(self):
     body = get_mock_contact_body(message=" ")
     errors = contact_schema.validate(body)
     assert errors == {
         "message": [
             "Missing data for required field.",
         ],
     }
Beispiel #8
0
 def test_index_POST_400_bad_data(self):
     body = get_mock_contact_body()
     del body["email"]
     response = self.__send_index_POST_request(body)
     self._assert_400(response, {
         "email": [
             "Missing data for required field.",
         ],
     })
Beispiel #9
0
 def test_index_POST_204(self, send_contact_emails):
     body = get_mock_contact_body()
     response = self.__send_index_POST_request(body)
     self._assert_204(response)
     send_contact_emails.assert_called_with(
         body["email"],
         body["subject"],
         body["message"],
     )
Beispiel #10
0
 def test_ContactSchema_no_email(self):
     body = get_mock_contact_body()
     del body["email"]
     errors = contact_schema.validate(body)
     assert errors == {
         "email": [
             "Missing data for required field.",
         ],
     }
Beispiel #11
0
 def test_ContactSchema_invalid_email(self):
     email = fake.sentence()
     body = get_mock_contact_body(email=email)
     errors = contact_schema.validate(body)
     assert errors == {
         "email": [
             "Not a valid email address.",
         ],
     }
Beispiel #12
0
 def test_ContactSchema_subject_greater_than_max(self):
     subject = fake.pystr(
         min_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH + 1,
         max_chars=Limits.MAX_CONTACT_SUBJECT_LENGTH + 1,
     )
     body = get_mock_contact_body(subject=subject)
     errors = contact_schema.validate(body)
     assert errors == {
         "subject": [
             "Longer than maximum length "
             f"{Limits.MAX_CONTACT_SUBJECT_LENGTH}.",
         ],
     }
Beispiel #13
0
 def test_ContactSchema_message_greater_than_max(self):
     message = fake.pystr(
         min_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH + 1,
         max_chars=Limits.MAX_CONTACT_MESSAGE_LENGTH + 1,
     )
     body = get_mock_contact_body(message=message)
     errors = contact_schema.validate(body)
     assert errors == {
         "message": [
             "Longer than maximum length "
             f"{Limits.MAX_CONTACT_MESSAGE_LENGTH}.",
         ],
     }