Coverage for views.py : 43%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
def verify_user_password(name, password):
user = User.query.get_or_404(id) result = user_schema.dump(user).data return result
def get(self): pagination_helper = PaginationHelper( request, query=User.query, resource_for_url='service.userlistresource', key_name='results', schema=user_schema) result = pagination_helper.paginate_query() return result
response = {'user': 'No input data provided'} return response, HttpStatus.bad_request_400.value return errors, HttpStatus.bad_request_400.value response = {'user': 'An user with the name {} already exists'.format(user_name)} return response, HttpStatus.bad_request_400.value user.check_password_strength_and_hash_if_ok(user_dict['password']) else: return {"error": error_message}, HttpStatus.bad_request_400.value except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.bad_request_400.value
notification = Notification.query.get_or_404(id) dumped_notification = notification_schema.dump(notification).data return dumped_notification
notification = Notification.query.get_or_404(id) notification_dict = request.get_json(force=True) print(notification_dict) if 'message' in notification_dict and notification_dict['message'] is not None: notification_message = notification_dict['message'] if not Notification.is_message_unique(id=0, message=notification_message): response = {'error': 'A notification with the message {} already exists'.format(notification_message)} return response, HttpStatus.bad_request_400.value notification.message = notification_message if 'ttl' in notification_dict and notification_dict['ttl'] is not None: notification.duration = notification_dict['duration'] if 'displayed_times' in notification_dict and notification_dict['displayed_times'] is not None: notification.displayed_times = notification_dict['displayed_times'] if 'displayed_once' in notification_dict and notification_dict['displayed_once'] is not None: notification.displayed_once = notification_dict['displayed_once'] == 'true' dumped_notification, dump_errors = notification_schema.dump(notification) if dump_errors: return dump_errors, HttpStatus.bad_request_400.value validate_errors = notification_schema.validate(dumped_notification) if validate_errors: return validate_errors, HttpStatus.bad_request_400.value try: notification.update() return self.get(id) except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.bad_request_400.value
notification = Notification.query.get_or_404(id) try: delete = notification.delete(notification) response = make_response() return response, HttpStatus.no_content_204.value except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.unauthorized_401.value
pagination_helper = PaginationHelper( request, query=Notification.query, resource_for_url='service.notificationlistresource', key_name='results', schema=notification_schema) pagination_result = pagination_helper.paginate_query() return pagination_result
notification_category_dict = request.get_json() if not notification_category_dict: response = {'message': 'No input data provided'} return response, HttpStatus.bad_request_400.value errors = notification_schema.validate(notification_category_dict) if errors: return errors, HttpStatus.bad_request_400.value notification_message = notification_category_dict['message'] if not Notification.is_message_unique(id=0, message=notification_message): response = {'error': 'A notification with the message {} already exists'.format(notification_message)} return response, HttpStatus.bad_request_400.value try: notification_category_name = notification_category_dict['notification_category']['name'] notification_category = NotificationCategory.query.filter_by(name=notification_category_name).first() if notification_category is None: # Create a new NotificationCategory notification_category = NotificationCategory(name=notification_category_name) orm.session.add(notification_category) # Now that we are sure we have a notification category, # we can create a new Notification notification = Notification( message=notification_message, ttl=notification_category_dict['ttl'], notification_category=notification_category) notification.add(notification) query = Notification.query.get(notification.id) dump_result = notification_schema.dump(query).data return dump_result, HttpStatus.created_201.value except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.bad_request_400.value
response = {'message': 'No input data provided'} return response, HttpStatus.bad_request_400.value return errors, HttpStatus.bad_request_400.value else: response = {'error': 'A category with the name {} already exists'.format(notification_category_name)} return response, HttpStatus.bad_request_400.value except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.bad_request_400.value
notification_category = NotificationCategory.query.get_or_404(id) try: notification_category.delete(notification_category) response = make_response() return response, HttpStatus.no_content_204.value except SQLAlchemyError as e: orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.unauthorized_401.value
response = {'message': 'No input data provided'} return response, HttpStatus.bad_request_400.value return errors, HttpStatus.bad_request_400.value except SQLAlchemyError as e: print("Error") print(e) orm.session.rollback() response = {"error": str(e)} return response, HttpStatus.bad_request_400.value
'/notification_categories/') '/notification_categories/<int:id>') '/notifications/') '/notifications/<int:id>') '/users/') '/users/<int:id>')
|