Exemplo n.º 1
0
    def setUp(self) -> None:
        # get connection, 2 users, 2 polls (named/unnamed), 4 votes, third user for testing the logIn
        self.connection = MongoDB()
        self.user: User = User("mavroudo", "*****@*****.**", "1234")
        self.user2: User = User("charis", "*****@*****.**", "12345")
        self.user3: User = User("Stef", "*****@*****.**", "asdf")

        # user: UserWrapper = self.connection.userDB.deleteUser(self.user.mail)
        # user2: UserWrapper = self.connection.userDB.deleteUser(self.user2.mail)

        userWrapper: UserWrapper = self.connection.userDB.createNewUser(self.user.name, self.user.mail,
                                                                        self.user.password)
        self.assertIsNotNone(userWrapper.object)
        self.assertIsNotNone(userWrapper.object.session_id)
        self.session_id = userWrapper.object.session_id
        userWrapper2: UserWrapper = self.connection.userDB.createNewUser(self.user2.name, self.user2.mail,
                                                                         self.user2.password)
        self.assertIsNotNone(userWrapper2.object)
        self.assertIsNotNone(userWrapper2.object.session_id)
        self.session_id2 = userWrapper.object.session_id

        # get user id from session_id
        (user, self.user_id) = self.connection.userDB.getUserWithSessionId(self.session_id)
        self.assertIsNotNone(user)
        self.assertNotEqual(self.user_id, "")
        (user2, self.user_id2) = self.connection.userDB.getUserWithSessionId(self.session_id2)
        self.assertIsNotNone(user2)
        self.assertNotEqual(self.user_id2, "")
        # add polls
        self.poll: Poll = Poll("how cool are we?", ["A lot", "A lot but second", "same as 2"], named=True, unique=True,
                               creator_user_id=self.user_id)
        pollWrapper: PollWrapper = self.connection.pollsDB.createPoll(self.poll.question, self.poll.options,
                                                                      self.poll.named, self.poll.unique, self.user_id)
        self.assertTrue(pollWrapper.operationDone)
        self.assertIsNotNone(pollWrapper.object)
        self.poll_id = pollWrapper.pollId

        self.poll2_noNamed: Poll = Poll("how cool are we?", ["A lot", "A lot but second", "same as 2"], named=False,
                                        unique=True,
                                        creator_user_id=self.user_id)
        pollWrapper2: PollWrapper = self.connection.pollsDB.createPoll(self.poll2_noNamed.question,
                                                                       self.poll2_noNamed.options,
                                                                       self.poll2_noNamed.named,
                                                                       self.poll2_noNamed.unique, self.user_id)
        self.assertTrue(pollWrapper2.operationDone)
        self.assertIsNotNone(pollWrapper2.object)
        self.poll_id2 = pollWrapper2.pollId
        # add 2 votes for each
        voteWrapper: VotesWrapper = self.connection.votesDB.createVote(self.user_id, self.poll_id, self.poll.named, 0)
        self.assertTrue(voteWrapper.operationDone)
        voteWrapper: VotesWrapper = self.connection.votesDB.createVote(self.user_id2, self.poll_id, self.poll.named, 1)
        self.assertTrue(voteWrapper.operationDone)
        voteWrapper: VotesWrapper = self.connection.votesDB.createVote(self.user_id, self.poll_id2,
                                                                       self.poll2_noNamed.named, 0)
        self.assertTrue(voteWrapper.operationDone)
        voteWrapper: VotesWrapper = self.connection.votesDB.createVote(self.user_id2, self.poll_id2,
                                                                       self.poll2_noNamed.named, 1)
        self.assertTrue(voteWrapper.operationDone)
