Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d61d8c5b67
Fetching contributors…

Cannot retrieve contributors at this time

file 76 lines (55 sloc) 2.498 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
# -*- coding: utf-8 -*-

import unittest
from emailahoy import VerifyEmail
from emailahoy import query_mx
from emailahoy import verify_email_address

class TestEmailVerificationFunctions(unittest.TestCase):

    def setUp(self):
        """ Instantiate the class """
        self.e = VerifyEmail()

    def test_class_based_invalid_email(self):
        """ Test the existance of an invalid email address (class based)"""
        status = self.e.verify_email_smtp(
                            email='non-existing-email@gmail.com',
                            from_host='neekware.com',
                            from_email='info@neekware.com'
                        )
        
        # email doesn't exist
        self.assertEquals(self.e.not_found(status), True)

    def test_class_based_valid_email(self):
        """ Test the existance of a valid email address (class based)"""
        status = self.e.verify_email_smtp(
                            email='un33kvu@gmail.com',
                            from_host='neekware.com',
                            from_email='info@neekware.com'
                        )

        # email exists
        self.assertEquals(self.e.was_found(status), True)

    def test_function_based_invalid_email(self):
        """ Test the existance of an invalid email address (function based)"""

        found = verify_email_address(
                            email='non-existing-email@gmail.com',
                            from_host='neekware.com',
                            from_email='info@neekware.com'
                        )

        # email doesn't exists
        self.assertEquals(found, False)
            

    def test_function_based_valid_email(self):
        """ Test the existance of a valid email address (function based)"""

        found = verify_email_address(
                            email='un33kvu@gmail.com',
                            from_host='neekware.com',
                            from_email='info@neekware.com'
                        )

        # email exists
        self.assertEquals(found, True)
            

    def test_mx_query_invalid_domain(self):
        """ Query mx of an invalid domain name """
        mx = query_mx('invalid_domain_address.com')
        self.assertEquals(len(mx), 0)


    def test_mx_query_valid_domain(self):
        """ Query mx of a valid domain name """

        mx = query_mx('gmail.com')
        self.assertGreater(len(mx), 0)


if __name__ == '__main__':
    unittest.main()
Something went wrong with that request. Please try again.