コード例 #1
0
    def test_get_category_by_user_id_and_name(self):
        userData = {'email': 'test', 'password': '******', 'username': '******'}
        user = User(**userData).create()

        categoryData = {'user_id': user.user_id, 'name': 'test_category'}
        category = Category(**categoryData).create()
        result_category = Category.getCategoryByUserIdAndName(
            user.user_id, category.name)
        assert result_category == category
コード例 #2
0
 def createCategory(json):
     valid_params = verify_parameters(json, Category.REQUIRED_PARAMETERS)
     if valid_params:
         try:
             category_exists = Category.getCategoryByUserIdAndName(json['user_id'], json['name'])
             if category_exists:
                 return jsonify(message="The category you tried to create already exsists."), HttpStatus.BAD_REQUEST
             category = Category(**valid_params).create()
             category_dict = to_dict(category)
             result = {
                 "message": "Success!",
                 "category": category_dict,
             }
             return jsonify(result), HttpStatus.CREATED
         except Exception as err:
             return jsonify(message="Server error!", error=err.__str__()), HttpStatus.INTERNAL_SERVER_ERROR # pragma: no mutate
     else:
         return jsonify(message="Bad Request!"), HttpStatus.BAD_REQUEST