Exemplo n.º 2
0
    def setUp(self):
        self.connection = MongoDB()

        self.workout1 = {
            "name": 'Squat with weight',
            "category": 'Legs',
            "muscle_groups": ["Quads", "Glutes", "Core"],
            "advised_for": 'Women',
            "difficulty": 'Hard',
            "equipment": True,
            "sets": '4x15 10kg+10kg',
            "video_url": 'https://www.youtube.com/embed/MVMNk0HiTMg'
        }
        self.workout2 = {
            "name": 'Kickbacks',
            "category": 'Arms',
            "muscle_groups": ["Triceps"],
            "advised_for": 'Men',
            "difficulty": 'Medium',
            "equipment": True,
            "sets": '4x15 8kg+8kg',
            "video_url": 'https://www.youtube.com/embed/ShCYaoHmWmk'
        }

        workout_wrapper = self.connection.workoutDB.create(self.workout1)
        self.assertTrue(workout_wrapper.operationDone)
        self.workout1["_id"] = workout_wrapper.workout["_id"]
Exemplo n.º 3
0
    def setUp(self):
        self.connection = MongoDB()

        self.business1 = {
            "name": 'FitClub',
            "category": 'gym',
            "country": 'Greece',
            "city": 'Thessaloniki',
            "address": 'Diagora 20',
            "postal_code": '567 55',
            "phone_number": '2310 634590',
            "email": '*****@*****.**',
            "img_path": './assets/gym-preview.JPG',
            "services": ["service_1", "service_2"],
            "products": ['product_1', 'product_2']
        }
        self.business2 = {
            "name": 'Planet Fitness',
            "category": 'gym',
            "country": 'Greece',
            "city": 'Athens',
            "address": '3 Septembriou Street 6',
            "postal_code": '576 45',
            "phone_number": '202-555-0376',
            "email": '*****@*****.**',
            "img_path": './assets/gym-preview.JPG',
            "services": ["service_1", "service_2"],
            "products": ['product_1', 'product_2']
        }

        business_wrapper = self.connection.businessDB.create(self.business1)
        self.assertTrue(business_wrapper.operationDone)
        self.business1["_id"] = business_wrapper.business["_id"]
Exemplo n.º 4
0
    def setUp(self):
        self.connection = MongoDB()

        self.user1 = {
            "name" :     "Alexandros",
            "surname" :  "Wawaroutas",
            "email":     "*****@*****.**",
            "password":  "******",
            "birthdate": "27/02/1997",
            "role":      "admin"
        }
        self.user2 = {
            "name" :     "Georgios Alexandros",
            "surname" :  "Vavaroutas",
            "email":     "*****@*****.**", # same email
            "password":  "******",
            "birthdate": "27/02/1997",
            "role":      "admin"
        }
        self.user3 = { # new user
            "name" :     "Dimitrios",
            "surname" :  "Vrakas",
            "email":     "*****@*****.**",
            "password":  "******",
            "birthdate": "10/05/1977",
            "role":      "admin"
        }
        
        user_wrapper = self.connection.userDB.create(self.user1)
        self.assertTrue(user_wrapper.operationDone)
        self.user1["_id"] = user_wrapper.user["_id"]
        self.assertTrue(self.connection.userDB._verifyPassword(
                    user_wrapper.user["password"], self.user1["password"]))
        self.user1["password"] = user_wrapper.user["password"]
    def setUp(self) -> None:
        # get connection, create a user, get its session_id, create a Poll object
        self.connection = MongoDB()
        self.user: User = User("mavroudo", "*****@*****.**", "1234")

        userWrapper: UserWrapper = self.connection.userDB.createNewUser(
            self.user.name, self.user.mail, self.user.password)
        self.assertIsNotNone(userWrapper.object)
        self.assertIsNotNone(userWrapper.object.session_id)
        self.session_id = userWrapper.object.session_id
        # get user id from session_id
        (user, user_id) = self.connection.userDB.getUserWithSessionId(
            self.session_id)

        self.assertIsNotNone(user)
        self.assertNotEqual(user_id, "")
        self.poll: Poll = Poll("how cool are we?",
                               ["A lot", "A lot but second", "same as 2"],
                               named=True,
                               unique=True,
                               creator_user_id=user_id)
        pollWrapper: PollWrapper = self.connection.pollsDB.createPoll(
            self.poll.question, self.poll.options, self.poll.named,
            self.poll.unique, user_id)
        self.assertTrue(pollWrapper.operationDone)
        self.assertIsNotNone(pollWrapper.object)
        self.poll_id = pollWrapper.pollId
