Exemplo n.º 1
0
 def test_find_contact_by_number(self):
     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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
class TestContact(unittest.TestCase):
    def setUp(self):
        '''
        set up method that should run before each test case
        '''
        self.new_contact = Contact("Maryanne", "Njeri", "071234567",
                                   "*****@*****.**")

    def test_init(self):
        '''
        this is to test whether the objects have been intialized properly
        '''
        self.assertEqual(self.new_contact.first_name, "Maryanne")
        self.assertEqual(self.new_contact.last_name, "Njeri")
        self.assertEqual(self.new_contact.phone_number, "071234567")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        tesy whether conatcts are saved succesfully
        '''
        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",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 2)
Exemplo n.º 4
0
 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())
Exemplo n.º 5
0
 def test_contact_exists(self):
     test_contact = Contact("Test", "user", "0711223344",
                            "*****@*****.**")  # new contact
     test_contact.save_contact()
     contact_exists = Contact.contact_exists("0711223344")
     # Checks whether the value returned is true...
     self.assertTrue(contact_exists)
Exemplo n.º 6
0
 def test_delete_contact(self):
     # You've saved two contacts
     self.new_contact.save_contact()
     test_contact = Contact("Test", "user", "0712345678",
                            "*****@*****.**")  # new contact
     test_contact.save_contact()
     self.new_contact.delete_contact()
     self.assertEqual(len(Contact.contact_list), 1)
Exemplo n.º 7
0
    def contact_update(self):

        try:

            self.selected_item = self.listbox.selection()[0]
            values = tuple(self.listbox.item(self.selected_item)['values'])
            self.update = Contact(self)
            self.update.contact_update_form(values[0])

        except IndexError:
            msgbox.showerror("error", "First Select the Item")
    def new_contact(self):

        name = input("Name: ")
        phone = input("Phone: ")
        email = input("Email: ")

        person = Contact(name, phone, email)
        self.contact_list.append(person)

        print("The entry has been added")
    def change_contact(self):
        cname = input("Enter a name: ")

        for contact in self.contact_list:
            if cname == contact.name:
                self.delete_contact(cname)
                name = input("Name: ")
                phone = input("Phone: ")
                email = input("Email: ")

                person = Contact(name, phone, email)
                self.contact_list.append(person)
Exemplo n.º 10
0
class MainWindow(tk.Tk):
    def __init__(self):
        super().__init__()
        self.db = DB()
        self.title("Contact-Book")
        self.geometry("1100x600")
        self.resizable(False, False)
        self.label_0 = tk.Label(self,
                                text='!!!!WELCOME TO THE CONTACT MANAGER!!!!',
                                width=50,
                                font=("bold", 20))
        self.label_0.place(x=100, y=43)

        self.label_1 = tk.Label(self,
                                text='Your Contact List',
                                width=50,
                                font=("bold", 20))
        self.label_1.place(x=100, y=103)

        self.scrollbar = ttk.Scrollbar(self)
        self.scrollbar.pack(side=RIGHT, fill=Y)
        self.cols = ('ID', 'Name', 'Gender', 'Email', 'Phone', 'Type',
                     'Address', 'Date Time')
        self.listbox = ttk.Treeview(self, columns=self.cols, show="headings")

        for col in self.cols:
            self.listbox.heading(col, text=col)

        self.listbox.place(x=10, y=163)
        self.listbox.column(self.cols[0], width=35)
        self.listbox.column(self.cols[1], width=150)
        self.listbox.column(self.cols[2], width=60)
        self.listbox.column(self.cols[3], width=220)
        self.listbox.column(self.cols[4], width=150)
        self.listbox.column(self.cols[5], width=70)
        self.listbox.column(self.cols[6], width=220)
        self.listbox.column(self.cols[7], width=160)

        self.listbox.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.listbox.yview)
        self.scrollbar.config(command=self.listbox.xview)

        self.search_label = tk.Label(self,
                                     text='Search By Name',
                                     width=20,
                                     font=("bold", 10))
        self.search_label.place(x=36, y=420)

        self.search_entry = ttk.Entry(self)
        self.search_entry.place(x=200, y=420)

        sort_list = ['A', 'Name', 'Id', 'Address', 'Date']
        self.sort_type = tk.StringVar()
        droplist = ttk.OptionMenu(self, self.sort_type, *sort_list)
        droplist.config(width=7)
        self.sort_type.set('Sort By')
        droplist.place(x=970, y=383)

        tk.Button(self,
                  text='Create Contact',
                  command=self.contact_create,
                  width=15,
                  bg='green',
                  fg='white',
                  font=("bold", 10)).place(x=50, y=500)
        tk.Button(self,
                  text='Show Contact List',
                  command=self.contact_list,
                  width=15,
                  bg='blue',
                  fg='white',
                  font=("bold", 10)).place(x=270, y=500)
        tk.Button(self,
                  text='Update Contact ',
                  command=self.contact_update,
                  width=15,
                  bg='orange',
                  fg='white',
                  font=("bold", 10)).place(x=490, y=500)
        tk.Button(self,
                  text='Delete Contact',
                  command=self.contact_delete,
                  width=15,
                  bg='red',
                  fg='white',
                  font=("bold", 10)).place(x=710, y=500)
        tk.Button(self,
                  text='Search',
                  command=self.search_contact,
                  width=10,
                  bg='yellow',
                  fg='white',
                  font=("bold", 10)).place(x=400, y=415)

    def contact_create(self):
        self.create = Contact(self)
        self.create.contact_create_form()

    def contact_list(self):
        sort_type = self.sort_type.get()
        if sort_type == 'Name':
            self.sort_by_name()

        elif sort_type == 'Address':
            self.sort_by_address()

        elif sort_type == 'Id':
            self.sort_by_id()

        elif sort_type == 'Date':
            self.sort_by_date()

        else:
            self.contact = self.db.list_contact()
            for i in self.listbox.get_children():
                self.listbox.delete(i)

            for c in self.contact:
                self.listbox.insert("",
                                    "end",
                                    values=(c['id'], c['name'], c['gender'],
                                            c['email'], c['phone'], c['Type'],
                                            c['address'], c['date']))

    def contact_update(self):

        try:

            self.selected_item = self.listbox.selection()[0]
            values = tuple(self.listbox.item(self.selected_item)['values'])
            self.update = Contact(self)
            self.update.contact_update_form(values[0])

        except IndexError:
            msgbox.showerror("error", "First Select the Item")

    def contact_delete(self):
        try:
            if msgbox.askyesno("Delete Contact?",
                               "Do you really want to delete?"):

                self.selected_item = self.listbox.selection()[0]
                values = tuple(self.listbox.item(self.selected_item)['values'])
                self.listbox.delete(self.selected_item)
                self.db.delete(values[0])
                msgbox.showinfo("deleted", "Successfully Deleted")

            else:
                pass

        except IndexError:
            msgbox.showerror("error", "First Select the Item")

    def on_closing(self):
        if msgbox.askokcancel("Quit", "Do you want to quit?"):
            del self.db
            self.destroy()

    def search_contact(self):
        self.contact_name = self.search_entry.get()
        self.result = self.db.search(self.contact_name)

        for i in self.listbox.get_children():
            self.listbox.delete(i)

        if self.result == []:
            msgbox.showinfo('Not Found', "Search result not found")

        else:
            for c in self.result:
                self.listbox.insert("",
                                    "end",
                                    values=(c['id'], c['name'], c['gender'],
                                            c['email'], c['phone'], c['Type'],
                                            c['address'], c['date']))

    def sort_by_name(self):
        self.sort_name = self.db.sort_by_name()
        for i in self.listbox.get_children():
            self.listbox.delete(i)
        for c in self.sort_name:
            self.listbox.insert("",
                                "end",
                                values=(c['id'], c['name'], c['gender'],
                                        c['email'], c['phone'], c['Type'],
                                        c['address'], c['date']))

    def sort_by_address(self):
        self.sort_address = self.db.sort_by_address()
        for i in self.listbox.get_children():
            self.listbox.delete(i)
        for c in self.sort_address:
            self.listbox.insert("",
                                "end",
                                values=(c['id'], c['name'], c['gender'],
                                        c['email'], c['phone'], c['Type'],
                                        c['address'], c['date']))

    def sort_by_id(self):
        self.sort_id = self.db.sort_by_id()
        for i in self.listbox.get_children():
            self.listbox.delete(i)
        for c in self.sort_id:
            self.listbox.insert("",
                                "end",
                                values=(c['id'], c['name'], c['gender'],
                                        c['email'], c['phone'], c['Type'],
                                        c['address'], c['date']))

    def sort_by_date(self):
        self.sort_date = self.db.sort_by_date()
        for i in self.listbox.get_children():
            self.listbox.delete(i)
        for c in self.sort_date:
            self.listbox.insert("",
                                "end",
                                values=(c['id'], c['name'], c['gender'],
                                        c['email'], c['phone'], c['Type'],
                                        c['address'], c['date']))
Exemplo n.º 11
0
 def contact_create(self):
     self.create = Contact(self)
     self.create.contact_create_form()
Exemplo n.º 12
0
 def test_display_all_contacts(self):
     '''
     method that returns a list of all contacts saved
     '''
     self.assertEqual(Contact.display_contacts(), Contact.contact_list)
Exemplo n.º 13
0
 def setUp(self):
     '''
     set up method that should run before each test case
     '''
     self.new_contact = Contact("Maryanne", "Njeri", "071234567",
                                "*****@*****.**")
Exemplo n.º 14
0
class TestContact(unittest.TestCase):
    def setUp(self):
        '''
        set up method that should run before each test case
        '''
        self.new_contact = Contact("Maryanne", "Njeri", "071234567",
                                   "*****@*****.**")

    def test_init(self):
        '''
        this is to test whether the objects have been intialized properly
        '''
        self.assertEqual(self.new_contact.first_name, "Maryanne")
        self.assertEqual(self.new_contact.last_name, "Njeri")
        self.assertEqual(self.new_contact.phone_number, "071234567")
        self.assertEqual(self.new_contact.email, "*****@*****.**")

    def test_save_contact(self):
        '''
        tesy whether conatcts are saved succesfully
        '''
        self.new_contact.save_contact()
        self.assertEqual(len(Contact.contact_list), 1)

    def tearDown(self):
        '''
        this does clean up after each test case runs 
        '''
        Contact.contact_list = []

    def test_save_multiple_contacts(self):
        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):
        # You've saved two contacts
        self.new_contact.save_contact()
        test_contact = Contact("Test", "user", "0712345678",
                               "*****@*****.**")  # new contact
        test_contact.save_contact()
        self.new_contact.delete_contact()
        test_contact.delete_contact()
        self.assertEqual(len(Contact.contact_list), 0)

    def test_find_contact_by_number(self):
        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_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):
        '''
        method that returns a list of all contacts saved
        '''
        self.assertEqual(Contact.display_contacts(), Contact.contact_list)
Exemplo n.º 15
0
 def test_save_multiple_contacts(self):
     self.new_contact.save_contact()
     test_contact = Contact("Test", "user", "0712345678",
                            "*****@*****.**")  # new contact
     test_contact.save_contact()
     self.assertEqual(len(Contact.contact_list), 2)
Exemplo n.º 16
0
def create_contact(fname, lname, phone, email):
    new_contact = Contact(fname, lname, phone, email)
    return new_contact
Exemplo n.º 17
0
def display_contacts():
    return Contact.display_contacts()
Exemplo n.º 18
0
def find_contact(number):
    return Contact.find_by_number(number)