def tearDown(self): """Removes the testing user and game board from the database.""" # remove the user profile_db.remove_user(self.user_info) # remove the created games game_db.remove_game(self.game_id)
def delete(request): """ If the username has the given token, user's account is deleted. Else, UNAUTHORIZED error is returned. user_id: unique user identifier (same as username). token: authentication token that allow access to the user's account. :param request: POST request with fields 'user_id', 'token'. :return: success message, else error status. """ # user_name == user_id required_fields = ['user_id', 'token'] # Check if the post request contain the required fields if set(required_fields) != set(list(request.data.keys())): return Response({'error': str('Missing required fields!')}, status=status.HTTP_400_BAD_REQUEST) # POST Request content data = request.data # check for not allowed characters if check_special_characters(str( data['user_id'])) or check_special_characters(str(data['token'])): return Response({'error': str('Unaccepted character passed!')}, status=status.HTTP_400_BAD_REQUEST) # Here check if user_id matches the token with the database if not db.check_user(data['user_id'], data['token']): return Response({'error': str('UNAUTHORIZED')}, status=status.HTTP_401_UNAUTHORIZED) # Here remove the user's account from the database if not db.remove_user(data['user_id']): return Response( {'error': str('Error when removing the user account!')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response({'status': 'success'})
def tearDown(self): """Removes the testing users.""" # remove the users profile_db.remove_user(self.user_1_info) profile_db.remove_user(self.user_2_info)
def tearDown(self): """Removes the testing user from the database.""" profile_db.remove_user(self.user_info)
def tearDown(self): """ The data needed for homepage tests is removed -- no residual data """ mongo2.remove_user(self.user["user_id"])