register has a lot less duplicated code from add_player() in DatabaseInterface. Might have been part of the problem.
parent
b4d7e598d3
commit
8373bc0c31
|
@ -21,12 +21,8 @@ class Commands:
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
player = self.interface.add_player(session, player_name, discord_uuid)
|
||||||
self.interface.find_player(session, player_name)
|
player_name = player.name
|
||||||
raise PlayerInDBError
|
|
||||||
except PlayerNotFound:
|
|
||||||
player = self.interface.add_player(session, player_name, discord_uuid)
|
|
||||||
player_name = player.name
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
|
@ -56,7 +56,8 @@ class DatabaseInterface:
|
||||||
except PlayerNotFound:
|
except PlayerNotFound:
|
||||||
mc_uuid = grab_UUID(player_name)
|
mc_uuid = grab_UUID(player_name)
|
||||||
try:
|
try:
|
||||||
player = self.find_player_by_mc_uuid(session, mc_uuid)
|
self.find_player_by_mc_uuid(session, mc_uuid)
|
||||||
|
raise PlayerInDBError
|
||||||
except PlayerNotFound:
|
except PlayerNotFound:
|
||||||
player = Player(player_name, discord_uuid)
|
player = Player(player_name, discord_uuid)
|
||||||
self.database.add_object(session, player)
|
self.database.add_object(session, player)
|
||||||
|
|
|
@ -260,30 +260,3 @@ class TestCommands(TestCase):
|
||||||
|
|
||||||
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
||||||
discord_uuid='143072699567177728')
|
discord_uuid='143072699567177728')
|
||||||
|
|
||||||
def test_register_and_add(self):
|
|
||||||
|
|
||||||
for i in range(0, 1000):
|
|
||||||
|
|
||||||
time.sleep(10)
|
|
||||||
self.commands.register('BirbHD', '143072699567177728')
|
|
||||||
time.sleep(10)
|
|
||||||
self.commands.add_base(0, 0, "tmpB" + str(i), discord_uuid='143072699567177728')
|
|
||||||
|
|
||||||
time.sleep(15)
|
|
||||||
self.commands.register('YMCA', '151081244824698880')
|
|
||||||
time.sleep(10)
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.commands.add_tunnel("North", i, discord_uuid='151081244824698880')
|
|
||||||
except:
|
|
||||||
False
|
|
||||||
|
|
||||||
time.sleep(1)
|
|
||||||
self.commands.add_base(0, 0, "tmpY" + str(i), discord_uuid='151081244824698880')
|
|
||||||
|
|
||||||
if "YMCA" not in self.commands.find("YMCA"):
|
|
||||||
self.fail()
|
|
||||||
|
|
||||||
self.session = self.commands.interface.database.Session()
|
|
||||||
self.commands.interface.database.clear_all(self.session)
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
self.interface = DatabaseInterface(self.bot_config, True)
|
self.interface = DatabaseInterface(self.bot_config, True)
|
||||||
self.session = self.interface.database.Session()
|
self.session = self.interface.database.Session()
|
||||||
self.interface.database.clear_all(self.session)
|
self.interface.database.clear_all(self.session)
|
||||||
self.owner = Player('YMCA', '151081244824698880')
|
self.owner = Player('BirbHD', '143072699567177728')
|
||||||
self.loc = Location('test', 1, 3, self.owner, dimension='Nether')
|
self.loc = Location('test', 1, 3, self.owner, dimension='Nether')
|
||||||
self.tunnel = Tunnel(self.owner, "west", 105, self.loc)
|
self.tunnel = Tunnel(self.owner, "west", 105, self.loc)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
self.interface.database.add_object(self.session, self.owner)
|
self.interface.database.add_object(self.session, self.owner)
|
||||||
self.interface.database.add_object(self.session, self.tunnel)
|
self.interface.database.add_object(self.session, self.tunnel)
|
||||||
|
|
||||||
uuid = grab_UUID('YMCA')
|
uuid = grab_UUID('BirbHD')
|
||||||
expr = Player.mc_uuid == uuid
|
expr = Player.mc_uuid == uuid
|
||||||
p = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
p = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ class TestGeoffreyDatabase(TestCase):
|
||||||
expr = Location.owner == self.owner
|
expr = Location.owner == self.owner
|
||||||
self.interface.database.delete_entry(self.session, Location, expr)
|
self.interface.database.delete_entry(self.session, Location, expr)
|
||||||
|
|
||||||
expr = Player.name == 'YMCA'
|
expr = Player.name == 'BirbHD'
|
||||||
player = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
player = self.interface.database.query_by_filter(self.session, Player, expr)[0]
|
||||||
self.assertEqual(player.name, 'YMCA')
|
self.assertEqual(player.name, 'BirbHD')
|
||||||
|
|
||||||
expr = Location.owner == player
|
expr = Location.owner == player
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue