示例#1
0
 def test_delete_contact(self):
     test_contact = Contact("test", "user","700000000", "*****@*****.**")
     test_contact.save_contact()
     test_contact2=Contact("test", "user", "978899877766", "*****@*****.**")
     test_contact2.save_contact()
     test_contact.delete_contact()
     self.assertEqual(len(Contact.contact_list),1)
示例#2
0
class TestContact(unittest.TestCase):

    def setUp(self):

        self.new_contact = Contact("James","Muriuki","0712345678","*****@*****.**") # create contact object


    def test_init(self):


        self.assertEqual(self.new_contact.first_name,"James")
        self.assertEqual(self.new_contact.last_name,"Muriuki")
        self.assertEqual(self.new_contact.phone_number,"0712345678")
        self.assertEqual(self.new_contact.email,"*****@*****.**")

    def test_save_contact(self):
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list),1)

    def tearDown(self):
        Contact.contact_list = []

    def test_save_multiple_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test","user","0745678932","test2user.com")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list),2)

    def test_delete_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test","user","0745678932","test2user.com")
        test_contact.save_contact()
        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list),1)

    def test_find_contact_by_number(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test","user","0711223344","*****@*****.**")
        test_contact.save_contact()
        found_contact = Contact.find_by_number("0711223344")
        self.assertEqual(found_contact.email,test_contact.email)

    def test_contact_exists(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test","user","0711223344","*****@*****.**")
        test_contact.save_contact()
        contact_exists = Contact.contact_exist("0711223344")
        self.assertTrue(contact_exists)

    def test_display_all_conatcts(self):
        self.assertEqual(Contact.display_contacts(),Contact.contact_list)

    def test_copy_email(self):
        self.new_contact.save_contact()
        Contact.copy_email("0712345678")
        self.assertEqual(self.new_contact.email,pyperclip.paste())
class TestContact(unittest.TestCase):
    def setUp(self):
        self.new_contact = Contact("Betty", "Cherotich", "0712345678",
                                   "*****@*****.**")

    def tearDown(self):
        Contact.contact_list = []

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, "Betty")
        self.assertEqual(self.new_contact.last_name, "Cherotich")
        self.assertEqual(self.new_contact.phone_number, "0712345678")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_save_multiple_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "User", "0712345678", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.new_contact.delete_contact()  # deleting contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        found_contact = Contact.find_by_number("0711223344")
        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        contact_exists = Contact.contact_exists("0711223344")
        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        self.new_contact.save_contact()
        Contact.copy_email("0712345678")
        self.assertEqual(self.new_contact.email, pyperclip.paste())
class PhonebookTestCase(unittest.TestCase):
    def setUp(self):
        self.contact = Contact()

    def test_add_contact(self):
        result = self.contact.add_contact("pete", "0712351423")
        self.assertEqual(result["info"], "Contact added")

    def test_add_contact_with_contact_greater_than_10_digits(self):
        result = self.contact.add_contact("anne", "3414444444444414")
        self.assertNotEqual(result["info"], "Contact added")
        self.assertEqual(result["info"],
                         "Re-enter the contact, contact must be 10 digits")

    def test_delete_contact(self):
        result = self.contact.delete_contact("jane", "1873137103")
        self.assertEqual(result["info"], "Contact deleted")

    def test_update_contact(self):
        result = self.contact.update_contact("jane", "34251617181",
                                             "5463727828")
        self.assertEqual(result, "My new contact is 5463727828")

    def test_view_contacts(self):
        result = self.contact.view_contacts("shaz", "2151853811")
        self.assertEqual(result, "Contact for shaz is 2151853811")
示例#5
0
class TestContact(unittest.TestCase):
	def setUp(self):
		self.contact = Contact()

	def test_add_contact(self):
		result = self.contact.add_contact("Tittoh", "0729261228")
		self.assertEqual(result["message"], "Contact added successfully")

	def test_update_contact(self):
		result =self.contact.update_contact("Tittoh", "0729261228", "0736197716")
		self.assertEqual(result["message"], "Contact updated successfully")

	def test_delete_contact(self):
		result = self.contact.delete_contact("Ken", "0734123456")
		self.assertEqual(result["message"], "Contact deleted successfully")

	def test_view_contact(self):
		result = self.contact.view_contact("Emmy", "099345667")
		self.assertEqual(result, "Contact for Emmy is 099345667")
示例#6
0
class TestContact(unittest.TestCase):

    # Items up here .......

    def setUp(self):
        '''
        Set up method to run before each test cases.
        '''
        self.new_contact = Contact("James", "Muriuki", "0712345678",
                                   "*****@*****.**")  # create contact object

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_contact.first_name, "James")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "0712345678")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into
         the contact list
        '''
        self.new_contact.save_contact()  # saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

        # setup and class creation up here
    def tearDown(self):
        '''
            tearDown method that does clean up after each test case has run.
            '''
        Contact.contact_list = []


# other test cases here

    def test_save_multiple_contact(self):
        '''
            test_save_multiple_contact to check if we can save multiple contact
            objects to our contact_list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

        # More tests above
    def delete_contact(self):
        '''
        delete_contact method deletes a saved contact from the contact_list
        '''

        Contact.contact_list.remove(self)

    @classmethod
    def find_by_number(cls, number):
        '''
        Method that takes in a number and returns a contact that matches that number.

        Args:
            number: Phone number to search for
        Returns :
            Contact of person that matches the number.
        '''

        for contact in cls.contact_list:
            if contact.phone_number == number:
                return contact

    # More tests above
    def test_delete_contact(self):
        '''
            test_delete_contact to test if we can remove a contact from our contact list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

        return False

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a Boolean  if we cannot find the contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0712345678")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#7
0
class TestContact(unittest.TestCase):
    def setUp(self):

        self.new_contact = Contact(
            "Peter", "Maina", "072012131",
            "*****@*****.**")  # create contact object

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, "Peter")
        self.assertEqual(self.new_contact.last_name, "Maina")
        self.assertEqual(self.new_contact.phone_number, "072012131")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        Contact.contact_list = []

    def test_save_multiple_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact_list
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact_list
        test_contact.save_contact()

        self.new_contact.delete_contact()  # delete contact
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        # test to check if we can find a contact by phone number
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact_list
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0712345678")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact_list
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0712345678")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):

        # test to confirm we are copying the email address from a found contact
        self.new_contact.save_contact()
        Contact.copy_email("072012131")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#8
0
class Test(unittest.TestCase):
    def setUp(self):
        self.new_contact = Contact('apiut', 'Toel', '071235698',
                                   '*****@*****.**')

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, 'apiut')
        self.assertEqual(self.new_contact.last_name, 'Toel')
        self.assertEqual(self.new_contact.phone_number, '071235698')
        self.assertEqual(self.new_contact.email, '*****@*****.**')

    def test_save_contact(self):

        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):

        Contact.contact_list = []

    def test_save_multiple_contact(self):

        self.new_contact.save_contact()
        self.test_concat = Contact("Test", "user", "01235464", "*****@*****.**")

        self.test_concat.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):

        self.new_contact.save_contact()
        self.test_concat = Contact("Test", "user", "01235464", "*****@*****.**")

        self.test_concat.save_contact()
        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):

        self.new_contact.save_contact()
        self.test_concat = Contact("Test", "user", "0711223344",
                                   "*****@*****.**")
        self.test_concat.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.phone_number,
                         self.test_concat.phone_number)

    def test_contact_exists(self):
        self.new_contact.save_contact()
        test_concat = Contact("Test", "user", "0711223344", "*****@*****.**")
        test_concat.save_contact()

        contact_exist = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exist)

    def test_display_all_contact(self):
        self.assertEqual(Contact.display_contact(), Contact.contact_list)

    def test_copy_email(self):
        self.new_contact.save_contact()
        Contact.copy_email("071235698")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#9
0
class TestContact(unittest.TestCase):
    '''
    Test class that desfines test cases for the contact class behaviours

    Args:
        unittest.TestCase: TestCase class that helps in creating test cases
    '''
    def setUp(self):
        '''
        Set up method to run before each test cases
        '''
        self.new_contact = Contact('Carine', 'I. SEMWAGA', '0788206956',
                                   '*****@*****.**')
        # Create contact object

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''
        self.assertEqual(self.new_contact.first_name, 'Carine')
        self.assertEqual(self.new_contact.last_name, 'I. SEMWAGA')
        self.assertEqual(self.new_contact.phone_number, '0788206956')
        self.assertEqual(self.new_contact.email, '*****@*****.**')

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is savd into the contact list
        '''
        self.new_contact.save_contact()  #saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

    # SetUp and class creation up here

    def tearDown(self):
        '''
        tearDown method that does clean up after each test has run
        '''
        Contact.contact_list = []

    # Other test cases here
    def test_save_multiple_contact(self):
        '''
        test_save_multiple_contact to check if we can save multiple contact
        '''
        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    #More test
    def test_delete_contact(self):
        '''
        test_delete_contact to test if we can remove a contact from our contact list
        '''
        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  #Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number('0712345678')
        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we canreturn a Booleanif we cannot find the contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exists('0712345678')

        self.assertTrue(contact_exists)

    def test_displat_all_contacts(self):
        '''
        Method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''
        self.new_contact.save_contact()
        Contact.copy_email('0712345678')

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#10
0
class EstContact(unittest.TestCase):
    def setUp(self):
        self.new_contact = Contact("james", "Muriuki", "0746743772",
                                   "*****@*****.**")

    def tearDown(self):
        Contact.contact_list = []

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, "james")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "0746743772")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_(self):
        self.new_contact.save_contact()

        self.assertEqual(len(Contact.contact_list), 1)

    def test_save_multiple_contacts(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("test", "user", "078654321", "*****@*****.**")
        test_contact.save_contact()

        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("*****@*****.**")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#11
0
class TestContact(unittest.TestCase):
    """
    Test class that defines test cases for the contact class behaviours

    Args:
       unittest.TestCase: TestCase class that helps in creating test cases

    We pass in the parent class as a parameter in the parenthesis
    """
    def setUp(self):
        """
        Set up method to run before each test path. This method is what we will test against.
        """
        # Below creating the new contact object to test.
        self.new_contact = Contact("James", "Muriuki", "0712345678",
                                   "*****@*****.**")
# Just like the setUp() method the tearDown() method executes a set of instructions after every test

    def tearDown(self):
        """
        tearDown method that does clean up after each test case has run.
        """

        # Here the tearDown() method assigns the contact_list in the Contact class empty. This helps us get accurate test results everytime have a new test case
        Contact.contact_list = []

    # self.new_contact is an instance of the Contact class.
    # We create method test_init to check if our objects are instantiated corectly.

    def test_init(self):
        """
        has to be called test_init. This is to test if the object is initialized properly.
        """
        # the self.assertEqual() checks fofr an expected result
        # We are checking if the name and description of our new object is what we actually put
        self.assertEqual(self.new_contact.first_name, "James")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "0712345678")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    # Second test
    # We want to test if we can save contacts.
    # indentation wise it below function has to be on the same line with the ohter functions
    def test_save_contact(self):
        """
        test_save_contact test case to test if the contact object is saved into the contact list
        """
        # .save_contact() is the save to contact function.
        # Test would check if an addition has been made to our contact list
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    # Test to se if we can add to contact list multiple times
    def test_save_multiple_contact(self):
        """
        def test_save_multiple_contact to check if we can save multiple contacts to our contact_list
        """
        self.new_contact.save_contact()
        # new contact
        test_contact = Contact("Test", "user", "0798765432", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    # Test to see if we can delete contacts
    def test_delete_contact(self):
        """
        test_delete_contact to test if we can remove a contact from our contact list
        """
        self.new_contact.save_contact()
        # new contact
        test_contact = Contact("Test", "user", "0745639300", "*****@*****.**")
        # new contact saved
        test_contact.save_contact()
        #    For deleting the new contact
        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    # Test to see if we can search and find our saved contacts
    def test_find_by_number(self):
        """
        Test to check if we can find a contact by phone nuber and display any information.
        """
        self.new_contact.save_contact()
        # new contact
        test_contact = Contact("Test", "user", "0748363839", "*****@*****.**")
        test_contact.save_contact()
        # The number that we find in found_contact should be the same as the one in test_contact for the test to pass.
        # If they aren't the same...the test will always fail
        found_contact = Contact.find_by_number("0748363839")
        # The test
        self.assertEqual(found_contact.email, test_contact.email)

    # Test to see if a contact exists

    def test_contact_exists(self):
        """
        Test to check if we can return a Boolean if we cannot find the contact.
        """

        self.new_contact.save_contact()
        # Test user
        test_contact = Contact("Test", "user", "0722334455", "*****@*****.**")
        # We save
        test_contact.save_contact()
        # variable that stores what we expect
        contact_exists = Contact.contact_exist("0722334455")
        # The test that should return a variable
        self.assertTrue(contact_exists)

    def test_display_all_contact(self):
        """
        Method that returns a list of all contacts saved.
        """
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

# We want to test if we can copy paste info.

    def test_copy_email(self):
        """
        Test to confirm that we are copying the email address from a found contact
        """
        self.new_contact.save_contact()
        Contact.copy_email("0712345678")
        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#12
0
class TestContact(unittest.TestCase):
    '''
    Test class that defines test cases for the contact class behaviours

    Args:
        unittest.TestCase: Testcase class that helps in creating test cases

    '''
    def setUp(self):
        '''
        Set up method to run before each test cases.
        '''
        self.new_contact = Contact("Irene", "Adler", "98378973",
                                   "*****@*****.**")

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_contact.first_name, "Irene")
        self.assertEqual(self.new_contact.last_name, "Adler")
        self.assertEqual(self.new_contact.phone_number, "98378973")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into
        the contact list
        '''
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        '''
        tearDown method that does cleanup after each test case has run.
        '''
        Contact.contact_list = []

    def test_save_multiple_contact(self):
        '''
        test_save_multiple to check if we can save multiple contact
        objects to our contact_list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Irene", "Adler", "98378973",
                               "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
        test_delete_contact to test if we can remove a contact from our contact list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Irene", "Adler", "98378973",
                               "*****@*****.**")
        test_contact.save_contact()

        self.new_contact.delete_contact()

        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Irene", "Adler", "98378973",
                               "*****@*****.**")
        test_contact.save_contact()

        found_contact = Contact.find_by_number("98378973")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a Boolean if we cannot find the contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Irene", "Adler", "98378973",
                               "*****@*****.**")
        test_contact.save_contact()

        contact_exists = Contact.contact_exists("98378973")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm thet we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("98378973")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#13
0
文件: run.py 项目: dan-jugz/conact
def del_contact(Contact):
    '''
    function to delete a contact
    '''
    Contact.delete_contact()
示例#14
0
 def test_delete_contact(self):
     contact3 = Contact("Ary", "07230754545")
     contact3.delete_contact()
     self.assertEqual(len(contactList), 49)
示例#15
0
class TestContact(unittest.TestCase):
    '''
   Test class that defines test cases for the contact class behaviours.

   Args:
       unittest.TestCase: TestCase class that helps in creating test cases
   '''
    def setUp(self):
        '''
       Set up method to run before each test cases.
       '''
        self.new_contact = Contact("evans", "Mwenda", "0705861793",
                                   "*****@*****.**")  # create contact object

    def test_init(self):
        '''
       test_init test case to test if the object is initialized properly
       '''
        self.assertEqual(self.new_contact.first_name, "evans")
        self.assertEqual(self.new_contact.last_name, "Mwenda")
        self.assertEqual(self.new_contact.number, "0705861793")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
       test_save_contact test case to test if the object is saved onto
       the contact_list
       '''
        self.new_contact.save_contact()  #saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)