Exemplo n.º 6
0
def login():
    user = request.get_json()  # get username and password
 
    # connection with mongo sending user and getting answer if this user exists or not
    try:
        user_wrapper: UserWrapper = MongoDB.logIn(user)
    except TypeError as type_err:  # Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if type(user_wrapper.user) is not dict:
            return "Something is wrong with the database", 500
        if not user_wrapper.found:
            return "User does not exist", 404
        if not user_wrapper.operationDone:
            return "Wrong password", 401
        return jsonify(user={
            "_id": user_wrapper.user["_id"],
            "name": user_wrapper.user["name"],
            "surname": user_wrapper.user["surname"],
            "email": user_wrapper.user["email"],
            "privilegeLevel": user_wrapper.user["privilegeLevel"],
            "token": user_wrapper.user["token"],
            "favoriteWorkout": user_wrapper.user["favoriteWorkout"],
            "favoriteBusiness": user_wrapper.user["favoriteBusiness"]
        })
Exemplo n.º 7
0
 def decorated(*args, **kwargs):
     token = request.headers["Authorization"]
     if not token:
         return "token is missing", 401
     user_wrapper = MongoDB.getUser({"token": token})
     if not user_wrapper.found:
         return "token is invalid", 403
     return f(*args, **kwargs)
Exemplo n.º 8
0
def get_workouts():
    try:
        workout_list_wrapper: WorkoutListWrapper = MongoDB.getAllWorkouts()
    except:
        return "Bad error", 500
    else:
        if type(workout_list_wrapper.workout_list) is not list:
            return "Something is wrong with the database", 500
        return jsonify(data=workout_list_wrapper.workout_list)
Exemplo n.º 9
0
def getCities():
  try:
    cities_list = MongoDB.getCities()
  except:
    return "Bad error", 500
  else:
    if cities_list is None:
        return "Something is wrong with the database", 500
    return jsonify(data=cities_list)
Exemplo n.º 10
0
 def setUp(self) -> None:
     self.connection = MongoDB()  # this will connect to mongo
     self.user1 = User("mavroudo", "*****@*****.**", "1234")
     self.user2_same_mail = User("mavroudo2", "*****@*****.**", "4567")
     self.user3 = User("kalliopi", "*****@*****.**", "789")
     userWrapper: UserWrapper = self.connection.userDB.createNewUser(
         self.user1.name, self.user1.mail, self.user1.password)
     self.assertTrue(userWrapper.operationDone)
     self.session_id = userWrapper.object.session_id
Exemplo n.º 11
0
def delete_workouts():
    delete_query = request.get_json()
    try:
        deleted_successfull = MongoDB.deleteWorkouts(delete_query)
    except:
        return "Bad error", 500
    else:
        if not deleted_successfull:
            return "Could not delete workouts", 400
        return jsonify("Workouts deleted successfully")
Exemplo n.º 12
0
def manageAllBusinessesDisplay():
    #connection with mongo getting all the existed business entries
    try:
        business_wrapper_list : BusinessWrapper = MongoDB.getAllBusinesses()
    except:
        return "Bad error", 500
    else:
        if business_wrapper_list.business_list is None:
            return "Something is wrong with the database", 500
        if type(business_wrapper_list.business_list) is list and not business_wrapper_list.found and not business_wrapper_list.operationDone:
            return "Couldn't get businesses", 500
        return jsonify(businessList=business_wrapper_list.business_list)
