def test_login_works_well(self): #Checking if all inputs are filled results = User().login('quantum', '') self.assertEqual(results, 'Enter both username and password', msg='You need to enter both username and password') #Type check the data results1 = User().login(45, 1234567) self.assertEqual( results1, 'Please enter a string value for username and password')
def test_modify_order(self): Caterer().post_menu(7, "Ugali", 250, "lunch", "Monday") User().make_order(7, "Ugali", 250, "lunch", "Monday", 1, "quantum") #Check if meal exists results = User().modify_order(3, 3) self.assertEqual(results, 'Meal doesn\'t exists in orders!') #Modify meal results = User().modify_order(7, 3) self.assertEqual(results, 'Order modified Succesfully')
def users(active_user): if active_user['admin']: return 'Only available for users!' users = User().show_users() return jsonify({"message": users})
def users(current_user): if not current_user['admin']: return jsonify({'Message': 'You have no privilages to view this'}) users = User().show_users() return jsonify({"message": users})
def make_orders(current_user): if current_user['admin']: return jsonify({"message": 'Sorry you have no access Priviladges'}) new_order = User().make_order( request.json['meal_id'], request.json['meal_name'], request.json['price'], request.json['category'], request.json['day'], request.json['quantity'], request.json['username']) return jsonify({"messages": new_order})
def make_orders(active_user): if active_user['admin']: return 'Only available for users!' new_order = User().make_order( request.json['meal_id'], request.json['meal_name'], request.json['price'], request.json['category'], request.json['day'], request.json['quantity'], request.json['username']) return jsonify({"messages": new_order})
def test_create_users(self): #Test if any of the entered values are empty results = User().signup('', '1234567', 7624) self.assertEqual(results, 'Please fill all the details', msg='There is an empty input') #Type check the data results4 = User().signup(45, 1234567, 7624) self.assertEqual( results4, 'Please enter a string value for username and password') results5 = User().signup('quantum', '1234567', '9805') self.assertEqual(results5, 'User Id should be an integer!') #Creating a new user results1 = User().signup('quantum', '1234567', 7624) self.assertEqual(results1, 'User successfully created', msg='Successful registration')
def decorated(*args, **kwargs): token = None if 'Authorization' in request.headers: token = request.headers['Authorization'] if not token: return jsonify({"message": "Token is missing!"}), 401 try: data = jwt.decode(token, 'Quantum#@$%^^&$#@@') active = [ u for u in User().users if u["user_id"] == data["user_id"] ] current_user = active[0] except: return jsonify({"message": "Token is Invalid!"}), 401 return f(current_user, *args, **kwargs)
def decorated(*args, **kwargs): token = None if 'Authorization' in request.headers: token = request.headers['Authorization'] if not token: return jsonify({"message": "Token is missing!"}), 401 try: data = jwt.decode(token, 'secret_key') active = [ user1 for user1 in User().users if user1["user_id"] == data["user_id"] ] active_user = active[0] except: return jsonify({"message": "Token is Invalid!"}), 401 return f(active_user, *args, **kwargs)
def menu_getter(current_user): if current_user['admin']: return jsonify({"message": 'Sorry you have no access Priviladges'}) get_menu = User().get_menu() return jsonify({"messages": get_menu})
def logout_user(active_user): logouts = User().logout() return jsonify({"message": logouts})
def test_get_menu(self): #Post menu Caterer().post_menu(6, "Ugali", 300, "lunch", "Monday") results = User().get_menu() self.assertIsInstance(results, list, msg='Incorrect output type')
def login(): loging = User().login(request.json['username'], request.json['password']) return jsonify({"message": loging})
def test_user_login(self): #Creating a new user User().signup('test', '1234567', 7624) #Correct login from new user results = User().login('test', '1234567') self.assertIsInstance(results, str, msg='Incorrect output type')
def test_make_order(self): Caterer().post_menu(4, "Ugali", 250, "lunch", "Monday") results = User().make_order(4, "Ugali", 250, "lunch", "Monday", 1, "quantum") self.assertEqual(results, 'Meal successfully added ')
def modify_orders(current_user, orderId): if current_user['admin']: return jsonify({"message": 'Sorry you have no access Priviladges'}) mod = User().modify_order(orderId, request.json['quantity']) return jsonify({"messages": mod})
def menu_getter(active_user): if active_user['admin']: return 'Only available for users!' get_menu = User().get_menu() return jsonify({"messages": get_menu})
def signup(): new_user = User().signup(request.json['username'], request.json['password'], request.json['user_id']) return jsonify({"user": new_user})
def modify_orders(active_user, orderId): if active_user['admin']: return 'Only available for users!' mod = User().modify_order(orderId, request.json['quantity']) return jsonify({"messages": mod})
def user_logout(current_user): logouts = User().logout() return jsonify({"message": logouts})
def test_get_orders(self): Caterer().post_menu(4, "Ugali", 250, "lunch", "Monday") User().make_order(4, "Ugali", 250, "lunch", "Monday", 1, "quantum") results = Caterer().get_orders() self.assertIsInstance(results, list, msg='Incorrect output type')