Example #1
0
 def test_create_contact(self):
     # rewrite to so only having one field filled will pass
     contact = {'name': '', 'email': '', 'address': '', 'phone': ''}
     self.assertEqual(queries.create_contact(contact), "Invalid input")
     self.assertFalse(queries.create_contact(None))
     # test if name only
     contact['name'] = 'Bert'
     self.assertTrue(queries.create_contact(contact))
     # email only
     contact['name'] = ""
     contact['email'] = "*****@*****.**"
     self.assertEqual(queries.create_contact(contact), "Invalid input")
     # address only
     contact['email'] = ""
     contact['address'] = "123 easy street wealth OK"
     self.assertEqual(queries.create_contact(contact), "Invalid input")
     # phone only
     contact['address'] = ""
     contact['phone'] = "99999999999"
     self.assertEqual(queries.create_contact(contact), "Invalid input")
     #more than one field filled in
     contact['name'] = "Bob"
     contact['email'] = "uiouepi@uoiupe"
     self.assertEqual(queries.create_contact(contact), "Contact created.")
     queries.delete_contact('Bob')
Example #2
0
 def test_find_contact_by_email(self):
     self.assertEqual(queries.find_contact_by_email(None), "Invalid input")
     self.assertEqual(queries.find_contact_by_email(""), "Invalid input")
     self.assertEqual(queries.find_contact_by_email(self.contacts['email']),
                      "No contact with that email.")
     queries.create_contact(self.contacts)
     self.assertTrue(queries.find_contact_by_email(self.contacts['email']))
     queries.delete_contact(self.contacts['name'])
Example #3
0
 def test_find_contacts_by_address(self):
     self.assertEqual(queries.find_contact_by_address(None),
                      "Invalid input")
     self.assertEqual(queries.find_contact_by_address(""), "Invalid input")
     self.assertEqual(queries.find_contact_by_address(self.contacts),
                      "No contact with that address.")
     queries.create_contact(self.contacts)
     self.assertTrue(
         queries.find_contact_by_address(self.contacts['address']))
     queries.delete_contact(self.contacts['name'])
Example #4
0
 def test_find_contact_by_name(self):
     contact = {
         'name': 'Marc',
         'email': '*****@*****.**',
         'phone': '',
         'address': ''
     }
     queries.create_contact(contact)
     self.assertTrue(queries.find_contact_by_name("Marc"))
     self.assertEqual(queries.find_contact_by_name(None), "Invalid input")
     self.assertEqual(queries.find_contact_by_name(""), "Invalid input")
     queries.delete_contact('Marc')
Example #5
0
 def test_delete_contact(self):
     contact = {
         'name': 'Bob',
         'phone': '99999999999',
         'email': '',
         'address': ''
     }
     queries.create_contact(contact)
     self.assertTrue(queries.delete_contact(""))
     self.assertEqual(queries.delete_contact(None), "Invalid input")
     self.assertEqual(queries.delete_contact(contact['name']),
                      "Contact deleted")
     self.assertEqual(queries.delete_contact('Joe'),
                      "No contact by the name Joe")
Example #6
0
 def test_find_contact_by_phonenumber(self):
     contact = {
         'name': 'Marc',
         'email': 'dklf;[email protected]',
         'phone': '99999999999',
         'address': ''
     }
     self.assertEqual(queries.find_contact_by_phoneNumber(None),
                      "Invalid input")
     self.assertEqual(queries.find_contact_by_phoneNumber(""),
                      "Invalid input")
     self.assertEqual(queries.find_contact_by_phoneNumber(contact['phone']),
                      "No contact with 99999999999 as a number")
     queries.create_contact(contact)
     self.assertTrue(queries.find_contact_by_phoneNumber(contact['phone']))
     queries.delete_contact(contact['name'])
Example #7
0
 def test_edit_contact(self):
     contact = {
         'name': 'Bob',
         'email': '*****@*****.**',
         'phone': '',
         'address': ''
     }
     queries.create_contact(contact)
     self.assertEqual(queries.edit_contact(None), "Invalid input")
     self.assertEqual(queries.edit_contact(""), "Invalid input")
     # what if name was changed
     contact['phone'] = '99999999999'
     self.assertEqual(queries.edit_contact(contact),
                      "Contact has been edited.")
     queries.delete_contact('Bob')
     contact['name'] = ""
     contact['email'] = ""
     self.assertEqual(queries.edit_contact(contact),
                      "No contact by that name")
Example #8
0
def deleteContact():

    """
    This function is used delete the contact which is already present.

    :return: On successful deletion it returns 200 else returns 404

    """
    result = {}
    try:

        email=0
        new_req = request.get_json()

        logs = {}
        logs["TIME"] = "{0}".format(datetime.datetime.isoformat(datetime.datetime.now()))
        logs["@request"] = "{0}".format(new_req)
        LOGGER.info(json.dumps(logs))


        if "email" in new_req:
            email = new_req["email"]

        if queries.contact_exists(email):
            delete_query=queries.delete_contact(email)
        else:
            delete_query=0

        if delete_query:
            message="Deletion successful."
            code=200

        else:
            message = "Deletion Failed."
            code = 201


        result["data"] = {}
        result["data"]["message"] ="{0}".format(message)
        result["code"] = code
        return jsonify(result)

    except:
        result["code"] = 404
        result["data"] = {}
        logs = {}
        logs["TIME"] = "{0}".format(datetime.datetime.isoformat(datetime.datetime.now()))
        logs["message"] = "Insertion failed."
        logs["TraceBack"] = traceback.print_exc()
        LOGGER.info(json.dumps(logs))
        return jsonify(result)