Exemplo n.º 13
0
def removeFavoriteWorkout():
    business = request.get_json()
    try:
        favorite = MongoDB.removeFavoriteWorkout(business)
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if not favorite:
            return "Couldn't remove entry", 400
        return jsonify("Workout removal successful")
Exemplo n.º 14
0
def addFavoriteBusiness():
    business = request.get_json()
    try:
        favorite = MongoDB.addFavoriteBusiness(business)
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if not favorite:
            return "Couldn't add entry", 400
        return jsonify("Addition successful")
Exemplo n.º 15
0
def manageAllUsersDisplay():
    #connection with mongo getting all the existed user entries
    try:
        user_wrapper_list: UserListWrapper = MongoDB.getAllUsers()
    except:
        return "Bad error", 500
    else:
        if user_wrapper_list.user_list is None:
            return "Something is wrong with the database", 500
        if type(user_wrapper_list.user_list) is list and not user_wrapper_list.found and not user_wrapper_list.operationDone:
            return "Couldn't get users", 500
        return jsonify(userList=user_wrapper_list.user_list)
Exemplo n.º 16
0
def addFavoriteWorkout():
    workout=request.get_json() #get new workout
    #connection with mongo sending the filters and creating the workout
    try:
        favorite = MongoDB.addFavoriteWorkout(workout)
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if favorite is False:
            return ("Couldn't add entry"), 400
        return jsonify("Addition successful")
Exemplo n.º 17
0
def manageBusinessDelete():
    entries = request.get_json() #get entries for delete
    #connection with mongo sending the entry
    try:
        response = MongoDB.deleteBusinesses(entries)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if not response:
            return "Couldn't delete business entries", 500
        return jsonify("Deletion successful")
Exemplo n.º 18
0
def manageUserDelete():
    users=request.get_json() #get users for delete
    #connection with mongo sending the id
    try:
        response = MongoDB.deleteUsers(users)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if response is False:
            return "Coudn't delete user entries", 500
        return jsonify("Delete successful")
Exemplo n.º 19
0
def getMyBusiness():
    user = request.get_json()
    #connection with mongo sending the user and modifying the profile's details
    try:
        business_list_wrapper: BusinessListWrapper = MongoDB.getUserBusinesses(user)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if type(business_list_wrapper.business_list) is not list:
            return "Couldn't get users", 500
        return jsonify(data=business_list_wrapper.business_list)
Exemplo n.º 20
0
def displayFavoriteWorkout():
    user=request.get_json()
    #connection wit mongo sending the user and getting his favorite workout
    try:
        workout_list = MongoDB.getFavoriteWorkout(user)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if workout_list is None:
            return "Something is wrong with the database", 500
        else:
            return jsonify(workoutList=workout_list)
Exemplo n.º 21
0
def update_workout():
    new_workout = request.get_json()
    try:
        workout_wrapper: WorkoutWrapper = MongoDB.updateWorkout(new_workout)
    except TypeError as type_err:
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if type(workout_wrapper.workout) is not dict:
            return "Something is wrong with the database", 500
        if not workout_wrapper.found:
            return "Workout doesn't exist in the database", 404
        return jsonify("Workout update successfull")
Exemplo n.º 22
0
def displayFavoritePlaces():
    user=request.get_json()
    #connection wit mongo sending the user and getting his favorite places
    try:
        business_list = MongoDB.getFavoriteBusiness(user)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if business_list is None:
            return "Something is wrong with the database", 500
        else:
            return jsonify(businessList=business_list)
Exemplo n.º 23
0
def getWorkout():
    filters=request.get_json() #get chosen filters by user
    #connection with mongo sending the filters and getting the matched workout
    try:
        workout_wrapper_list : WorkoutListWrapper = MongoDB.workoutSearch(filters)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
        return "Bad error", 500
    else:
        if workout_wrapper_list.workout_list is None:
            return "Something is wrong with the database", 500
        if type(workout_wrapper_list.workout_list) is list and not workout_wrapper_list.found and not workout_wrapper_list.operationDone:
            return "Couldn't find workout with these filters", 404
        return jsonify(workoutList=workout_wrapper_list.workout_list)
