def delete_pets(pet_id): """ Removes a Pet from the database that matches the id """ app.logger.info('Deleting a Pet with id [{}]'.format(pet_id)) pet = Pet.find(pet_id) if pet: pet.delete() return make_response('', HTTP_204_NO_CONTENT)
def test_find_pet(self): Pet(0, "fido", "dog").save() Pet(0, "kitty", "cat").save() pet = Pet.find(2) self.assertIsNot( pet, None) self.assertEqual( pet.id, 2 ) self.assertEqual( pet.name, "kitty" )
def get_pets(id): """ Retrieve a single Pet This endpoint will return a Pet based on it's id --- tags: - Pets produces: - application/json parameters: - name: id in: path description: ID of pet to retrieve type: integer required: true responses: 200: description: Pet returned schema: $ref: '#/definitions/Pet' 404: description: Pet not found """ pet = Pet.find(id) if not pet: raise NotFound("Pet with id '{}' was not found.".format(id)) return make_response(jsonify(pet.serialize()), status.HTTP_200_OK)
def test_find_pet(self): """ Find a Pet by ID """ Pet(name="fido", category="dog", available=True).save() kitty = Pet(name="kitty", category="cat", available=False) kitty.save() pet = Pet.find(kitty.id) self.assertIsNot(pet, None) self.assertEqual(pet.id, kitty.id) self.assertEqual(pet.name, "kitty") self.assertEqual(pet.available, False)
def get_pets(pet_id): """ Retrieve a single Pet This endpoint will return a Pet based on it's id """ pet = Pet.find(pet_id) if not pet: raise NotFound("Pet with id '{}' was not found.".format(pet_id)) return make_response(jsonify(pet.serialize()), status.HTTP_200_OK)
def delete_pets(pet_id): """ Delete a Pet This endpoint will delete a Pet based the id specified in the path """ pet = Pet.find(pet_id) if pet: pet.delete() return make_response('', HTTP_204_NO_CONTENT)
def get_pets(id): pet = Pet.find(id) if pet: message = pet.serialize() rc = HTTP_200_OK else: message = {'error': 'Pet with id: %s was not found' % str(id)} rc = HTTP_404_NOT_FOUND return make_response(jsonify(message), rc)
def update_pets(id): """ Update a Pet This endpoint will update a Pet based the body that is posted --- tags: - Pets consumes: - application/json produces: - application/json parameters: - name: id in: path description: ID of pet to retrieve type: integer required: true - in: body name: body schema: id: data required: - name - category properties: name: type: string description: name for the Pet category: type: string description: the category of pet (dog, cat, etc.) responses: 200: description: Pet Updated schema: id: Pet properties: id: type: integer description: unique id assigned internallt by service name: type: string description: the pets's name category: type: string description: the category of pet (e.g., dog, cat, fish, etc.) 400: description: Bad Request (the posted data was not valid) """ pet = Pet.find(id) if not pet: raise NotFound("Pet with id '{}' was not found.".format(id)) pet.deserialize(request.get_json()) pet.save() return make_response(jsonify(pet.serialize()), status.HTTP_200_OK)
def get_pets(id): """ Retrieves a Pet with a specific id """ pet = Pet.find(id) if pet: message = pet.serialize() return_code = HTTP_200_OK else: message = {'error': 'Pet with id: %s was not found' % str(id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def purchase_pets(pet_id): """ Purchase a Pet """ app.logger.info('Request to purchase Pet with id %s', pet_id) pet = Pet.find(pet_id) if not pet: abort(HTTP_404_NOT_FOUND, "Pet with id '{}' was not found.".format(pet_id)) if not pet.available: abort(HTTP_400_BAD_REQUEST, "Pet with id '{}' is not available.".format(pet_id)) pet.available = False pet.save() return make_response(jsonify(pet.serialize()), HTTP_200_OK)
def delete_pets(pet_id): """ Delete a Pet This endpoint will delete a Pet based the id specified in the path """ app.logger.info('Request to delete Pet with id %s', pet_id) pet = Pet.find(pet_id) if pet: pet.delete() return make_response('', HTTP_204_NO_CONTENT)
def get_pets(pet_id): """ Retrieve a single Pet This endpoint will return a Pet based on it's id """ app.logger.info('Request to get Pet with id %s', pet_id) pet = Pet.find(pet_id) if not pet: abort(HTTP_404_NOT_FOUND, "Pet with id '{}' was not found.".format(pet_id)) return make_response(jsonify(pet.serialize()), HTTP_200_OK)
def get_pets(id): """ Retrieves a Pet with a specific id """ pet = Pet.find(id) if pet: message = pet.serialize() return_code = HTTP_200_OK else: message = {'error' : 'Pet with id: %s was not found' % str(id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def get_pets(pet_id): """ Retrieves a Pet with a specific id """ app.logger.info('Finding a Pet with id [{}]'.format(pet_id)) pet = Pet.find(pet_id) if pet: message = pet.serialize() return_code = HTTP_200_OK else: message = {'error' : 'Pet with id: %s was not found' % str(pet_id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def update_pets(id): pet = Pet.find(id) if pet: pet.deserialize(request.get_json()) pet.save() message = pet.serialize() rc = HTTP_200_OK else: message = {'error': 'Pet %s was not found' % id} rc = HTTP_404_NOT_FOUND return make_response(jsonify(message), rc)
def purchase_pets(id): pet = Pet.find(id) if pet: pet.available = False pet.save() message = pet.serialize() rc = HTTP_200_OK else: message = {'error': 'Pet %s was not found' % id} rc = HTTP_404_NOT_FOUND return make_response(jsonify(message), rc)
def update_pets(id): """ Updates a Pet in the database fom the posted database """ pet = Pet.find(id) if pet: payload = request.get_json() pet.deserialize(payload) pet.save() message = pet.serialize() return_code = HTTP_200_OK else: message = {'error' : 'Pet with id: %s was not found' % str(id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def update_pets(pet_id): """ Update a Pet This endpoint will update a Pet based the body that is posted """ check_content_type('application/json') pet = Pet.find(pet_id) if not pet: raise NotFound("Pet with id '{}' was not found.".format(pet_id)) pet.deserialize(request.get_json()) pet.id = pet_id pet.save() return make_response(jsonify(pet.serialize()), status.HTTP_200_OK)
def update_pets(id): """ Updates a Pet in the database fom the posted database """ pet = Pet.find(id) if pet: payload = request.get_json() pet.deserialize(payload) pet.save() message = pet.serialize() return_code = HTTP_200_OK else: message = {'error': 'Pet with id: %s was not found' % str(id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def update_pets(pet_id): """ Update a Pet This endpoint will update a Pet based the body that is posted """ app.logger.info('Request to update Pet with id %s', pet_id) pet = Pet.find(pet_id) if not pet: abort(HTTP_404_NOT_FOUND, "Pet with id '{}' was not found.".format(pet_id)) pet.deserialize(request.get_json()) pet.id = pet_id pet.save() return make_response(jsonify(pet.serialize()), HTTP_200_OK)
def update_pets(pet_id): """ Updates a Pet in the database fom the posted database """ app.logger.info('Updating a Pet with id [{}]'.format(pet_id)) pet = Pet.find(pet_id) if pet: payload = request.get_json() pet.deserialize(payload) pet.id = pet_id pet.save() message = pet.serialize() return_code = HTTP_200_OK else: message = {'error' : 'Pet with id: %s was not found' % str(pet_id)} return_code = HTTP_404_NOT_FOUND return jsonify(message), return_code
def delete_pets(id): """ Delete a Pet This endpoint will delete a Pet based the id specified in the path --- tags: - Pets description: Deletes a Pet from the database parameters: - name: id in: path description: ID of pet to delete type: integer required: true responses: 204: description: Pet deleted """ pet = Pet.find(id) if pet: pet.delete() return make_response('', status.HTTP_204_NO_CONTENT)
def get_pets(id): """ Retrieve a single Pet This endpoint will return a Pet based on it's id --- tags: - Pets produces: - application/json parameters: - name: id in: path description: ID of pet to retrieve type: integer required: true responses: 200: description: Pet returned schema: id: Pet properties: id: type: integer description: unique id assigned internallt by service name: type: string description: the pets's name category: type: string description: the category of pet (e.g., dog, cat, fish, etc.) 404: description: Pet not found """ pet = Pet.find(id) if not pet: raise NotFound("Pet with id '{}' was not found.".format(id)) return make_response(jsonify(pet.serialize()), status.HTTP_200_OK)
def delete_pets(id): """ Removes a Pet from the database that matches the id """ pet = Pet.find(id) if pet: pet.delete() return make_response('', HTTP_204_NO_CONTENT)
def delete_pets(id): """ Removes a Pet from the database that matches the id """ pet = Pet.find(id) if pet: pet.delete() return make_response('', HTTP_204_NO_CONTENT)
def test_find_with_no_pets(self): """ Find a Pet with empty database """ pet = Pet.find(1) self.assertIs(pet, None)
def test_pet_not_found(self): Pet(0, "fido", "dog").save() pet = Pet.find(2) self.assertIs( pet, None)
def test_find_with_no_pets(self): pet = Pet.find(1) self.assertIs( pet, None)
def delete_pets(id): pet = Pet.find(id) if pet: pet.delete() return make_response('', status.HTTP_204_NO_CONTENT)
def test_pet_not_found(self): """ Test for a Pet that doesn't exist """ Pet(0, "fido", "dog").save() pet = Pet.find(2) self.assertIs(pet, None)
def test_find_with_no_pets(self): """ Find a Pet with no Pets """ pet = Pet.find(1) self.assertIs(pet, None)