# third test

# setup and class creation up here
# setup and class creation up here

    def tearDown(self):
        '''
       tearDown method that does clean up after each test case has run.
       '''
        Contact.contact_list = []

    def test_save_multiple_contact(self):
        '''
           test_save_multiple_contact to check if we save multiple contact_list
           objects to our contact_list
           '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0705861793", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)


# foorth test

    def test_delete_contact(self):
        '''
            test_delete_contact to test if we can remove a contact from contact_list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0705861793", "*****@*****.**")
        test_contact.save_contact()
        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

        # fifth test
    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0705861793",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0705861793")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a Boolean if we cannot find the
        contact
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0705861793",
                               "*****@*****.**")  # add contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0705861793")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns list the contact saved
        '''
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0705861793")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#16
0
class TestContact(unittest.TestCase):
    def setUp(self):
        self.new_contact = Contact(
            "Nyakundi", "Lamech", "0790406870",
            "*****@*****.**")  # Create contact object

    def tearDown(self):
        Contact.contact_list = []

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, "Nyakundi")
        self.assertEqual(self.new_contact.last_name, "Lamech")
        self.assertEqual(self.new_contact.phone_number, "0790406870")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_save_contact(self):
        self.new_contact.save_contact()  # saving the contact
        self.assertEqual(len(Contact.contact_list), 1)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_save_multiple_contact(self):

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0790406870", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_delete_contact(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0790406870", "*****@*****.**")
        test_contact.save_contact()

        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_find_contact_by_number(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0791406870", "*****@*****.**")
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0791406870")

        self.assertEqual(found_contact.email, test_contact.email)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_contact_exists(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0791406870",
                               "*****@*****.**")
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0791406870")
        self.assertTrue(contact_exists)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_diplay_all_contacts(self):
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def setUp(self):
        self.new_contact = Contact("Nyakundi", "Lamech", "0790406870",
                                   "*****@*****.**")

    def test_copy_email(self):
        self.new_contact.save_contact()
        Contact.copy_email("0790406870")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#17
0
class TestContact(unittest.TestCase):
    '''
    Test class that defines test cases for contact class behaviours.

    Args:
        unittest.TestCase: TestCase class that helps in creating test cases
    '''

    def setUp(self):
        '''
        setup method to run before each test cases.
        '''
        self.new_contact = Contact("Newton", "Karanu", "0714895623", "*****@*****.**") #create new contact object

    def test_init(self):
        '''
        test_init test case to test if the object is initialised properly
        '''

        self.assertEqual(self.new_contact.first_name, "Newton")
        self.assertEqual(self.new_contact.last_name,"Karanu")
        self.assertEqual(self.new_contact.number,"0714895623")
        self.assertEqual(self.new_contact.email,"*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into the contact list
        '''
        self.new_contact.save_contact() #saving the new contact
        self.assertEqual(len(Contact.contact_list),1)

    def test_contact_exists(self):
        '''
        test_contact_exists test case to check if we can return a boolean if we cannot find the contact.
        '''
        self.new_contact.save_contact()
        Test_contact = Contact("Test","user","0711223344","*****@*****.**")
        Test_contact.save_contact()

        contact_exists = Contact.contact_exists("0711223344")

        self.assertTrue(contact_exists)

    def tearDown(self):
        '''
        tearDown method that helps clean up after each test has run.
        '''
        Contact.contact_list = []

    def test_save_multiple_contacts(self):
        '''
        test_save_multiple_contacts test case to test if we can save multiple contact objects into our contact_list
        '''
        self.new_contact.save_contact()
        Test_contact = Contact("Test","user","0712345678","*****@*****.**")
        Test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list),2)

    def test_delete_contact(self):
        '''
        test_delete_contact test case to test if we can remove a contact object from our contact list
        '''
        self.new_contact.save_contact()
        Test_contact = Contact("Test","user","0712345678","*****@*****.**")
        Test_contact.save_contact()

        self.new_contact.delete_contact() #deleting a contact object
        self.assertEqual(len(Contact.contact_list),1)

    def test_find_contact_by_number(self):
        '''
        test_find_contact_by_number test case to test if we can find a contact object by phone number.
        '''
        self.new_contact.save_contact()
        Test_contact = Contact("Test","user","0712345678","*****@*****.**")
        Test_contact.save_contact()

        found_contact = Contact.find_by_number("0712345678")
        self.assertEqual(found_contact.email,Test_contact.email)

    def test_display_all_contacts(self):
        '''
        test_dislplay_all_contacts test case to test if we can be able to display all contacts
        '''

        self.assertEqual(Contact.display_contacts(),Contact.contact_list)

    def test_copy_email(self):
        '''
        test_copy_self test case to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0714895623")

        self.assertEqual(self.new_contact.email,pyperclip.paste())
示例#18
0
class TestContact(unittest.TestCase):
    
    def setUp(self):
        self.new_contact = Contact('Shiko', 'Kimita', '0780047102', '*****@*****.**')# creating the contact object

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, 'Shiko')
        self.assertEqual(self.new_contact.last_name, 'Kimita')
        self.assertEqual(self.new_contact.phone_number,'0780047102')
        self.assertEqual(self.new_contact.email,'*****@*****.**')

    def tearDown(self):
        '''
        tearDown method that does cleanup after each test case has run
        '''
        Contact.contact_list = []

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into the contact list
        '''
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list),1)

    def test_save_multiple_contact(self):
            '''
            test_save_multiple_contact to check if we can save multiple contact objects to our contact_list
            '''
            self.new_contact.save_contact()
            test_contact = Contact("Test", "user", "0721216565", "*****@*****.**")
            test_contact.save_contact()
            self.assertEqual(len(Contact.contact_list),2)

    def test_delete_test(self):
            '''
            test_delete_test to test if we can remove a contact from our contact list
            '''
            self.new_contact.save_contact()
            test_contact = Contact("Test", "user", "0734499942", "*****@*****.**")
            test_contact.save_contact()

            self.new_contact.delete_contact()
            self.assertEqual(len(Contact.contact_list),1)

    def test_find_contact_by_number(self):
            '''
            test_find_contact_by_number tests to check if we can find a contact by number and display the information
            '''

            self.new_contact.save_contact()
            test_contact = Contact("Kijo", "Kimita", "0720327460", "*****@*****.**")
            test_contact.save_contact()

            found_contact = Contact.find_by_number("0720327460")
            self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a boolean if we cannot find a contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact ("Kare", "Kimita","0780047102","*****@*****.**")
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0780047102")
        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method taht returns a list of all the contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0780047102")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#19
