| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import given, settings |
| 14 |
from hypothesis.strategies import emails, just |
| 15 |
|
| 16 |
|
| 17 |
@pytest.mark.skipif( |
| 18 |
settings.get_current_profile_name() == "crosshair", |
| 19 |
reason="takes ~7 mins; first barrier: the `sampled_from(get_top_level_domains())` decision is " |
| 20 |
"realized via iterative comparisons; see https://github.com/pschanely/CrossHair/issues/332", |
| 21 |
) |
| 22 |
@given(emails()) |
| 23 |
def test_is_valid_email(address: str): |
| 24 |
local, at_, domain = address.rpartition("@") |
| 25 |
assert len(address) <= 254 |
| 26 |
assert at_ == "@" |
| 27 |
assert local |
| 28 |
assert domain |
| 29 |
assert not domain.lower().endswith(".arpa") |
| 30 |
|
| 31 |
|
| 32 |
@given(emails(domains=just("mydomain.com"))) |
| 33 |
def test_can_restrict_email_domains(address: str): |
| 34 |
assert address.endswith("@mydomain.com") |