def add_category():
    new_category = request.get_json()
    new_category = Category (
        category_name = new_category.get("category_name"),
    )
    new_category.add()
    return jsonify(new_category.to_dict())
Beispiel #2
0
 def test_get(self, init_db, category):
     """Test for get method
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             category (Category): Fixture to create a new category
     """
     assert Category.get(category.id) == category
Beispiel #3
0
    def test_child_relationships(self, init_db, category_with_favorites):
        """ Test child relationships of audit

            Args:
                init_db(SQLAlchemy): fixture to initialize the test database
                category_with_favorites (Category): Fixture to create a new category with favorites
        """

        category = Category.get(id=category_with_favorites.id)
        assert category.get_child_relationships() is not None
        assert len(category.favorites.all()) > 0
Beispiel #4
0
    def is_valid(self, data):
        """
        Ensure id fields reference existing resource
        and name supplied is not owned by an exising category

        Arguments:
            data (dict): request body

        Raises:
            ValidationError: Used to raise exception if request body is empty
        """
        if not data.get('name'):
            raise ValidationError(
                {'message': ERROR_MESSAGES['NOT_FOUND'].format('Name')}, 400)
        if data.get('id'):
            category = Category.get(data.get('id'))
            if category.name == data.get('name'):
                return

        validate_duplicate(Category,
                           'EXISTS',
                           'Category',
                           name=data.get('name'))
Beispiel #5
0
def validate_category_exist(value):
    category = Category.get(value)
    raise_error('NOT_FOUND_IDENTIFIER', 'category',
                fields=['categoryId']) if not category else None