0
class TestContact(unittest.TestCase):
    def setUp(self):
        self.new_contact = Contact("June", "James", "123456785",
                                   "*****@*****.**")

    def test_init(self):
        self.assertEqual(self.new_contact.first_name, "June")
        self.assertEqual(self.new_contact.last_name, "James")
        self.assertEqual(self.new_contact.phone_number, "123456785")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    """
    Args:unittest.TestCase: TestCase class that helps in creating test cases
    """

    def test_save_contact(self):
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_save_multiple_contact(self):
        '''
        test_save_multiple_contact to check if we can save multiple contact
        objects to our contact_list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    # setup and class creation up here
    def tearDown(self):
        '''
            tearDown method that does clean up after each test case has run.
            '''
        Contact.contact_list = []


# other test cases here

    def test_save_multiple_contact(self):
        '''
        test_save_multiple_contact to check if we can save multiple contact
        objects to our contact_list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    # More tests above
    def test_delete_contact(self):
        '''
        test_delete_contact to test if we can remove a contact from our contact list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a Boolean  if we cannot find the contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0712345678")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#20
0
class TestContact(unittest.TestCase):
    '''
    Test class that defines test cases for the contact class behaviours.

    Args:
        unittest.TestCase: TestCase class that helps in creating test classes

    '''
    def setUp(self):
        '''
        Set up method to run before eact test cases.

        '''
        self.new_contact = Contact('James', 'Muriuki', '0712345678',
                                   '*****@*****.**')  # create contact object

    def tearDown(self):
        '''
        tearDown method that does clean up after each test case has run.
        '''
        Contact.contact_list = []

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_contact.first_name, 'James')
        self.assertEqual(self.new_contact.last_name, 'Muriuki')
        self.assertEqual(self.new_contact.phone_number, '0712345678')
        self.assertEqual(self.new_contact.email, '*****@*****.**')

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into the contact list
        '''
        self.new_contact.save_contact()  # saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

    def test_save_multiple_contact(self):
        '''
        test_save_multiple_contact to check if we can save multiple contact objects to our contact list
        '''

        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
        test_delete_contact to test if we an remove a contact from our contact list
        '''
        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0712345678',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact('Test', 'user', '0711223344',
                               '*****@*****.**')  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number('0711223344')
        self.assertEqual(found_contact.email, test_contact.email)
class TestContact(unittest.TestCase):
    '''
    Test class that define test case for the contact class behaviours.
    
    Args:
    unittest.TestCase class that helps in creating test cases
    '''
    def setUp(self):
        '''
        set up method to run before each test cases
        '''
        self.new_contact = Contact("james", "Muriuki", "07030538879",
                                   "*****@*****.**")

    def test_init(self):

        self.assertEqual(self.new_contact.first_name, "james")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "07030538879")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into the contact list
        '''
        self.new_contact.save_contact()  # saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        '''
        tearDown method that does clean up after each test has run.
        '''
        Contact.contact_list = []

    # other test cases here

    def test_save_multiple_contact(self):
        '''
        test_save_multiple_contact to check if we can save multiple contact
        objects to our contact_list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
        test_delete_contact to test if we can remove a contact from our contact list
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678", "*****@*****.**")
        test_contact.save_contact()

        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678", "*****@*****.**")
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0712345678")
        self.assertEqual(found_contact.email, test_contact.email)
