コード例 #1
0
ファイル: service.py プロジェクト: NYU-Wishlists/wishlists
    def get(self):
        """ Retrieves all the wishlists """
        app.logger.info('Request to list wishlists')
        wishlists = []
        wishlist_user = request.args.get('wishlist_user')
        wishlist_name = request.args.get('wishlist_name')
        app.logger.info('Request to list wishlists of user %s with name: %s',
                        wishlist_user, wishlist_name)

        if wishlist_user:
            a = Wishlist.find_by_user(wishlist_user)
            ay = [w.serialize() for w in a]

            if wishlist_name:
                b = Wishlist.find_by_name(wishlist_name)
                bee = [w.serialize() for w in b]

                wishlists = [x for x in ay if x in bee]
            else:
                wishlists = ay
        else:
            wishlists = [w.serialize() for w in Wishlist.all()]

        app.logger.info('[%s] Wishlists returned', len(wishlists))
        return wishlists, status.HTTP_200_OK
コード例 #2
0
ファイル: test_wishlists.py プロジェクト: rudi116/wishlists
 def test_find_by_name(self):
     """ Find a Wishlist by Name """
     Wishlist("fido", "1").save()
     Wishlist("Bags", "2").save()
     wishlists = Wishlist.find_by_name("fido")
     self.assertNotEqual(len(wishlists), 0)
     self.assertEqual(wishlists[0].customer_id, "1")
     self.assertEqual(wishlists[0].name, "fido")
コード例 #3
0
	def test_find_by_name(self):
		""" Find a Wishlist by Name """
		Wishlist("mike's wishlist", "mike").save()
		Wishlist("joan's wishlist", "joan").save()
		wishlists = Wishlist.find_by_name("mike's wishlist")
		self.assertEqual(len(wishlists), 1)
		self.assertEqual(wishlists[0].user, "mike")
		self.assertEqual(wishlists[0].name, "mike's wishlist")
コード例 #4
0
 def test_delete_wishlist(self):
     """ Delete a wishlist by ID """
     wishlist = Wishlist.find_by_name('Wishlist demo 1')[0]
     wishlist_count = self.get_wishlist_count()
     resp = self.app.delete('/wishlists/{}'.format(wishlist.id),
                            content_type='application/json')
     self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(len(resp.data), 0)
     new_count = self.get_wishlist_count()
     self.assertEqual(new_count, wishlist_count - 1)
コード例 #5
0
ファイル: server.py プロジェクト: rudi116/wishlists
def list_wishlists():
    """ Returns all of the Wishlists """
    app.logger.info('Request to list Wishlists...')
    wishlists = []
    customer_id = request.args.get('customer_id')
    name = request.args.get('name')
    if customer_id:
        app.logger.info('Find by customer_id')
        wishlists = Wishlist.find_by_customer_id(customer_id)
    elif name:
        app.logger.info('Find by name')
        wishlists = Wishlist.find_by_name(name)
    else:
        app.logger.info('Find all')
        wishlists = Wishlist.all()

    app.logger.info('[%s] Wishlists returned', len(wishlists))
    results = [wishlist.serialize() for wishlist in wishlists]
    return make_response(jsonify(results), status.HTTP_200_OK)