From 02845efaf2761c3693d5c0f128a8b5a8990e638a Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 25 Sep 2019 20:02:58 -0500 Subject: [PATCH] Fixed `?selling_price` --- GeoffreyApp/api/commands.py | 11 +++++------ GeoffreyApp/test/test_commands.py | 7 +++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/GeoffreyApp/api/commands.py b/GeoffreyApp/api/commands.py index cb581ed..8ca13cc 100644 --- a/GeoffreyApp/api/commands.py +++ b/GeoffreyApp/api/commands.py @@ -80,8 +80,8 @@ def get_player_by_name(mc_username): def get_player(discord_uuid=None, mc_uuid=None): try: - discord_uuid = str(discord_uuid) - mc_uuid = str(mc_uuid) + discord_uuid = str(discord_uuid) if discord_uuid else None + mc_uuid = str(mc_uuid) if mc_uuid else None if discord_uuid is not None: player = Player.objects.get(discord_uuid__iexact=discord_uuid) @@ -456,10 +456,9 @@ def get_selling(item_name, sort): if len(item_name) == 0: raise EmptryString - all_shop_ids = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \ - .filter(item_name__icontains=item_name).order_by(sort).values('shop_id').all() + all_shop_ids = ItemListing.objects.filter(item_name__icontains=item_name).annotate(normalized_price=F('price') / F('amount')).order_by(sort).values("shop_id").all() - if len(all_shop_ids) == 0: + if all_shop_ids.count() == 0: raise ItemNotFound # Removes duplicates @@ -473,7 +472,7 @@ def get_selling(item_name, sort): shop = Shop.objects.get(pk=shop_id['shop_id']).json item_query = ItemListing.objects.filter( - item_name__icontains=item_name, shop_id=shop_id['shop_id']).order_by(sort) + item_name__icontains=item_name, shop_id=shop_id['shop_id']).order_by("-date_restocked") item_list = [] for item in item_query: diff --git a/GeoffreyApp/test/test_commands.py b/GeoffreyApp/test/test_commands.py index bb0514b..bb43d12 100644 --- a/GeoffreyApp/test/test_commands.py +++ b/GeoffreyApp/test/test_commands.py @@ -124,6 +124,13 @@ class CommandsAPITestCase(TestCase): self.assertEqual(len(items), 1) + def test_selling_price(self): + self.populate() + + items = selling_price(item_name="sED") + + self.assertEqual(len(items), 1) + def test_info(self): self.populate() location = info(location_name="test")