def setup_class(cls): user_controller = UserController() user_controller.delete_every_user() test_user_dict = { "username": "******", "password": "******", "reCaptchaResponse": "asd" } requests.post('http://127.0.0.1:{}/register'.format(cls.PORT), json=test_user_dict) login_response = requests.post('http://127.0.0.1:{}/login'.format( cls.PORT), json=test_user_dict) jwt = login_response.json()['accessToken'] refresh_jwt = login_response.json()['refreshToken'] cls.headers = {"Authorization": "Bearer {}".format(jwt)} cls.refresh_headers = { "Authorization": "Bearer {}".format(refresh_jwt) }
class Register(Resource): def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error @errorhandler.bad_login_or_register_request @errorhandler.user_already_exists def post(self): request_body_dict = request.json self.user_controller.create_user(request_body_dict) return self.response_creator.created()
def func_wrapper(*args, **kwargs): from app.shared.response import ResponseCreator from app.authentication.controller import UserController response_creator = ResponseCreator() api_key = request.headers.get('x-api-key') user_controller = UserController() if not user_controller.is_api_key_valid(api_key): return response_creator.invalid_api_key() return func(*args, **kwargs)
class Account(Resource): decorators = [flask_jwt_extended.jwt_required] def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error @errorhandler.user_does_not_exist def delete(self): username = flask_jwt_extended.get_jwt_identity() self.user_controller.delete_user(username) return self.response_creator.ok()
def setup_class(cls): cls.sample_video_dict = { "closeTimeStamp": 1511095414, "title": "A.Simpson.csalad.8x11.DVDrip.XviD.CUSTOM.HunDub-RH.avi", "lastPosition": 669, "duration": 1313 } cls.sample_video_dict2 = { "closeTimeStamp": 1511095404, "title": "A.Simpson.csalad.8x12.DVDrip.XviD.CUSTOM.HunDub-RH.avi", "lastPosition": 659, "duration": 1323 } cls.sample_videos = [cls.sample_video_dict, cls.sample_video_dict2] cls.video_controller = VideoController() cls.user_controller = UserController() cls.user_controller.delete_every_user() test_user_dict = { 'username': '******', 'password': '******' } cls.user_controller.create_user(test_user_dict) cls.user_obj = cls.user_controller.get_user_by_username('testuser')
class Login(Resource): def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @staticmethod def get_tokens_dict(username): tokens_dict = { 'accessToken': flask_jwt_extended.create_access_token(identity=username), 'refreshToken': flask_jwt_extended.create_refresh_token(identity=username) } return tokens_dict @errorhandler.invalid_recaptcha @errorhandler.internal_server_error @errorhandler.bad_login_or_register_request @errorhandler.unauthorized def post(self): request_body_dict = request.json username, password = request_body_dict['username'], request_body_dict[ 'password'] if self.user_controller.is_username_password_valid(username, password): tokens_json = json.dumps(self.get_tokens_dict(username)) self.response_creator.create_response(tokens_json) return self.response_creator.response_obj return self.response_creator.unauthorized()
class ApiKey(Resource): decorators = [flask_jwt_extended.jwt_required] def __init__(self): self.user_controller = UserController() self.response_creator = ResponseCreator() @errorhandler.internal_server_error def get(self): current_user = flask_jwt_extended.get_jwt_identity() api_key = self.user_controller.get_api_key_by_username(current_user) return self.response_creator.create_response( json.dumps({"apiKey": api_key}))
class Videos(Resource): def __init__(self): self.video_controller = VideoController() self.response_creator = ResponseCreator() self.user_controller = UserController() @errorhandler.internal_server_error @errorhandler.invalid_api_key def post(self): api_key = request.headers.get('x-api-key') user = self.user_controller.get_user_by_api_key(api_key) self.video_controller.create_video(request.json, user) return self.response_creator.ok() @flask_jwt_extended.jwt_required @errorhandler.internal_server_error def get(self): username = flask_jwt_extended.get_jwt_identity() videos_dict = self.video_controller.get_videos_by_username(username) videos_json = json.dumps(videos_dict) return self.response_creator.create_response(videos_json)
def setup_class(cls): cls.user_controller = UserController()
def teardown_class(cls): user_controller = UserController() user_controller.delete_every_user() video_controller = VideoController() video_controller.delete_videos()
def teardown_class(cls): user_controller = UserController() user_controller.delete_every_user()
def __init__(self): self.video_controller = VideoController() self.response_creator = ResponseCreator() self.user_controller = UserController()