def add_contacts(self, contact_name, contact_list):
        """

        :return: add a contact list consisting of new contact details
        """
        try:
            contact_dict = {
                "first_name": input("Enter your first name: "),
                "last_name": input("Enter your last name: "),
                "address": input("Enter your address: "),
                "city": input("Enter your city name: "),
                "state": input("Enter your state name: "),
                "zip": input("Enter your zip code: "),
                "phone_number": input("Enter your phone number: "),
                "email": input("Enter your email: ")
            }
            contact = Contacts(contact_dict)
            contact_list.append(contact)
            self.contact_book[contact_name] = contact_list
        except Exception as e:
            logger.error(e)
 def setUp(self):
     self.c = Contacts("test.db")
     self.c.populate_database()
class TestContacts(unittest.TestCase):
    def setUp(self):
        self.c = Contacts("test.db")
        self.c.populate_database()

    def tearDown(self):
        self.c.delete_database()

    def test_search(self):
        self.assertEquals(self.c.search("Simpson"), [])
        self.assertNotEquals(self.c.search("Frankfurt"), [])

    def test_insert(self):
        self.c.insert(
            name="Lisa Simpson",
            zipcode="80085",
            city="Springfield",
            street="742 Evergreen Terrace",
            phone="555 636",
            mobile="",
            email="*****@*****.**",
        )
        self.assertNotEquals(self.c.search("Evergreen Terrace"), [])

    def test_show_all(self):
        self.c.show_all()

    def test_delete_table(self):
        self.c.delete_table()
        with self.assertRaises(OperationalError):
            self.c.search("Frankfurt")

    def test_delete_database(self):
        self.c.populate_database()
        self.assertTrue(os.path.isfile("test.db"))
        self.c.delete_database()
        self.assertFalse(os.path.isfile("test.db"))
Exemple #4
0
 def setUp(self):
     self.c = Contacts("test.db")
     self.c.populate_database()
Exemple #5
0
class TestContacts(unittest.TestCase):
    def setUp(self):
        self.c = Contacts("test.db")
        self.c.populate_database()

    def tearDown(self):
        self.c.delete_database()

    def test_search(self):
        self.assertEquals(self.c.search("Simpson"), [])
        self.assertNotEquals(self.c.search("Frankfurt"), [])

    def test_insert(self):
        self.c.insert(name="Lisa Simpson",
                      zipcode="80085",
                      city="Springfield",
                      street="742 Evergreen Terrace",
                      phone="555 636",
                      mobile="",
                      email="*****@*****.**")
        self.assertNotEquals(self.c.search("Evergreen Terrace"), [])

    def test_show_all(self):
        self.c.show_all()

    def test_delete_table(self):
        self.c.delete_table()
        with self.assertRaises(OperationalError):
            self.c.search("Frankfurt")

    def test_delete_database(self):
        self.c.populate_database()
        self.assertTrue(os.path.isfile("test.db"))
        self.c.delete_database()
        self.assertFalse(os.path.isfile("test.db"))