async def add_pet(request: web.Request, body) -> web.Response:
    """Add a new pet to the store

    

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    """
    body = Pet.from_dict(body)
    return web.Response(status=200)
async def update_pet(request: web.Request, body) -> web.Response:
    """Update an existing pet

    

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    """
    body = Pet.from_dict(body)
    return web.Response(status=200)
Пример #3
0
    def test_update_pet(self):
        """Test case for update_pet

        Update an existing pet
        """
        body = Pet()
        response = self.client.open('/v2/pet',
                                    method='PUT',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Пример #4
0
    def test_add_pet(self):
        """Test case for add_pet

        Add a new pet to the store
        """
        body = Pet()
        response = self.client.open('/v2/pet',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Пример #5
0
def update_pet(pet):  # noqa: E501
    """Update an existing pet

     # noqa: E501

    :param pet: Pet object that needs to be added to the store
    :type pet: dict | bytes

    :rtype: Pet
    """
    if connexion.request.is_json:
        pet = Pet.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
Пример #6
0
def add_pet(pet):  # noqa: E501
    """Add a new pet to the store

     # noqa: E501

    :param pet: Pet object that needs to be added to the store
    :type pet: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        pet = Pet.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
def update_pet(body):  # noqa: E501
    """Update an existing pet

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
    """
    if connexion.request.is_json:
        body = Pet.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
def update_pet():  # noqa: E501
    """Update an existing pet

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: Pet
    """
    if connexion.request.is_json:
        body = Pet.from_dict(connexion.request.get_json())  # noqa: E501
        id = body.id
        name = body.name
        status = body.status
        category_id = body.category.id
        category_name = body.category.name
        tags = body.tags
        photoURLs = body.photo_urls
        pet_id = petstore.Pet.query.get(id)
        pet_n = petstore.Pet.query.filter_by(pet_name=name).first()

        if id is None:
            return "Pet ID is Required", 404

        if name is None:
            return "Pet Name is Required", 404

        if pet_n and pet_n.pet_name != pet_id.pet_name:
            return "Pet Name Already Exists", 409

        elif pet_id:
            statusdb = petstore.Status.query.filter_by(value=status).first()

            category_id_db = petstore.Category.query.filter_by(
                cat_name=category_name).first()
            category_name_db = petstore.Category.query.filter_by(
                id=category_id).first()

            if category_id_db is None and category_name_db is None:
                new_category = petstore.Category(category_id, category_name)
                petstore.db.session.add(new_category)
                petstore.db.session.commit()
            elif category_id_db and category_name_db is None:
                return "Category ID is Already Exists in Category Name = {}".format(
                    category_id_db.cat_name), 409
            elif category_id_db is None and category_name_db:
                return "Category name is Already Exists in ID = {}".format(
                    category_name_db.id), 409
            pet_id.pet_name = name
            pet_id.category_id = category_id
            pet_id.status_id = statusdb.id
            petstore.db.session.commit()

            if tags:
                for tag in tags:
                    tag_id = petstore.Tag.query.filter_by(id=tag.id).first()
                    tag_n = petstore.Tag.query.filter_by(
                        tag_name=tag.name).first()
                    if tag_id is None and tag_n is None:
                        new_tag = petstore.Tag(tag.id, tag.name)
                        petstore.db.session.add(new_tag)
                        petstore.db.session.commit()
                    elif tag_id and tag_n is None:
                        return "Tad ID Already Exists in {}. Can not Assign to New Tag Name".format(
                            tag_id.tag_name), 409
                    elif tag_id is None and tag_n:
                        return "Tag Name is Already Exists in {}. Can not Assign to New Tag ID".format(
                            tag_n.id), 409
                for tag in tags:
                    pet = petstore.Pet.query.filter_by(pet_name=name).first()
                    tag_db = petstore.Tag.query.filter_by(
                        tag_name=tag.name).first()

                    if tag_db and pet:
                        tag_db.tags.append(pet)
                        petstore.db.session.commit()
                    elif tag is None and pet is None:
                        return "Pet and Tag Does Not Exists", 404
                    elif pet is None:
                        return "Pet Does Not Exists", 404
                    elif tag_db is None:
                        return "Tag Does Not Exists", 404

            if photoURLs:
                for photoURL in photoURLs:
                    url = petstore.PhotoURL.query.filter_by(
                        url=photoURL).first()
                    if url is None:
                        new_url = petstore.PhotoURL(photoURL, id)
                        petstore.db.session.add(new_url)
                        petstore.db.session.commit()
        return body
def add_pet():  # noqa: E501
    """Add a new pet to the store

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: Pet
    """
    if connexion.request.is_json:
        body = Pet.from_dict(connexion.request.get_json())  # noqa: E501
        id = body.id
        category_id = body.category.id
        category_name = body.category.name
        status = body.status
        name = body.name
        tags = body.tags
        photoURLs = body.photo_urls

        cat_id = petstore.Category.query.filter_by(id=category_id).first()
        cat_name = petstore.Category.query.filter_by(
            cat_name=category_name).first()

        if cat_id is None and cat_name is None:
            new_category = petstore.Category(category_id, category_name)
            petstore.db.session.add(new_category)
            petstore.db.session.commit()
        elif cat_id and cat_name is None:
            return "Category ID Already Exists. Can not assign to New Category", 409
        elif cat_id is None and cat_name:
            return "Category name is Already Exists. Can not assign to the ID", 409

        status = petstore.Status.query.filter_by(value=status).first()

        for tag in tags:
            tag_id = petstore.Tag.query.filter_by(id=tag.id).first()
            tag_n = petstore.Tag.query.filter_by(tag_name=tag.name).first()
            if tag_id is None and tag_n is None:
                new_tag = petstore.Tag(tag.id, tag.name)
                petstore.db.session.add(new_tag)
                petstore.db.session.commit()
            elif tag_id and tag_n is None:
                return "Tad ID Already Exists in {}. Can not Assign to New Tag Name".format(
                    tag_id.tag_name), 409
            elif tag_id is None and tag_n:
                return "Tag Name is Already Exists in {}. Can not Assign to New Tag ID".format(
                    tag_n.id), 409
        pet_id_exists = petstore.Pet.query.filter_by(id=id).first()
        pet_name_exists = petstore.Pet.query.filter_by(pet_name=name).first()
        if pet_id_exists:
            return "Pet ID is Already Exists", 409
        if pet_name_exists:
            return "Pet Name is Already Exists", 409
        category = petstore.Category.query.filter_by(id=category_id).first()
        new_pet = petstore.Pet(id, name, category.id, status.id)
        petstore.db.session.add(new_pet)
        petstore.db.session.commit()

        if tags:
            for tag in tags:
                tag_db = petstore.Tag.query.filter_by(
                    tag_name=tag.name).first()
                pet = petstore.Pet.query.filter_by(pet_name=name).first()
                if tag_db and pet:
                    tag_db.tags.append(pet)
                    petstore.db.session.commit()
                elif tag is None and pet is None:
                    return "Pet and Tag Does Not Exists", 404
                elif pet is None:
                    return "Pet Does Not Exists", 404
                elif tag_db is None:
                    return "Tag Does Not Exists", 404

        if photoURLs:
            for photoURL in photoURLs:
                new_url = petstore.PhotoURL(photoURL, id)
                petstore.db.session.add(new_url)
                petstore.db.session.commit()

        return body, 200