Fixed `?selling_price`

doc_update
Joey Hines 2019-09-25 20:02:58 -05:00
parent 00d4f136de
commit 02845efaf2
2 changed files with 12 additions and 6 deletions

View File

@ -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:

View File

@ -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")