Ejemplo n.º 1
0
 def test_find_wishlist(self):
     """ Find a Wishlist by id """
     Wishlist("fido", "2").save()
     saved_wishlist = Wishlist("Bags", "1")
     saved_wishlist.save()
     wishlist = Wishlist.find(saved_wishlist.id)
     self.assertIsNot(wishlist, None)
     self.assertEqual(wishlist.id, saved_wishlist.id)
     self.assertEqual(wishlist.name, "Bags")
Ejemplo n.º 2
0
	def test_find_wishlist(self):
		""" Find a wishlist by ID """
		Wishlist("mike's wishlist", "mike").save()
		saved_wishlist = Wishlist("joan's wishlist", "joan")
		saved_wishlist.save()
		wishlist = Wishlist.find(saved_wishlist.id)
		self.assertIsNot(wishlist, None)
		self.assertEqual(wishlist.id, saved_wishlist.id)
		self.assertEqual(wishlist.name, "joan's wishlist")
Ejemplo n.º 3
0
def get_wishlists(wishlist_id):
    """
    Retrieve a single Wishlist

    This endpoint will return a Wishlist based on it's id
    """
    app.logger.info("Request to Retrieve a wishlist with id [%s]", wishlist_id)
    wishlist =  Wishlist.find(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    return make_response(jsonify(wishlist.serialize()), status.HTTP_200_OK)
Ejemplo n.º 4
0
def delete_wishlists(wishlist_id):
    """
    Delete a Wishlist

    This endpoint will delete a Wishlist based the id specified in the path
    """
    app.logger.info('Request to Delete a wishlist with id [%s]', wishlist_id)
    wishlist = Wishlist.find(wishlist_id)
    if wishlist:
        wishlist.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Ejemplo n.º 5
0
    def delete(self, wishlist_id):
        """
        Delete a Wishlist

        This endpoint will delete a Wishlist based on it's id
        """
        app.logger.info('Request to Delete a wishlist with id [%s]',
                        wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if wishlist:
            wishlist.delete_wishlist()
        return '', status.HTTP_204_NO_CONTENT
Ejemplo n.º 6
0
    def get(self, wishlist_id):
        """
        Retrieve a single wishlist

        This endpoint will return a wishlist based on it's id
        """
        app.logger.info("Request to retrieve a wishlist with id [%s]",
                        wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if not wishlist:
            api.abort(
                status.HTTP_404_NOT_FOUND,
                "Wishlist with id '{}' was not found".format(wishlist_id))
        return wishlist.serialize(), status.HTTP_200_OK
Ejemplo n.º 7
0
def update_wishlists(wishlist_id):
    """
    Update a Wishlist

    This endpoint will update a Wishlist based the body that is posted
    """
    app.logger.info('Request to Update a wishlist with id [%s]', wishlist_id)
    check_content_type('application/json')
    wishlist = Wishlist.find(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    data = request.get_json()
    app.logger.info(data)
    wishlist.deserialize(data)
    wishlist.id = wishlist_id
    wishlist.save()
    return make_response(jsonify(wishlist.serialize()), status.HTTP_200_OK)
Ejemplo n.º 8
0
    def put(self, wishlist_id):
        """
        update a Wishlist

        This endpoint will update a Wishlist based on it's id
        """
        app.logger.info('Request to Update a wishlist with id [%s]',
                        wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if wishlist:
            app.logger.info('Payload to update = %s', api.payload)
            wishlist.deserialize(api.payload)
            if wishlist.name == None or wishlist.name == "":
                app.logger.info('Payload to update missing name')
                api.abort(status.HTTP_400_BAD_REQUEST, "Missing wishlist name")
            wishlist.save()
        else:
            app.logger.info('Wishlist with id [%s] not found', wishlist_id)
            api.abort(status.HTTP_404_NOT_FOUND,
                      "Wishlist with id {} not found".format(wishlist_id))
        app.logger.info('Wishlist with  id [%s] updated', wishlist.id)
        return '', status.HTTP_200_OK
Ejemplo n.º 9
0
 def test_wishlist_not_found(self):
     """ Find a Wishlist that doesnt exist """
     Wishlist("fido", "1").save()
     wishlist = Wishlist.find("2")
     self.assertIs(wishlist, None)
Ejemplo n.º 10
0
 def test_find_with_no_wishlists(self):
     """ Find a Wishlist with empty database """
     wishlist = Wishlist.find("1")
     self.assertIs(wishlist, None)
Ejemplo n.º 11
0
	def test_wishlist_not_found(self):
		""" Test for a Wishlist that doesn't exist """
		Wishlist("mike's wishlist", "mike").save()
		wishlist = Wishlist.find("2")
		self.assertIs(wishlist, None)
Ejemplo n.º 12
0
	def test_find_with_no_wishlists(self):
		""" Find a Wishlist with no Wishlists """
		wishlist = Wishlist.find("1")
		self.assertIs(wishlist, None)