Exemplo n.º 1
0
    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')
Exemplo n.º 2
0
    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')
Exemplo n.º 3
0
def users(active_user):

    if active_user['admin']:
        return 'Only available for users!'

    users = User().show_users()
    return jsonify({"message": users})
Exemplo n.º 4
0
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})
Exemplo n.º 5
0
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})
Exemplo n.º 6
0
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})
Exemplo n.º 7
0
    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')
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
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})
Exemplo n.º 11
0
def logout_user(active_user):
    logouts = User().logout()
    return jsonify({"message": logouts})
Exemplo n.º 12
0
    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')
Exemplo n.º 13
0
def login():
    loging = User().login(request.json['username'], request.json['password'])
    return jsonify({"message": loging})
Exemplo n.º 14
0
 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')
Exemplo n.º 15
0
 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 ')
Exemplo n.º 16
0
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})
Exemplo n.º 17
0
def menu_getter(active_user):
    if active_user['admin']:
        return 'Only available for users!'

    get_menu = User().get_menu()
    return jsonify({"messages": get_menu})
Exemplo n.º 18
0
def signup():
    new_user = User().signup(request.json['username'],
                             request.json['password'], request.json['user_id'])
    return jsonify({"user": new_user})
Exemplo n.º 19
0
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})
Exemplo n.º 20
0
def user_logout(current_user):
    logouts = User().logout()
    return jsonify({"message": logouts})
Exemplo n.º 21
0
 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')