Geoffrey-Django/test/test_commands.py

137 lines
4.1 KiB
Python

from django.test import TestCase
from GeoffreyApp.api.commands import *
from GeoffreyApp.models import *
# Create your tests here.
MC_UUID = "fe7e84132570458892032b69ff188bc3"
DISCORD_UUID = "143072699567177728"
USERNAME = "ZeroHD"
class CommandsAPITestCase(TestCase):
def setUp(self):
self.player = Player.objects.create(name=USERNAME, mc_uuid=MC_UUID, discord_uuid=DISCORD_UUID)
def tearDown(self):
Player.objects.all().delete()
Base.objects.all().delete()
Location.objects.all().delete()
Shop.objects.all().delete()
ItemListing.objects.all().delete()
Tunnel.objects.all().delete()
def populate(self):
base = Base.objects.create(owner=self.player, name="test", x_coord=0, z_coord=0, dimension="O")
shop = Shop.objects.create(owner=self.player, name="test shop", x_coord=500, z_coord=500,
dimension="O")
item = ItemListing.objects.create(shop=shop, price=1, amount=5, item_name="sed")
tunnel = Tunnel.objects.create(tunnel_number="42", tunnel_direction="S", location=base)
def test_register(self):
register(player_name="Vakky", discord_uuid="229423434256351233")
count = Player.objects.filter(mc_uuid__iexact="7afbf6632bf049ef915f22e81b298d17").count()
self.assertEqual(count, 1)
def test_add_base(self):
add_base(x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
base = Base.objects.filter(name__icontains=USERNAME).all().first()
self.assertEqual(base.owner.name, "ZeroHD")
def test_add_shop(self):
add_shop(x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
shop = Shop.objects.filter(name__icontains=USERNAME).all().first()
self.assertEqual(shop.owner.name, "ZeroHD")
def test_add_tunnel(self):
base = Base.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
add_tunnel(tunnel_direction="N", tunnel_number=500, discord_uuid=DISCORD_UUID)
qbase = Base.objects.filter(tunnel_location__tunnel_direction="N").all().first()
self.assertEqual(base.id, qbase.id)
def test_add_item(self):
shop = Shop.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
add_item(item_name="sed", quantity=5, diamond_price=5, discord_uuid=DISCORD_UUID)
item = ItemListing.objects.filter(shop_id=shop.id).all().first()
self.assertEqual(item.item_name, "sed")
def test_edit_post(self):
shop = Shop.objects.create(owner=self.player, name="Test", x_coord=0, z_coord=0)
edit_pos(x=500, z=500, loc_name="Test", discord_uuid=DISCORD_UUID)
qshop = Shop.objects.filter(name__exact="Test").all().first()
self.assertEqual(qshop.x_coord, 500)
def test_find_location(self):
self.populate()
locations = find_location(search="Test")
count = len(locations)
self.assertEqual(count, 2)
def test_find_around(self):
self.populate()
locations = find_around(x_pos=0, z_pos=0, radius=50)
self.assertEqual(len(locations), 1)
def test_selling(self):
self.populate()
items = selling(item_name="sED")
self.assertEqual(len(items), 1)
def test_info(self):
self.populate()
location = info(location_name="test")
self.assertEqual(location["Name"], "test")
def test_tunnel(self):
self.populate()
tunnels = tunnel(player_name=USERNAME)
self.assertEqual(len(tunnels), 1)
def test_me(self):
self.populate()
locations = me(discord_uuid=DISCORD_UUID)
self.assertEqual(len(locations), 2)
def test_delete(self):
self.populate()
delete(name="test", discord_uuid=DISCORD_UUID)
locations = Location.objects.filter(name__icontains="test").all()
self.assertEqual(len(locations), 1)
def delete_item(self):
self.populate()
delete_item(item="sed", shop_name="test shop", discord_uuid=DISCORD_UUID)
items = ItemListing.objects.filter(item_name__iexact="sed").all()
self.assertEqual(len(items), 0)