Exemple #1
0
 def test_SignUpSchema_name_equal_to_max(self):
     name = fake.pystr(
         min_chars=Limits.MAX_USER_NAME_LENGTH,
         max_chars=Limits.MAX_USER_NAME_LENGTH,
     )
     body = get_mock_sign_up_body(name=name)
     errors = sign_up_schema.validate(body)
     assert not errors
Exemple #2
0
 def test_SignUpSchema_password_equal_to_min(self):
     password = fake.pystr(
         min_chars=Limits.MIN_USER_PASSWORD_LENGTH,
         max_chars=Limits.MIN_USER_PASSWORD_LENGTH,
     )
     body = get_mock_sign_up_body(password=password)
     errors = sign_up_schema.validate(body)
     assert not errors
Exemple #3
0
 def test_PasswordSchema_password_equal_to_max(self):
     password = fake.pystr(
         min_chars=Limits.MAX_USER_PASSWORD_LENGTH,
         max_chars=Limits.MAX_USER_PASSWORD_LENGTH,
     )
     body = get_mock_password_body(password=password)
     errors = password_schema.validate(body)
     assert not errors
Exemple #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
Exemple #5
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
Exemple #6
0
 def test_SignUpSchema_name_greater_than_max(self):
     name = fake.pystr(
         min_chars=Limits.MAX_USER_NAME_LENGTH + 1,
         max_chars=Limits.MAX_USER_NAME_LENGTH + 1,
     )
     body = get_mock_sign_up_body(name=name)
     errors = sign_up_schema.validate(body)
     assert errors == {
         "name": [
             f"Longer than maximum length {Limits.MAX_USER_NAME_LENGTH}.",
         ],
     }
Exemple #7
0
 def test_PasswordSchema_password_greater_than_max(self):
     password = fake.pystr(
         min_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1,
         max_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1,
     )
     body = get_mock_password_body(password=password)
     errors = password_schema.validate(body)
     assert errors == {
         "password": [
             f"Length must be between {Limits.MIN_USER_PASSWORD_LENGTH} "
             f"and {Limits.MAX_USER_PASSWORD_LENGTH}.",
         ],
     }
Exemple #8
0
 def test_SignUpSchema_password_less_than_min(self):
     password = fake.pystr(
         min_chars=Limits.MIN_USER_PASSWORD_LENGTH - 1,
         max_chars=Limits.MIN_USER_PASSWORD_LENGTH - 1,
     )
     body = get_mock_sign_up_body(password=password)
     errors = sign_up_schema.validate(body)
     assert errors == {
         "password": [
             f"Length must be between {Limits.MIN_USER_PASSWORD_LENGTH} "
             f"and {Limits.MAX_USER_PASSWORD_LENGTH}.",
         ],
     }
Exemple #9
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}.",
         ],
     }
Exemple #10
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}.",
         ],
     }
Exemple #11
0
    def test_send(self, client):
        app = MockApp()

        sendgrid.init_app(app)

        template_id = fake.pystr()
        recipient = fake.email()
        data = fake.pydict(4, True, ["str"])

        sendgrid.send(template_id, recipient, data)

        message = client().send.call_args[0][0]

        assert message.from_email.name == "Dawdle"
        assert message.from_email.email == app.config["SENDER_EMAIL"]
        assert message.personalizations[0].tos[0]["email"] == recipient
        assert message.template_id.template_id == template_id
        assert message.personalizations[0].dynamic_template_data == data
Exemple #12
0
class MockApp:

    config = {
        "SENDGRID_API_KEY": fake.pystr(),
        "SENDER_EMAIL": fake.email(),
    }
Exemple #13
0
 def test_PasswordSchema_unrecognised_field(self):
     body = get_mock_password_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not password_schema.validate(body)
     assert key not in password_schema.dump(body)
Exemple #14
0
 def test_EmailSchema_unrecognised_field(self):
     body = get_mock_email_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not email_schema.validate(body)
     assert key not in email_schema.dump(body)
Exemple #15
0
 def test_SignUpSchema_unrecognised_field(self):
     body = get_mock_sign_up_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not sign_up_schema.validate(body)
     assert key not in sign_up_schema.dump(body)