示例#22
0
class TestContact(unittest.TestCase):
    '''
    Test class that defines test cases for the contact class behaviours.

    Args:
        unittest.TestCase: TestCase class that helps in creating test cases
    '''

    # Items up here .......

    def setUp(self):
        '''
        Set up method to run before each test cases.
        '''
        self.new_contact = Contact("James", "Muriuki", "0712345678",
                                   "*****@*****.**")  # create contact object

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_contact.first_name, "James")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "0712345678")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into
         the contact list
        '''
        self.new_contact.save_contact()  # saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        '''
            tearDown method that does clean up after each test case has run.
            '''
        Contact.contact_list = []


# other test cases here

    def test_save_multiple_contact(self):
        '''
            test_save_multiple_contact to check if we can save multiple contact
            objects to our contact_list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
            test_delete_contact to test if we can remove a contact from our contact list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exists(self):
        '''
        test to check if we can return a Boolean  if we cannot find the contact.
        '''

        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)

    def test_copy_email(self):
        '''
        Test to confirm that we are copying the email address from a found contact
        '''

        self.new_contact.save_contact()
        Contact.copy_email("0712345678")

        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#23
0
class TestContact(unittest.TestCase):
    """
    TestContact is a subclass (of TestCase) that defines test cases for the
    Contact class behaviors.
    TestCase is the parent class which helps create test cases.
    """
    def setUp(self):
        """
        setUp() method to run before each test case.
        """
        self.new_contact = Contact("Manuel","Sande","3153806748","*****@*****.**");

    def tearDown(self):
        """
        tearDown() method that runs after each test case.
        """
        Contact.contactList = [];

    def test_init(self):
        """
        test_init() test case to test if our object is being instantiated
        correctly.
        """
        self.assertEqual(self.new_contact.firstName,"Manuel")
        self.assertEqual(self.new_contact.lastName,"Sande")
        self.assertEqual(self.new_contact.phoneNumber,"3153806748")
        self.assertEqual(self.new_contact.email,"*****@*****.**")

    def test_save_contact(self):
        """
        test_save_contact() test case to test if contact object is saved
        to contact list.
        """
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contactList),1)

    def test_save_multiple_contact(self):
        """
        method test_save_multiple_contact() checks if we can save multiple
        contact objects to our contactList[].
        """
        self.new_contact.save_contact()
        test_contact = Contact("Ednas","Nell","3806743158","*****@*****.**");
        test_contact.save_contact()
        self.assertEqual(len(Contact.contactList),2)

    def test_delete_contact(self):
        """
        test_delete_contact() tests if we can delete a contact from our
        contact list.
        """
        self.new_contact.save_contact()
        test_contact = Contact("Ednas","Nell","3806743158","*****@*****.**");
        test_contact.save_contact()

        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contactList),1)

    def test_find_contact_by_number(self):
        """
        test_find_contact_by_number() tests if we can find a contact by phone
        number and display information
        """
        self.new_contact.save_contact()
        test_contact = Contact("Ednas","Nell","3806743158","*****@*****.**");
        test_contact.save_contact()

        found_contact = Contact.find_by_number("3806743158")
        self.assertEqual(found_contact.email,test_contact.email)

    def test_contact_exists(self):
        """return a boolean if contact is not found"""
        self.new_contact.save_contact()
        test_contact = Contact("Ednas","Nell","3806743158","*****@*****.**");
        test_contact.save_contact()

        contactExists = Contact.contact_exists("3806743158")
        self.assertTrue(contactExists)

    def test_display_contacts(self):
        self.assertEqual(Contact.display_contacts(),Contact.contactList)

    def test_copy_email(self):
        self.new_contact.save_contact()
        Contact.copy_email("3153806748")
        self.assertEqual(self.new_contact.email, pyperclip.paste())
