2018-06-02 17:40:55 +00:00
|
|
|
from unittest import TestCase
|
2018-06-23 17:33:02 +00:00
|
|
|
from DatabaseModels import *
|
2018-06-02 17:40:55 +00:00
|
|
|
from BotErrors import *
|
2018-06-23 15:17:51 +00:00
|
|
|
from MinecraftAccountInfoGrabber import *
|
2018-06-02 17:40:55 +00:00
|
|
|
|
|
|
|
class TestGeoffreyDatabase(TestCase):
|
|
|
|
def setUp(self):
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface = DiscordDatabaseInterface('sqlite:///:memory:')
|
|
|
|
self.owner = Player('ZeroHD', '143072699567177728')
|
2018-07-20 01:18:22 +00:00
|
|
|
self.loc = Location('test', 1, 2, 3, self.owner, dimension='Nether')
|
|
|
|
self.tunnel = Tunnel(self.owner, 'Green', 105, self.loc)
|
2018-06-23 17:33:02 +00:00
|
|
|
|
2018-06-02 17:40:55 +00:00
|
|
|
def test_add_object(self):
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.database.add_object(self.loc)
|
|
|
|
self.interface.database.add_object(self.owner)
|
2018-07-20 01:18:22 +00:00
|
|
|
self.interface.database.add_object(self.tunnel)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
2018-06-23 15:17:51 +00:00
|
|
|
uuid = grab_UUID('ZeroHD')
|
2018-07-08 19:19:40 +00:00
|
|
|
expr = Player.mc_uuid == uuid
|
|
|
|
p = self.interface.database.query_by_filter(Player, expr)[0]
|
2018-06-23 15:17:51 +00:00
|
|
|
|
|
|
|
expr = Location.owner == p
|
2018-07-08 19:19:40 +00:00
|
|
|
loc2 = self.interface.database.query_by_filter(Location, expr)[0]
|
2018-06-02 17:40:55 +00:00
|
|
|
|
|
|
|
self.assertEqual(self.loc.id, loc2.id)
|
|
|
|
|
|
|
|
def test_query_by_filter(self):
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.database.add_object(self.loc)
|
|
|
|
self.interface.database.add_object(self.owner)
|
|
|
|
expr = (Location.owner == self.owner)
|
|
|
|
loc2 = self.interface.database.query_by_filter(Location, expr)[0]
|
|
|
|
self.assertEqual(loc2.id, self.loc.id)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
|
|
|
def test_delete_entry(self):
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.database.add_object(self.loc)
|
|
|
|
self.interface.database.add_object(self.owner)
|
2018-06-23 15:17:51 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
expr = Location.owner == self.owner
|
|
|
|
self.interface.database.delete_entry(Location, expr)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc2 = self.interface.database.query_by_filter(Location, expr)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(loc2), 0)
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
self.assertRaises(DeleteEntryError, self.interface.database.delete_entry, Location, expr)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
def test_add_shop(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
shop = self.add_shop()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(type(shop), Shop)
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
shop_list = self.interface.find_shop_by_name('test')
|
|
|
|
self.assertEqual(shop_list[0].dimension, shop.dimension)
|
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
def add_shop(self):
|
2018-07-20 01:18:22 +00:00
|
|
|
return self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, "nether")
|
2018-07-15 18:27:11 +00:00
|
|
|
|
|
|
|
def add_player(self):
|
|
|
|
return self.interface.add_player('ZeroHD', '143072699567177728')
|
|
|
|
|
|
|
|
def add_loc(self):
|
2018-07-20 01:18:22 +00:00
|
|
|
return self.interface.add_location('143072699567177728', 'test', 0, 0, 0)
|
2018-07-15 18:27:11 +00:00
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
def test_add_two_shops(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
shop1 = self.add_shop()
|
2018-07-20 01:18:22 +00:00
|
|
|
shop2 = self.interface.add_shop('143072699567177728', 'no u', 1, 2, 3)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_owner_uuid('143072699567177728')
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[1].id, shop2.id)
|
|
|
|
|
2018-07-21 01:50:24 +00:00
|
|
|
def test_add_tunnel(self):
|
|
|
|
self.add_player()
|
|
|
|
args=[]
|
|
|
|
tunnel1 = self.interface.add_tunnel('143072699567177728', 'green', 155, None)
|
|
|
|
|
|
|
|
tunnel2 = self.interface.find_tunnel_by_owner_name('ZeroHD')[0]
|
|
|
|
self.assertEqual(tunnel1, tunnel2)
|
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
def test_add_item(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
self.add_shop()
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.add_item('143072699567177728', 'test', 'dirt', 1, 15)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
shops = self.interface.find_shop_selling_item('dirt')
|
2018-06-30 15:07:56 +00:00
|
|
|
self.assertEqual(shops[0].name, 'test')
|
|
|
|
|
|
|
|
def test_find_location_by_owner(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
shop = self.add_shop()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_owner(owner)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].id, shop.id)
|
|
|
|
|
|
|
|
def test_find_location_by_name_and_owner(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
shop = self.add_shop()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_name_and_owner_uuid('143072699567177728', 'test')
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].id, shop.id)
|
|
|
|
|
|
|
|
def test_delete_base(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
self.add_loc()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.delete_location('143072699567177728', 'test')
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_name_and_owner_uuid('143072699567177728', 'test')
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(loc_list), 0)
|
|
|
|
|
|
|
|
def test_find_location_around(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
loc = self.add_loc()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-15 18:27:11 +00:00
|
|
|
dim = "o"
|
2018-07-15 15:56:56 +00:00
|
|
|
|
|
|
|
loc_list = self.interface.find_location_around(100, 100, 100, dim)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
loc_list = self.interface.find_location_around(200, 200, 100, dim)
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(loc_list), 0)
|
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
loc_list = self.interface.find_location_around(-100, -100, 100, dim)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
loc_list = self.interface.find_location_around(100, -100, 100, dim)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
loc_list = self.interface.find_location_around(-100, 100, 100, dim)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
loc_list = self.interface.find_location_around(50, -50, 100, dim)
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-07-01 15:10:10 +00:00
|
|
|
def test_find_location_by_name(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
loc = self.add_loc()
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_name('test')
|
2018-07-01 15:10:10 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, loc.name)
|
|
|
|
|
2018-06-30 15:07:56 +00:00
|
|
|
def test_wrong_case(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
|
|
|
loc = self.add_loc()
|
2018-06-30 15:07:56 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_owner_name('zerohd')
|
2018-06-30 15:07:56 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].id, loc.id)
|
|
|
|
|
2018-07-20 01:18:22 +00:00
|
|
|
self.interface.add_shop('143072699567177728', 'testshop', 1, 2, 3, 'neThEr')
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
self.interface.add_item('143072699567177728', 'testshop', 'dirts', 1, 15)
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
shops = self.interface.find_shop_selling_item('Dirt')
|
2018-07-01 15:10:10 +00:00
|
|
|
|
|
|
|
self.assertEqual(shops[0].name, 'testshop')
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
#shops = self.database.find_shop_selling_item('sDirt')
|
|
|
|
|
|
|
|
#self.assertEqual(shops[0].name, 'testshop')
|
|
|
|
|
|
|
|
loc_list = self.interface.find_location_by_name('TEST')
|
2018-07-01 15:10:10 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].name, 'test')
|
|
|
|
|
2018-07-04 00:05:35 +00:00
|
|
|
def test_big_input(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
owner = self.add_player()
|
2018-07-08 19:19:40 +00:00
|
|
|
loc = self.interface.add_location('143072699567177728',
|
2018-07-15 18:27:11 +00:00
|
|
|
'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT', 0, 0, 0)
|
2018-07-04 00:05:35 +00:00
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
loc_list = self.interface.find_location_by_owner(owner)
|
2018-07-04 00:05:35 +00:00
|
|
|
|
|
|
|
self.assertEqual(loc_list[0].id, loc.id)
|
2018-07-01 15:10:10 +00:00
|
|
|
|
2018-07-15 15:56:56 +00:00
|
|
|
def test_duplicate_name(self):
|
2018-07-15 18:27:11 +00:00
|
|
|
self.add_player()
|
|
|
|
self.add_loc()
|
2018-07-15 15:56:56 +00:00
|
|
|
|
2018-07-21 01:50:24 +00:00
|
|
|
self.assertRaises(EntryNameNotUniqueError, self.interface.add_location,
|
2018-07-15 18:27:11 +00:00
|
|
|
'143072699567177728', 'test', 0, 0, 0)
|
2018-06-02 17:40:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-08 19:19:40 +00:00
|
|
|
|
|
|
|
|