Exemplo n.º 24
0
def displayMyprofile():
    user=request.get_json()
    #connection with mongo sending the user and modifying the profile's details
    try:
        user_wrapper: UserWrapper = MongoDB.getUser(user)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if user_wrapper.user is None:
            return "Something is wrong with the database", 500
        if type(user_wrapper.user) is dict and not user_wrapper.found and not user_wrapper.operationDone:
            return "User does not exist", 404
        return jsonify(user=user_wrapper.user)
Exemplo n.º 25
0
def manageUserModify():
    user=request.get_json() #get modifying user's details
    #connection with mongo sending the details of modified entry
    try:
        user_wrapper: UserWrapper = MongoDB.updateUser(user)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if user_wrapper.user is None:
            return "Something is wrong with the database", 500
        if type(user_wrapper.user) is dict and not user_wrapper.operationDone and not user_wrapper.found:
            return "Couldn't update user entry", 500
        return jsonify("Save successful")
Exemplo n.º 26
0
def search():
    filters=request.get_json() #get chosen filters by user
    #connection with mongo sending the fitlers and return the matched place
    try:
        business_wrapper_list : BusinessListWrapper = MongoDB.businessSearch(filters)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if business_wrapper_list.business_list is None:
            return "Something is wrong with the database", 500
        if type(business_wrapper_list.business_list) is list and not business_wrapper_list.found and not business_wrapper_list.operationDone:
            return "Couldn't find businesses with these filters", 404
        return jsonify(data=business_wrapper_list.business_list)
Exemplo n.º 27
0
def manageOneUserDisplay():
    user=request.get_json() #get user for display
    #connection with mongo getting the current user entry
    try:
        user_wrapper: UserWrapper = MongoDB.getUser(user_id)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if user_wrapper.user is None:
            return "Something is wrong with the database", 500
        if type(user_wrapper.user) is dict and not user_wrapper.operationDone and not user_wrapper.found:
            return "Couldn't find user", 500
        return jsonify(user=user_wrapper.user)
Exemplo n.º 28
0
def manageOneBusinessDisplay():
    entry=request.get_json() #get entry's id for display
    #connection with mongo getting all current business entry
    try:
        business_wrapper : BusinessWrapper = MongoDB.getBusiness(entry)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if business_wrapper.business is None:
            return "Something is wrong with the database", 500
        if type(business_wrapper.business) is dict and not business_wrapper.operationDone and not business_wrapper.found:
            return "Couldn't find business", 500
        return jsonify(business=business_wrapper.business)
Exemplo n.º 29
0
def deleteWorkout():
    workout=request.get_json() #get workout for delete
    #connection with mongo sending the filters and deleting the workout
    try:
        workout_wrapper : WorkoutWrapper = MongoDB.deleteWorkout(workout)
    except TypeError as type_err: #Checking for errors
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if workout_wrapper.workout is None:
            return "Something is wrong with the database", 500
        if workout_wrapper.found and not workout_wrapper.operationDone:
            return "Couldn't delete user", 500
        return jsonify("Delete successful")
Exemplo n.º 30
0
def create_workout():
    workout = request.get_json()
    try:
        workout_wrapper: WorkoutWrapper = MongoDB.createNewWorkout(workout)
    except TypeError as type_err:
        return str(type_err), 422
    except ValueError as value_err:
        return str(value_err), 422
    except:
        return "Bad error", 500
    else:
        if type(workout_wrapper.workout) is not dict:
            return "Something is wrong with the database", 500
        if workout_wrapper.found:
            return "Workout already exists", 409
        if not workout_wrapper.operationDone:
            return  "Couldn't create workout entry", 500
        return jsonify("Creation successful")