Fixed error handling for bad username lookups and updated tests.

doc_update
Joey Hines 2018-09-10 09:24:15 -05:00
parent 975648a926
commit af08269f56
6 changed files with 47 additions and 41 deletions

View File

@ -1,4 +1,4 @@
from json import JSONDecodeError from simplejson.errors import JSONDecodeError
import requests import requests

View File

@ -16,22 +16,22 @@ class TestCommands(TestCase):
def test_get_player(self): def test_get_player(self):
session = self.commands.interface.database.Session() session = self.commands.interface.database.Session()
self.commands.interface.add_player(session, 'ZeroHD', discord_uuid='143072699567177728') self.commands.interface.add_player(session, 'BirbHD', discord_uuid='143072699567177728')
player = self.commands.get_player(session, discord_uuid='143072699567177728') player = self.commands.get_player(session, discord_uuid='143072699567177728')
self.assertEqual(player.name, 'ZeroHD') self.assertEqual(player.name, 'BirbHD')
self.session.close() self.session.close()
def test_register(self): def test_register(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
player = self.commands.get_player(self.session, discord_uuid='143072699567177728') player = self.commands.get_player(self.session, discord_uuid='143072699567177728')
self.assertEqual(player.name, 'ZeroHD') self.assertEqual(player.name, 'BirbHD')
def test_addbase(self): def test_addbase(self):
player_name = self.commands.register('ZeroHD', '143072699567177728') player_name = self.commands.register('BirbHD', '143072699567177728')
base = self.commands.add_base(0, 0, discord_uuid='143072699567177728') base = self.commands.add_base(0, 0, discord_uuid='143072699567177728')
if player_name not in base: if player_name not in base:
@ -40,7 +40,7 @@ class TestCommands(TestCase):
pass pass
def test_addshop(self): def test_addshop(self):
player_name = self.commands.register('ZeroHD', '143072699567177728') player_name = self.commands.register('BirbHD', '143072699567177728')
shop = self.commands.add_shop(0, 0, discord_uuid='143072699567177728') shop = self.commands.add_shop(0, 0, discord_uuid='143072699567177728')
if player_name not in shop: if player_name not in shop:
@ -49,7 +49,7 @@ class TestCommands(TestCase):
pass pass
def test_addtunnel(self): def test_addtunnel(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
tunnel2 = self.commands.add_tunnel("East", 50, location_name='test_shop', tunnel2 = self.commands.add_tunnel("East", 50, location_name='test_shop',
@ -62,11 +62,11 @@ class TestCommands(TestCase):
location_name='test_shop', discord_uuid='143072699567177728') location_name='test_shop', discord_uuid='143072699567177728')
def test_find(self): def test_find(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
self.commands.add_base(0, 0, 'heck', discord_uuid='143072699567177728') self.commands.add_base(0, 0, 'heck', discord_uuid='143072699567177728')
result = self.commands.find('zerohd') result = self.commands.find('BirbHD')
if ('frick' in result) & ('heck' in result): if ('frick' in result) & ('heck' in result):
pass pass
@ -74,15 +74,15 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_delete(self): def test_delete(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
self.commands.delete('frick', discord_uuid='143072699567177728') self.commands.delete('frick', discord_uuid='143072699567177728')
self.assertRaises(LocationLookUpError, self.commands.find, 'zerohd') self.assertRaises(LocationLookUpError, self.commands.find, 'BirbHD')
def test_findaround(self): def test_findaround(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
result = self.commands.find_around(0, 0) result = self.commands.find_around(0, 0)
@ -93,7 +93,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_additem(self): def test_additem(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, discord_uuid='143072699567177728') self.commands.add_shop(0, 0, discord_uuid='143072699567177728')
result = self.commands.add_item('dirt', 5, 5, None, discord_uuid='143072699567177728') result = self.commands.add_item('dirt', 5, 5, None, discord_uuid='143072699567177728')
@ -113,7 +113,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_selling(self): def test_selling(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='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') self.commands.add_item('cool', 5, 5, shop_name='frick', discord_uuid='143072699567177728')
@ -126,7 +126,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_info(self): def test_info(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='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') self.commands.add_tunnel("West", 50, location_name='frick', discord_uuid='143072699567177728')
@ -139,12 +139,12 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_tunnel(self): def test_tunnel(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
self.commands.add_tunnel("soUTH", 50, None, discord_uuid='143072699567177728') self.commands.add_tunnel("soUTH", 50, None, discord_uuid='143072699567177728')
result = self.commands.tunnel('ZeroHD') result = self.commands.tunnel('BirbHD')
if "South" in result: if "South" in result:
pass pass
@ -152,7 +152,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_edit_name(self): def test_edit_name(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='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') self.commands.edit_name('cool shop', 'test shop', discord_uuid='143072699567177728')
@ -165,7 +165,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_edit_pos(self): def test_edit_pos(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='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') self.commands.edit_pos(500, 500, 'test shop', discord_uuid='143072699567177728')
@ -190,7 +190,7 @@ class TestCommands(TestCase):
discord_uuid='143072699567177728') discord_uuid='143072699567177728')
def test_edit_tunnel(self): def test_edit_tunnel(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='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') self.commands.edit_tunnel("West", 500, 'test shop', discord_uuid='143072699567177728')
@ -203,7 +203,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_delete_item(self): def test_delete_item(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='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') self.commands.add_item('dirt', 5, 5, shop_name='test shop', discord_uuid='143072699567177728')
@ -227,7 +227,7 @@ class TestCommands(TestCase):
discord_uuid='143072699567177728') discord_uuid='143072699567177728')
def test_me(self): def test_me(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
result = self.commands.me(discord_uuid='143072699567177728') result = self.commands.me(discord_uuid='143072699567177728')
@ -238,7 +238,7 @@ class TestCommands(TestCase):
self.fail() self.fail()
def test_update_mc_uuid(self): def test_update_mc_uuid(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.update_mc_uuid('0', '143072699567177728') self.commands.update_mc_uuid('0', '143072699567177728')
@ -246,12 +246,12 @@ class TestCommands(TestCase):
mc_uuid='fe7e84132570458892032b69ff188bc3') mc_uuid='fe7e84132570458892032b69ff188bc3')
def test_update_mc_name(self): def test_update_mc_name(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.update_mc_name('143072699567177728') self.commands.update_mc_name('143072699567177728')
def test_update_discord_uuid(self): def test_update_discord_uuid(self):
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
self.commands.update_discord_uuid('143072699567177728', '0') self.commands.update_discord_uuid('143072699567177728', '0')

View File

@ -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('ZeroHD', '143072699567177728') 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)
@ -26,7 +26,7 @@ class TestGeoffreyDatabase(TestCase):
return shop return shop
def add_player(self): def add_player(self):
player = self.interface.add_player(self.session, 'ZeroHD', discord_uuid='143072699567177728') player = self.interface.add_player(self.session, 'BirbHD', discord_uuid='143072699567177728')
return player return player
def add_loc(self, player): def add_loc(self, player):
@ -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('ZeroHD') 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 == 'ZeroHD' 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, 'ZeroHD') self.assertEqual(player.name, 'BirbHD')
expr = Location.owner == player expr = Location.owner == player
@ -96,7 +96,7 @@ class TestGeoffreyDatabase(TestCase):
player = self.add_player() player = self.add_player()
tunnel1 = self.interface.add_tunnel(self.session, player, "South", 155, None) tunnel1 = self.interface.add_tunnel(self.session, player, "South", 155, None)
tunnel2 = self.interface.find_tunnel_by_owner_name(self.session, 'ZeroHD')[0] tunnel2 = self.interface.find_tunnel_by_owner_name(self.session, 'BirbHD')[0]
self.assertEqual(tunnel1, tunnel2) self.assertEqual(tunnel1, tunnel2)
def test_add_item(self): def test_add_item(self):
@ -175,7 +175,7 @@ class TestGeoffreyDatabase(TestCase):
owner = self.add_player() owner = self.add_player()
self.add_loc(owner) self.add_loc(owner)
loc_list = self.interface.search_all_fields(self.session, 'ZeroHD') loc_list = self.interface.search_all_fields(self.session, 'BirbHD')
self.assertGreater(len(loc_list), 0) self.assertGreater(len(loc_list), 0)
@ -183,7 +183,7 @@ class TestGeoffreyDatabase(TestCase):
owner = self.add_player() owner = self.add_player()
loc = self.add_loc(owner) loc = self.add_loc(owner)
loc_list = self.interface.find_location_by_owner_name(self.session, 'zerohd') loc_list = self.interface.find_location_by_owner_name(self.session, 'BirbHD')
self.assertEqual(loc_list[0].id, loc.id) self.assertEqual(loc_list[0].id, loc.id)

View File

@ -1,4 +1,6 @@
from unittest import TestCase from unittest import TestCase
from BotConfig import get_config
import os
from DiscordHelperFunctions import get_nickname from DiscordHelperFunctions import get_nickname
@ -11,4 +13,5 @@ class TestGet_nickname(TestCase):
self.nick = 'dootb.in ꙩ ⃤' self.nick = 'dootb.in ꙩ ⃤'
tmp = test() tmp = test()
self.assertEqual(get_nickname(tmp), 'aeskdar')
self.assertEqual(get_nickname(tmp, {'dootb.in ꙩ ⃤':'aeskdar'}), 'aeskdar')

View File

@ -6,13 +6,13 @@ from MinecraftAccountInfoGrabber import *
class TestMinecraftInfoGrabber(TestCase): class TestMinecraftInfoGrabber(TestCase):
def test_handle_data(self): def test_handle_data(self):
self.assertEqual(grab_UUID('ZeroHD'), 'fe7e84132570458892032b69ff188bc3') self.assertEqual(grab_UUID('BirbHD'), 'fe7e84132570458892032b69ff188bc3')
def test_grab_playername(self): def test_grab_playername(self):
self.assertEqual(grab_playername('01c29c443f8d4ab490a56919407a5bd2'), 'CoolZero123') self.assertEqual(grab_playername('01c29c443f8d4ab490a56919407a5bd2'), 'CoolZero123')
def test_grab_playername_wrong_case(self): def test_grab_playername_wrong_case(self):
self.assertEqual(grab_UUID('zerohd'), 'fe7e84132570458892032b69ff188bc3') self.assertEqual(grab_UUID('birbhd'), 'fe7e84132570458892032b69ff188bc3')
def test_grab_invalid_player(self): def test_grab_invalid_player(self):
self.assertRaises(UsernameLookupFailed, grab_UUID, 'lsdlkjsljglfjgldkj') self.assertRaises(UsernameLookupFailed, grab_UUID, 'lsdlkjsljglfjgldkj')

View File

@ -1,13 +1,16 @@
from unittest import TestCase from unittest import TestCase
import os
from Commands import * from Commands import *
from BotConfig import * from BotConfig import get_config
from MinecraftAccountInfoGrabber import * from MinecraftAccountInfoGrabber import *
from time import sleep from time import sleep
class StressTest(TestCase): class StressTest(TestCase):
def setUp(self): def setUp(self):
self.commands = Commands(bot_config.config['SQL']['test_args']) path = os.path.dirname(os.path.abspath(__file__))
self.bot_config = get_config('{}/GeoffreyConfig.ini'.format(path))
self.commands = Commands(self.bot_config, True)
def clr_db(self): def clr_db(self):
self.session = self.commands.interface.database.Session() self.session = self.commands.interface.database.Session()
@ -16,12 +19,12 @@ class StressTest(TestCase):
def test_commands(self): def test_commands(self):
self.clr_db() self.clr_db()
self.commands.register('ZeroHD', '143072699567177728') self.commands.register('BirbHD', '143072699567177728')
for i in range(0, 1000): for i in range(0, 1000):
self.commands.add_shop(0, 0, shop_name='test shop{}'.format(i), discord_uuid='143072699567177728') self.commands.add_shop(0, 0, shop_name='test shop{}'.format(i), discord_uuid='143072699567177728')
self.commands.find('ZeroHD') self.commands.find('BirbHD')
sleep(0.5) sleep(0.5)