示例#24
0
class TestContact(unittest.TestCase):
    '''
    Test class that defines test cases for the contact class behaviours.

    Args:
        unittest.TestCase: TestCase class that helps in creating test cases
    '''
    def setUp(self):
        '''
        Set up method to run before each test cases.
        '''
        self.new_contact = Contact(
            "Eva", "Maina", "0722811823",
            "*****@*****.**")  # create contact object

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''

        self.assertEqual(self.new_contact.first_name, "Eva")
        self.assertEqual(self.new_contact.last_name, "Maina")
        self.assertEqual(self.new_contact.phone_number, "0722811823")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into
         the contact list
        '''
        self.new_contact.save_contact()  # saving the new contact
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        '''
            tearDown method that does clean up after each test case has run.
            '''
        Contact.contact_list = []

    def test_save_multiple_contact(self):
        '''
            test_save_multiple_contact to check if we can save multiple contact
            objects to our contact_list
            '''
        self.new_contact.save_contact()  #saving Record 1

        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact

        test_contact.save_contact()  #saving Record 2
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
            test_delete_contact to test if we can remove a contact from our contact list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        self.new_contact.delete_contact()  # Deleting a contact object
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)
示例#25
0
class TestContact(unittest.TestCase):
    def setUp(self):

        self.new_contact = Contact("james", "Muriuki", "0712345678",
                                   "*****@*****.**")

    def tearDown(self):
        '''
            tearDown method that does clean up after each test case has run.
            '''
        Contact.contact_list = []

    def test_init(self):
        '''
        test_init test case to test if the object is initialized properly
        '''
        self.assertEqual(self.new_contact.first_name, "james")
        self.assertEqual(self.new_contact.last_name, "Muriuki")
        self.assertEqual(self.new_contact.phone_number, "0712345678")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        test_save_contact test case to test if the contact object is saved into
         the contact list
        '''
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_multiple_contact(self):
        '''
            test_save_multiple_contact to check if we can save multiple contact
            objects to our contact_list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678", "*****@*****.**")
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)

    def test_delete_contact(self):
        '''
            test_delete_contact to test if we can remove a contact from our contact list
            '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678", "*****@*****.**")
        test_contact.save_contact()

        self.new_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def test_find_contact_by_number(self):
        '''
        test to check if we can find a contact by phone number and display information
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344", "*****@*****.**")
        test_contact.save_contact()

        found_contact = Contact.find_by_number("0711223344")

        self.assertEqual(found_contact.email, test_contact.email)

    def test_contact_exist(self):
        '''
        test to check if we can return a Boolean  if we cannot find the contact.
        '''
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0711223344",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()

        contact_exists = Contact.contact_exist("0711223344")

        self.assertTrue(contact_exists)

    def test_display_all_contacts(self):
        '''
        method that returns a list of all contacts saved
        '''

        self.assertEqual(Contact.display_contacts(), Contact.contact_list)