Added a constant for test cases so its easy to change the mc username.
parent
3026b240f4
commit
a14a3e1d31
|
@ -51,17 +51,18 @@ class Config:
|
|||
self.engine_args = self.read_engine_arg()
|
||||
|
||||
self.token = self.config['Discord']['Token']
|
||||
self.world_name = self.config['Minecraft']['World_Name']
|
||||
self.status = self.config['Discord']['Status']
|
||||
self.prefix = self.config['Discord']['Prefix']
|
||||
self.bot_mod = self.config['Discord']['Bot_Mod'].split(',')
|
||||
self.error_users = self.config['Discord']['Error_Users'].split(',')
|
||||
|
||||
self.world_name = self.config['Minecraft']['World_Name']
|
||||
self.dynmap_url = self.config['Minecraft']['Dynmap_Url']
|
||||
|
||||
self.log_path = self.config['Logging']['log_path']
|
||||
self.count = int(self.config['Logging']['Count'])
|
||||
self.rotation_duration = int(self.config['Logging']['Rotation_Duration'])
|
||||
|
||||
self.special_name_list = dict(self.config.items('Special Names'))
|
||||
except Exception as e:
|
||||
print("Invalid config file, missing {}.".format(e))
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest import TestCase
|
|||
from Commands import *
|
||||
from BotConfig import get_config
|
||||
|
||||
zerohd = 'birbhd'
|
||||
|
||||
class TestCommands(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -16,18 +17,18 @@ class TestCommands(TestCase):
|
|||
|
||||
def test_get_player(self):
|
||||
session = self.commands.interface.database.Session()
|
||||
self.commands.interface.add_player(session, 'BirbHD', discord_uuid='143072699567177728')
|
||||
self.commands.interface.add_player(session, zerohd, discord_uuid='143072699567177728')
|
||||
|
||||
player = self.commands.get_player(session, discord_uuid='143072699567177728')
|
||||
|
||||
self.assertEqual(player.name, 'BirbHD')
|
||||
self.assertEqual(player.name, zerohd)
|
||||
|
||||
self.assertRaises(AttributeError, self.commands.get_player, session)
|
||||
session.close()
|
||||
|
||||
def test_get_location(self):
|
||||
session = self.commands.interface.database.Session()
|
||||
self.commands.interface.add_player(session, 'BirbHD', discord_uuid='143072699567177728')
|
||||
self.commands.interface.add_player(session, zerohd, discord_uuid='143072699567177728')
|
||||
session.close()
|
||||
|
||||
session = self.commands.interface.database.Session()
|
||||
|
@ -64,14 +65,14 @@ class TestCommands(TestCase):
|
|||
|
||||
|
||||
def test_register(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
|
||||
player = self.commands.get_player(self.session, discord_uuid='143072699567177728')
|
||||
|
||||
self.assertEqual(player.name, 'BirbHD')
|
||||
self.assertEqual(player.name, zerohd)
|
||||
|
||||
def test_addbase(self):
|
||||
player_name = self.commands.register('BirbHD', '143072699567177728')
|
||||
player_name = self.commands.register(zerohd, '143072699567177728')
|
||||
base = self.commands.add_base(0, 0, discord_uuid='143072699567177728')
|
||||
|
||||
self.assertRaises(EntryNameNotUniqueError, self.commands.add_base, 0, 0, discord_uuid='143072699567177728')
|
||||
|
@ -82,7 +83,7 @@ class TestCommands(TestCase):
|
|||
pass
|
||||
|
||||
def test_addshop(self):
|
||||
player_name = self.commands.register('BirbHD', '143072699567177728')
|
||||
player_name = self.commands.register(zerohd, '143072699567177728')
|
||||
shop = self.commands.add_shop(0, 0, discord_uuid='143072699567177728')
|
||||
|
||||
self.assertRaises(EntryNameNotUniqueError, self.commands.add_shop, 0, 0, discord_uuid='143072699567177728')
|
||||
|
@ -93,7 +94,7 @@ class TestCommands(TestCase):
|
|||
pass
|
||||
|
||||
def test_addtunnel(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop2', discord_uuid='143072699567177728')
|
||||
|
||||
|
@ -110,11 +111,11 @@ class TestCommands(TestCase):
|
|||
discord_uuid='143072699567177728')
|
||||
|
||||
def test_find(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
||||
self.commands.add_base(0, 0, 'heck', discord_uuid='143072699567177728')
|
||||
|
||||
result = self.commands.find('BirbHD')
|
||||
result = self.commands.find(zerohd)
|
||||
|
||||
if ('frick' in result) & ('heck' in result):
|
||||
pass
|
||||
|
@ -122,15 +123,15 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_delete(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.delete('frick', discord_uuid='143072699567177728')
|
||||
|
||||
self.assertRaises(LocationLookUpError, self.commands.find, 'BirbHD')
|
||||
self.assertRaises(LocationLookUpError, self.commands.find, zerohd)
|
||||
|
||||
def test_findaround(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
||||
|
||||
result = self.commands.find_around(0, 0)
|
||||
|
@ -141,7 +142,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_additem(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.assertRaises(NoLocationsInDatabase, self.commands.add_item, 'dirt', 5, 5
|
||||
, discord_uuid='143072699567177728')
|
||||
|
||||
|
@ -164,7 +165,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_selling(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.add_item('cool', 5, 5, shop_name='frick', discord_uuid='143072699567177728')
|
||||
|
@ -177,7 +178,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_info(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.add_tunnel("West", 50, location_name='frick', discord_uuid='143072699567177728')
|
||||
|
@ -190,7 +191,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_add_tunnel(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
|
||||
self.assertRaises(NoLocationsInDatabase, self.commands.add_tunnel, "soUTH", 50, None,
|
||||
discord_uuid='143072699567177728')
|
||||
|
@ -199,7 +200,7 @@ class TestCommands(TestCase):
|
|||
|
||||
self.commands.add_tunnel("soUTH", 50, None, discord_uuid='143072699567177728')
|
||||
|
||||
result = self.commands.tunnel('BirbHD')
|
||||
result = self.commands.tunnel(zerohd)
|
||||
|
||||
if "South" in result:
|
||||
pass
|
||||
|
@ -207,10 +208,10 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_tunnel(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
self.assertRaises(LocationLookUpError, self.commands.tunnel, 'BirbHD')
|
||||
self.assertRaises(LocationLookUpError, self.commands.tunnel, zerohd)
|
||||
|
||||
result = self.commands.add_tunnel("WEST", 50, None, discord_uuid='143072699567177728')
|
||||
|
||||
|
@ -222,7 +223,7 @@ class TestCommands(TestCase):
|
|||
|
||||
|
||||
def test_edit_name(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.edit_name('cool shop', 'test shop', discord_uuid='143072699567177728')
|
||||
|
@ -235,7 +236,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_edit_pos(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.edit_pos(500, 500, 'test shop', discord_uuid='143072699567177728')
|
||||
|
@ -260,7 +261,7 @@ class TestCommands(TestCase):
|
|||
discord_uuid='143072699567177728')
|
||||
|
||||
def test_edit_tunnel(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.edit_tunnel("West", 500, 'test shop', discord_uuid='143072699567177728')
|
||||
|
@ -273,7 +274,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_delete_item(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.add_item('dirt', 5, 5, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
@ -294,7 +295,7 @@ class TestCommands(TestCase):
|
|||
discord_uuid='143072699567177728')
|
||||
|
||||
def test_me(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
||||
|
||||
result = self.commands.me(discord_uuid='143072699567177728')
|
||||
|
@ -305,7 +306,7 @@ class TestCommands(TestCase):
|
|||
self.fail()
|
||||
|
||||
def test_update_mc_uuid(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
|
||||
self.commands.update_mc_uuid('143072699567177728', '0')
|
||||
|
||||
|
@ -313,12 +314,12 @@ class TestCommands(TestCase):
|
|||
mc_uuid='fe7e84132570458892032b69ff188bc3')
|
||||
|
||||
def test_update_mc_name(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
|
||||
self.commands.update_mc_name('143072699567177728')
|
||||
|
||||
def test_update_discord_uuid(self):
|
||||
self.commands.register('BirbHD', '143072699567177728')
|
||||
self.commands.register(zerohd, '143072699567177728')
|
||||
|
||||
self.commands.update_discord_uuid('143072699567177728', '0')
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest import TestCase
|
|||
from DatabaseInterface import *
|
||||
from BotConfig import *
|
||||
|
||||
zerohd = 'BirbHD'
|
||||
|
||||
class TestGeoffreyDatabase(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -13,7 +14,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
self.interface = DatabaseInterface(self.bot_config, True)
|
||||
self.session = self.interface.database.Session()
|
||||
self.interface.database.clear_all(self.session)
|
||||
self.owner = Player('BirbHD', '143072699567177728')
|
||||
self.owner = Player(zerohd, '143072699567177728')
|
||||
self.loc = Location('test', 1, 3, self.owner, dimension='Nether')
|
||||
self.tunnel = Tunnel(self.owner, "west", 105, self.loc)
|
||||
|
||||
|
@ -26,7 +27,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
return shop
|
||||
|
||||
def add_player(self):
|
||||
player = self.interface.add_player(self.session, 'BirbHD', discord_uuid='143072699567177728')
|
||||
player = self.interface.add_player(self.session, zerohd, discord_uuid='143072699567177728')
|
||||
return player
|
||||
|
||||
def add_loc(self, player):
|
||||
|
@ -38,7 +39,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
self.interface.database.add_object(self.session, self.owner)
|
||||
self.interface.database.add_object(self.session, self.tunnel)
|
||||
|
||||
uuid = grab_UUID('BirbHD')
|
||||
uuid = grab_UUID(zerohd)
|
||||
expr = Player.mc_uuid == uuid
|
||||
p = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
||||
|
||||
|
@ -62,9 +63,9 @@ class TestGeoffreyDatabase(TestCase):
|
|||
expr = Location.owner == self.owner
|
||||
self.interface.database.delete_entry(self.session, Location, expr)
|
||||
|
||||
expr = Player.name == 'BirbHD'
|
||||
expr = Player.name == zerohd
|
||||
player = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
||||
self.assertEqual(player.name, 'BirbHD')
|
||||
self.assertEqual(player.name, zerohd)
|
||||
|
||||
expr = Location.owner == player
|
||||
|
||||
|
@ -76,7 +77,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
|
||||
def test_add_player(self):
|
||||
self.add_player()
|
||||
self.assertRaises(PlayerInDBError, self.interface.add_player, self.session, 'BirbHD',
|
||||
self.assertRaises(PlayerInDBError, self.interface.add_player, self.session, zerohd,
|
||||
discord_uuid='143072699567177728')
|
||||
|
||||
def test_add_shop(self):
|
||||
|
@ -101,7 +102,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
player = self.add_player()
|
||||
tunnel1 = self.interface.add_tunnel(self.session, player, "South", 155, None)
|
||||
|
||||
tunnel2 = self.interface.find_tunnel_by_owner_name(self.session, 'BirbHD')[0]
|
||||
tunnel2 = self.interface.find_tunnel_by_owner_name(self.session, zerohd)[0]
|
||||
self.assertEqual(tunnel1, tunnel2)
|
||||
|
||||
self.assertRaises(EntryNameNotUniqueError, self.interface.add_tunnel, self.session, player, "South", 155, None)
|
||||
|
@ -110,7 +111,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
|
||||
tunnel3 = self.interface.add_tunnel(self.session, player, "South", 155, 'test')
|
||||
|
||||
tunnel4 = self.interface.find_tunnel_by_owner_name(self.session, 'BirbHD')[0]
|
||||
tunnel4 = self.interface.find_tunnel_by_owner_name(self.session, zerohd)[0]
|
||||
self.assertEqual(tunnel3, tunnel4)
|
||||
|
||||
self.assertRaises(LocationHasTunnelError, self.interface.add_tunnel, self.session, player, "South", 155,
|
||||
|
@ -213,7 +214,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
owner = self.add_player()
|
||||
self.add_loc(owner)
|
||||
|
||||
loc_list = self.interface.search_all_fields(self.session, 'BirbHD')
|
||||
loc_list = self.interface.search_all_fields(self.session, zerohd)
|
||||
|
||||
self.assertGreater(len(loc_list), 0)
|
||||
|
||||
|
@ -221,7 +222,7 @@ class TestGeoffreyDatabase(TestCase):
|
|||
owner = self.add_player()
|
||||
loc = self.add_loc(owner)
|
||||
|
||||
loc_list = self.interface.find_location_by_owner_name(self.session, 'BirbHD')
|
||||
loc_list = self.interface.find_location_by_owner_name(self.session, zerohd)
|
||||
|
||||
self.assertEqual(loc_list[0].id, loc.id)
|
||||
|
||||
|
|
|
@ -25,11 +25,9 @@ class StressTest(TestCase):
|
|||
self.commands.add_shop(0, 0, shop_name='test shop{}'.format(i), discord_uuid='143072699567177728')
|
||||
|
||||
self.commands.find('BirbHD')
|
||||
|
||||
sleep(0.5)
|
||||
|
||||
def test_mc_query(self):
|
||||
|
||||
for i in range(0, 1000):
|
||||
grab_playername('fe7e84132570458892032b69ff188bc3')
|
||||
|
||||
|
|
Loading…
Reference in New Issue