register has a lot less duplicated code from add_player() in DatabaseInterface. Might have been part of the problem.

doc_update
Joey Hines 2018-09-16 13:34:33 -05:00
parent b4d7e598d3
commit 8373bc0c31
4 changed files with 9 additions and 39 deletions

View File

@ -21,12 +21,8 @@ class Commands:
session = self.interface.database.Session()
try:
try:
self.interface.find_player(session, player_name)
raise PlayerInDBError
except PlayerNotFound:
player = self.interface.add_player(session, player_name, discord_uuid)
player_name = player.name
player = self.interface.add_player(session, player_name, discord_uuid)
player_name = player.name
finally:
session.close()

View File

@ -56,7 +56,8 @@ class DatabaseInterface:
except PlayerNotFound:
mc_uuid = grab_UUID(player_name)
try:
player = self.find_player_by_mc_uuid(session, mc_uuid)
self.find_player_by_mc_uuid(session, mc_uuid)
raise PlayerInDBError
except PlayerNotFound:
player = Player(player_name, discord_uuid)
self.database.add_object(session, player)

View File

@ -260,30 +260,3 @@ class TestCommands(TestCase):
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
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)

View File

@ -13,7 +13,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('YMCA', '151081244824698880')
self.owner = Player('BirbHD', '143072699567177728')
self.loc = Location('test', 1, 3, self.owner, dimension='Nether')
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.tunnel)
uuid = grab_UUID('YMCA')
uuid = grab_UUID('BirbHD')
expr = Player.mc_uuid == uuid
p = self.interface.database.query_by_filter(self.session, Player, expr)[0]
@ -62,9 +62,9 @@ class TestGeoffreyDatabase(TestCase):
expr = Location.owner == self.owner
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]
self.assertEqual(player.name, 'YMCA')
self.assertEqual(player.name, 'BirbHD')
expr = Location.owner == player