2018-12-17 21:16:21 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from GeoffreyApp.api.commands import *
|
|
|
|
from GeoffreyApp.models import *
|
2019-01-04 21:09:44 +00:00
|
|
|
from time import sleep
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2018-12-17 21:16:21 +00:00
|
|
|
# Create your tests here.
|
|
|
|
|
|
|
|
MC_UUID = "fe7e84132570458892032b69ff188bc3"
|
|
|
|
DISCORD_UUID = "143072699567177728"
|
|
|
|
USERNAME = "ZeroHD"
|
|
|
|
|
|
|
|
|
|
|
|
class CommandsAPITestCase(TestCase):
|
2019-01-04 21:09:44 +00:00
|
|
|
|
2018-12-17 21:16:21 +00:00
|
|
|
def setUp(self):
|
2018-12-18 18:13:14 +00:00
|
|
|
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()
|
2019-03-02 17:48:28 +00:00
|
|
|
PublicFarm.objects.all().delete()
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
def populate(self):
|
2019-01-31 20:07:25 +00:00
|
|
|
self.base = Base.objects.create(name="test", x_coord=0, z_coord=0, dimension="O")
|
|
|
|
self.base.owner.add(self.player)
|
|
|
|
self.shop = Shop.objects.create(name="test shop", x_coord=500, z_coord=500,
|
2018-12-30 01:41:18 +00:00
|
|
|
dimension="O")
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
self.town = Town.objects.create(name="test town", x_coord=-500, z_coord=-500,
|
|
|
|
dimension="O")
|
|
|
|
|
|
|
|
self.town.owner.add(self.player)
|
2019-01-31 20:07:25 +00:00
|
|
|
self.shop.owner.add(self.player)
|
2019-01-04 21:09:44 +00:00
|
|
|
self.item = ItemListing.objects.create(shop=self.shop, price=1, amount=5, item_name="sed")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-01-04 21:09:44 +00:00
|
|
|
self.tunnel = Tunnel.objects.create(tunnel_number="42", tunnel_direction="S", location=self.base)
|
2018-12-17 21:16:21 +00:00
|
|
|
|
2019-03-02 17:48:28 +00:00
|
|
|
self.farm = PublicFarm.objects.create(name="test farm", x_coord=0, z_coord=0, dimension="O")
|
|
|
|
self.farm.owner.add(self.player)
|
|
|
|
|
2018-12-17 21:16:21 +00:00
|
|
|
def test_register(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
register(player_name="DrVakky", discord_uuid="229423434256351233")
|
2018-12-17 21:16:21 +00:00
|
|
|
|
|
|
|
count = Player.objects.filter(mc_uuid__iexact="7afbf6632bf049ef915f22e81b298d17").count()
|
|
|
|
|
|
|
|
self.assertEqual(count, 1)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-03-22 14:41:50 +00:00
|
|
|
self.assertRaises(PlayerInDBError, register, player_name="DrVakky", discord_uuid="229423434256351233")
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
def test_add_base(self):
|
2018-12-30 01:41:18 +00:00
|
|
|
add_base(x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
base = Base.objects.filter(name__icontains=USERNAME).all().first()
|
|
|
|
|
2019-01-31 20:07:25 +00:00
|
|
|
self.assertEqual(base.owner.all()[0].name, "ZeroHD")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-02-17 03:13:53 +00:00
|
|
|
self.assertRaises(LocationLookUpError, add_base, x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
def test_add_shop(self):
|
2018-12-30 01:41:18 +00:00
|
|
|
add_shop(x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
shop = Shop.objects.filter(name__icontains=USERNAME).all().first()
|
|
|
|
|
2019-01-31 20:07:25 +00:00
|
|
|
self.assertEqual(shop.owner.all()[0].name, "ZeroHD")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
def test_add_town(self):
|
|
|
|
add_town(x_pos=0, z_pos=0, name=None, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
town = Town.objects.filter(name__icontains=USERNAME).all().first()
|
|
|
|
|
|
|
|
self.assertEqual(town.owner.all()[0].name, "ZeroHD")
|
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
def test_add_tunnel(self):
|
2019-01-31 20:07:25 +00:00
|
|
|
base = Base.objects.create(name="Test", x_coord=0, z_coord=0)
|
|
|
|
|
|
|
|
base.owner.add(self.player)
|
2018-12-30 01:41:18 +00:00
|
|
|
add_tunnel(tunnel_direction="N", tunnel_number=500, discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
qbase = Base.objects.filter(tunnel_location__tunnel_direction="N").all().first()
|
|
|
|
|
|
|
|
self.assertEqual(base.id, qbase.id)
|
|
|
|
|
|
|
|
def test_add_item(self):
|
2019-01-31 20:07:25 +00:00
|
|
|
shop = Shop.objects.create(name="Test", x_coord=0, z_coord=0)
|
|
|
|
shop.owner.add(self.player)
|
2018-12-30 01:41:18 +00:00
|
|
|
add_item(item_name="sed", quantity=5, diamond_price=5, discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
item = ItemListing.objects.filter(shop_id=shop.id).all().first()
|
|
|
|
|
|
|
|
self.assertEqual(item.item_name, "sed")
|
|
|
|
|
|
|
|
def test_edit_post(self):
|
2019-01-31 20:07:25 +00:00
|
|
|
shop = Shop.objects.create(name="Test", x_coord=0, z_coord=0)
|
|
|
|
shop.owner.add(self.player)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
edit_pos(x=500, z=500, loc_name="Test", discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
qshop = Shop.objects.filter(name__exact="Test").all().first()
|
|
|
|
|
|
|
|
self.assertEqual(qshop.x_coord, 500)
|
|
|
|
|
|
|
|
def test_find_location(self):
|
|
|
|
self.populate()
|
2018-12-30 01:41:18 +00:00
|
|
|
locations = find_location(search="Test")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
count = len(locations)
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
self.assertGreater(count, 1)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
def test_find_around(self):
|
|
|
|
self.populate()
|
|
|
|
locations = find_around(x_pos=0, z_pos=0, radius=50)
|
|
|
|
|
2019-03-22 14:41:50 +00:00
|
|
|
self.assertEqual(len(locations), 2)
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2018-12-18 18:13:14 +00:00
|
|
|
def test_selling(self):
|
|
|
|
self.populate()
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
items = selling(item_name="sED")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(items), 1)
|
|
|
|
|
|
|
|
def test_info(self):
|
|
|
|
self.populate()
|
2018-12-30 01:41:18 +00:00
|
|
|
location = info(location_name="test")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-01-11 22:42:23 +00:00
|
|
|
self.assertEqual(location["name"], "test")
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
def test_tunnel(self):
|
|
|
|
self.populate()
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
tunnels = tunnel(player_name=USERNAME)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(tunnels), 1)
|
|
|
|
|
|
|
|
def test_me(self):
|
|
|
|
self.populate()
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
locations = me(discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
self.assertGreater(len(locations), 1)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
def test_delete(self):
|
|
|
|
self.populate()
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
count = Location.objects.filter(name__icontains="test").all().count()
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
delete(name="test", discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
locations = Location.objects.filter(name__icontains="test").all()
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
self.assertEqual(len(locations), count - 1)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
2019-01-04 21:09:44 +00:00
|
|
|
def test_delete_item(self):
|
2018-12-18 18:13:14 +00:00
|
|
|
self.populate()
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
delete_item(item="sed", shop_name="test shop", discord_uuid=DISCORD_UUID)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
items = ItemListing.objects.filter(item_name__iexact="sed").all()
|
|
|
|
|
|
|
|
self.assertEqual(len(items), 0)
|
2019-01-04 21:09:44 +00:00
|
|
|
|
|
|
|
def test_restock(self):
|
|
|
|
self.populate()
|
|
|
|
sleep(1)
|
|
|
|
item = ItemListing.objects.create(shop=self.shop, price=1, amount=5, item_name="sed2")
|
|
|
|
|
|
|
|
restock(item_name="sed", shop_name=self.shop.name, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
new_item = ItemListing.objects.get(item_name="sed2")
|
|
|
|
old_item = ItemListing.objects.get(item_name="sed")
|
|
|
|
|
|
|
|
self.assertGreater(old_item.date_restocked, new_item.date_restocked)
|
2019-02-02 15:34:49 +00:00
|
|
|
|
|
|
|
def test_add_owner(self):
|
|
|
|
self.populate()
|
|
|
|
new_owner = Player.objects.create(name="Vakky", mc_uuid="5", discord_uuid="5")
|
|
|
|
add_owner(new_owner.name, self.shop.name, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
shop = Shop.objects.get(owner__name__icontains="Vakky")
|
|
|
|
|
|
|
|
self.assertEquals(shop.id, self.shop.id)
|
2019-02-02 16:21:44 +00:00
|
|
|
|
2019-02-03 15:01:34 +00:00
|
|
|
self.assertRaises(IsOwnerError, add_owner, new_owner.name, self.shop.name, discord_uuid=DISCORD_UUID)
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
def test_add_resident(self):
|
|
|
|
self.populate()
|
|
|
|
new_resident = Player.objects.create(name="Vakky", mc_uuid="5", discord_uuid="5")
|
|
|
|
add_resident(new_resident.name, self.town.name, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
town = Town.objects.get(residents__name__icontains="Vakky")
|
|
|
|
|
|
|
|
self.assertEquals(town.id, self.town.id)
|
|
|
|
|
2019-02-03 15:01:34 +00:00
|
|
|
self.assertRaises(IsResidentError, add_resident, new_resident.name, self.town.name, discord_uuid=DISCORD_UUID)
|
|
|
|
self.assertRaises(IsResidentError, add_resident, self.player.name, self.town.name, discord_uuid=DISCORD_UUID)
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
def test_remove_resident(self):
|
|
|
|
self.populate()
|
|
|
|
new_resident = Player.objects.create(name="Vakky", mc_uuid="5", discord_uuid="5")
|
|
|
|
add_resident(new_resident.name, self.town.name, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
Town.objects.get(residents__name__icontains="Vakky")
|
|
|
|
|
|
|
|
remove_resident(new_resident.name, self.town.name, discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
self.assertRaises(Town.DoesNotExist, Town.objects.get, residents__name__icontains="Vakky")
|
|
|
|
|
|
|
|
self.assertRaises(ResidentNotFoundError, remove_resident, new_resident.name, self.town.name,
|
|
|
|
discord_uuid=DISCORD_UUID)
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
def test_add_resource(self):
|
|
|
|
self.populate()
|
|
|
|
|
|
|
|
resource = add_resource(resource_name="sed", farm_name="test farm", discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
farm = PublicFarm.objects.filter(resource__resource_name__icontains="sed").first()
|
|
|
|
|
|
|
|
self.assertEqual(resource["farm_id"], farm.id)
|
|
|
|
|
|
|
|
def test_remove_resource(self):
|
|
|
|
self.populate()
|
|
|
|
|
|
|
|
resource = add_resource(resource_name="sed", farm_name="test farm", discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
delete_resource(resource_name="sed", farm_name="test farm", discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
farm = PublicFarm.objects.filter(resource__resource_name__icontains="sed").all()
|
|
|
|
|
|
|
|
self.assertEqual(len(farm), 0)
|
|
|
|
|
|
|
|
def test_find_farm(self):
|
|
|
|
self.populate()
|
|
|
|
add_resource(resource_name="sed", farm_name="test farm", discord_uuid=DISCORD_UUID)
|
|
|
|
|
|
|
|
list = find_farm(resource_name="sed")
|
|
|
|
|
|
|
|
for farm in list:
|
|
|
|
if farm["name"] == "test farm":
|
|
|
|
return
|
|
|
|
|
|
|
|
self.fail("Farm not found")
|