How to use pyIsEmail - 10 common examples

To help you get started, we’ve selected a few pyIsEmail examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
def create_diagnosis(tag):

    """Create a Diagnosis for a given tag.

    Keyword arguments:
    tag --- the tag string to create a Diagnosis for

    """

    split_tag = tag.split("_")
    d_class = _get_diagnosis_class(split_tag[1])
    diagnosis_type = "_".join(split_tag[2:])
    if diagnosis_type == "" and d_class == ValidDiagnosis:
        diagnosis_type = "VALID"

    return d_class(diagnosis_type)
github michaelherold / pyIsEmail / tests / test_is_email.py View on Github external
def test_without_diagnosis(self):
        result = is_email(self.address)
        expected = create_diagnosis(self.diagnosis) < self.threshold

        self.assertEqual(
            result,
            expected,
            ("%s (%s): Got %s, but expected %s."
             % (self.id, self.address, result, expected))
        )
github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
def _get_diagnosis_class(tag):

    """Get class of the Diagnosis to use for a given tag.

    Keyword arguments:
    tag --- the tag string to look up

    """

    if tag == "ERR":
        d_class = InvalidDiagnosis
    elif tag == "DNSWARN":
        d_class = DNSDiagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "RFC5322":
        d_class = RFC5322Diagnosis
    elif tag == "CFWS":
        d_class = CFWSDiagnosis
    elif tag == "DEPREC":
        d_class = DeprecatedDiagnosis
github michaelherold / pyIsEmail / tests / diagnosis / test_base_diagnosis.py View on Github external
def test_lt(self):
        d1 = BaseDiagnosis("test")
        d1.code = 1
        d2 = BaseDiagnosis("test")
        d2.code = 2

        self.assertLess(d1, d2)
        self.assertLess(d1, 3)
github michaelherold / pyIsEmail / tests / test_is_email.py View on Github external
from testscenarios import TestWithScenarios
from unittest import TestCase
try:
    from unittest.mock import patch
except ImportError:
    from mock import patch
import dns.resolver
from pyisemail import is_email
from pyisemail.diagnosis import BaseDiagnosis, DNSDiagnosis
from tests.validators import create_diagnosis, get_scenarios


class IsEmailTest(TestWithScenarios):

    scenarios = get_scenarios("tests.xml")
    threshold = BaseDiagnosis.CATEGORIES['THRESHOLD']

    def test_without_diagnosis(self):
        result = is_email(self.address)
        expected = create_diagnosis(self.diagnosis) < self.threshold

        self.assertEqual(
            result,
            expected,
            ("%s (%s): Got %s, but expected %s."
             % (self.id, self.address, result, expected))
        )

    def test_with_diagnosis(self):
        result = is_email(self.address, diagnose=True)
        expected = create_diagnosis(self.diagnosis)
github michaelherold / pyIsEmail / tests / diagnosis / test_base_diagnosis.py View on Github external
def test_gt(self):
        d1 = BaseDiagnosis("test")
        d1.code = 1
        d2 = BaseDiagnosis("test")
        d2.code = 2

        self.assertGreater(d2, d1)
        self.assertGreater(3, d1)
github michaelherold / pyIsEmail / tests / diagnosis / test_base_diagnosis.py View on Github external
def test_lt(self):
        d1 = BaseDiagnosis("test")
        d1.code = 1
        d2 = BaseDiagnosis("test")
        d2.code = 2

        self.assertLess(d1, d2)
        self.assertLess(d1, 3)
github michaelherold / pyIsEmail / tests / diagnosis / test_base_diagnosis.py View on Github external
def test_hash(self):
        d1 = BaseDiagnosis("test")
        d2 = BaseDiagnosis("test")

        self.assertEqual(hash(d1), hash(d2))
github michaelherold / pyIsEmail / tests / diagnosis / test_base_diagnosis.py View on Github external
def test_gt(self):
        d1 = BaseDiagnosis("test")
        d1.code = 1
        d2 = BaseDiagnosis("test")
        d2.code = 2

        self.assertGreater(d2, d1)
        self.assertGreater(3, d1)
github michaelherold / pyIsEmail / tests / validators / __init__.py View on Github external
"""

    if tag == "ERR":
        d_class = InvalidDiagnosis
    elif tag == "DNSWARN":
        d_class = DNSDiagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "VALID":
        d_class = ValidDiagnosis
    elif tag == "RFC5321":
        d_class = RFC5321Diagnosis
    elif tag == "RFC5322":
        d_class = RFC5322Diagnosis
    elif tag == "CFWS":
        d_class = CFWSDiagnosis
    elif tag == "DEPREC":
        d_class = DeprecatedDiagnosis
    else:
        d_class = ""

    return d_class