예제 #1
0
 def test_delete_a_wishlist(self):
     """ Delete a Wishlist """
     wishlist = Wishlist("fido", "1")
     wishlist.save()
     self.assertEqual(len(Wishlist.all()), 1)
     # delete the wishlist and make sure it isn't in the database
     wishlist.delete()
     self.assertEqual(len(Wishlist.all()), 0)
예제 #2
0
 def test_add_a_wishlist(self):
     """ Create a wishlist and add it to the database """
     wishlists = Wishlist.all()
     self.assertEqual(wishlists, [])
     wishlist = Wishlist("fido", "1")
     self.assertNotEqual(wishlist, None)
     self.assertEqual(wishlist.id, None)
     wishlist.save()
     # Asert that it was assigned an id and shows up in the database
     self.assertNotEqual(wishlist.id, None)
     wishlists = Wishlist.all()
     self.assertEqual(len(wishlists), 1)
     self.assertEqual(wishlists[0].name, "fido")
     self.assertEqual(wishlists[0].customer_id, "1")
예제 #3
0
	def test_delete_error(self):
		""" Test failure of the delete try-catch"""
		wishlist = Wishlist("mike's wishlist", "mike")
		wishlist.save()
		self.assertEqual(len(Wishlist.all()), 1)
		og_id = wishlist.id
		# modify id to trigger try-catch
		wishlist.id = "asdf123"
		# delete the wishlist and make sure it failed and is still int the database
		wishlist.delete_wishlist()
		self.assertEqual(len(Wishlist.all()), 1)
		# Fetch it back and make sure the id and data hasn't changed
		wishlists = Wishlist.all()
		self.assertEqual(len(wishlists), 1)
		self.assertEqual(wishlists[0].name, "mike's wishlist")
		self.assertEqual(wishlists[0].id, og_id)
예제 #4
0
    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
예제 #5
0
	def test_update_a_wishlist(self):
		""" Update a Wishlist """
		wishlist = Wishlist("mike's wishlist", "mike")
		wishlist.save()
		self.assertNotEqual(wishlist.id, None)
		# Change it an save it
		wishlist.name = "mike's hard wishlist"
		wishlist.save()
		# Fetch it back and make sure the id hasn't changed
		# but the data did change
		wishlists = Wishlist.all()
		self.assertEqual(len(wishlists), 1)
		self.assertEqual(wishlists[0].name, "mike's hard wishlist")
예제 #6
0
 def test_update_a_wishlist(self):
     """ Update a Wishlist """
     wishlist = Wishlist("fido", "1")
     wishlist.save()
     self.assertNotEqual(wishlist.id, None)
     # Change it an save it
     wishlist.customer_id = "k9"
     wishlist.save()
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     wishlists = Wishlist.all()
     self.assertEqual(len(wishlists), 1)
     self.assertEqual(wishlists[0].customer_id, "k9")
     self.assertEqual(wishlists[0].name, "fido")
예제 #7
0
	def test_update_error(self):
		""" TEST failure of the update try-catch """
		wishlist = Wishlist("mike's wishlist", "mike")
		wishlist.save()
		self.assertNotEqual(wishlist.id, None)
		og_id = wishlist.id

		#change its ID before updating it to trigger try-catch block
		wishlist.id = "asdf123"
		wishlist.name = "mike's hard wishlist"
		wishlist.save()
		# Fetch it back and make sure the id and data hasn't changed
		wishlists = Wishlist.all()
		self.assertEqual(len(wishlists), 1)
		self.assertEqual(wishlists[0].name, "mike's wishlist")
		self.assertEqual(wishlists[0].id, og_id)
예제 #8
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)
예제 #9
0
	def test_all(self):
		""" All() should return a list of all wishlists """
		Wishlist("mike's wishlist", "mike").save()
		Wishlist("joan's wishlist", "joan").save()
		wishlists = Wishlist.all()
		self.assertEqual(len(wishlists), 2)
예제 #10
0
	def test_create_error(self, create_mock):
		"""Test create wishlist that returns error """
		create_mock.side_effect = HTTPError
		wishlist = Wishlist("mike's wishlist", "mike")
		wishlist.save()
		self.assertEqual(len(Wishlist.all()), 0)