2018-08-30 16:34:19 +00:00
|
|
|
import os
|
2018-09-14 13:21:02 +00:00
|
|
|
import time
|
2018-07-22 23:56:07 +00:00
|
|
|
from unittest import TestCase
|
2018-08-12 19:00:04 +00:00
|
|
|
|
2018-07-22 23:56:07 +00:00
|
|
|
from Commands import *
|
2018-08-29 21:10:35 +00:00
|
|
|
from BotConfig import get_config
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCommands(TestCase):
|
|
|
|
def setUp(self):
|
2018-08-30 16:34:19 +00:00
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
self.bot_config = get_config('{}/GeoffreyConfig.ini'.format(path))
|
2018-08-29 21:10:35 +00:00
|
|
|
self.commands = Commands(self.bot_config, True)
|
2018-07-22 23:56:07 +00:00
|
|
|
self.session = self.commands.interface.database.Session()
|
|
|
|
self.commands.interface.database.clear_all(self.session)
|
|
|
|
self.session.close()
|
|
|
|
|
|
|
|
def test_get_player(self):
|
|
|
|
session = self.commands.interface.database.Session()
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.interface.add_player(session, 'BirbHD', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
player = self.commands.get_player(session, discord_uuid='143072699567177728')
|
|
|
|
|
2018-09-10 14:24:15 +00:00
|
|
|
self.assertEqual(player.name, 'BirbHD')
|
2018-07-22 23:56:07 +00:00
|
|
|
self.session.close()
|
|
|
|
|
|
|
|
def test_register(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
player = self.commands.get_player(self.session, discord_uuid='143072699567177728')
|
|
|
|
|
2018-09-10 14:24:15 +00:00
|
|
|
self.assertEqual(player.name, 'BirbHD')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
def test_addbase(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
player_name = self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
base = self.commands.add_base(0, 0, discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if player_name not in base:
|
|
|
|
self.fail()
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_addshop(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
player_name = self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
shop = self.commands.add_shop(0, 0, discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if player_name not in shop:
|
|
|
|
self.fail()
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2018-07-24 01:12:23 +00:00
|
|
|
def test_addtunnel(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
tunnel2 = self.commands.add_tunnel("East", 50, location_name='test_shop',
|
2018-08-26 22:47:33 +00:00
|
|
|
discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
if "East" not in tunnel2:
|
2018-07-22 23:56:07 +00:00
|
|
|
self.fail()
|
2018-07-29 13:59:11 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
self.assertRaises(LocationHasTunnelError, self.commands.add_tunnel, "East", 50,
|
2018-08-26 22:47:33 +00:00
|
|
|
location_name='test_shop', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
def test_find(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
self.commands.add_base(0, 0, 'heck', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-09-10 14:24:15 +00:00
|
|
|
result = self.commands.find('BirbHD')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if ('frick' in result) & ('heck' in result):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
def test_delete(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
self.commands.delete('frick', discord_uuid='143072699567177728')
|
|
|
|
|
2018-09-10 14:24:15 +00:00
|
|
|
self.assertRaises(LocationLookUpError, self.commands.find, 'BirbHD')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
def test_findaround(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
result = self.commands.find_around(0, 0)
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if 'frick' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
def test_additem(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
self.commands.add_shop(0, 0, discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
result = self.commands.add_item('dirt', 5, 5, None, discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if 'dirt' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
result = self.commands.add_item('cool', 5, 5, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
if 'cool' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
def test_selling(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
self.commands.add_item('cool', 5, 5, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
result = self.commands.selling('cool')
|
|
|
|
|
|
|
|
if 'cool' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
def test_info(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
self.commands.add_tunnel("West", 50, location_name='frick', discord_uuid='143072699567177728')
|
2018-07-22 23:56:07 +00:00
|
|
|
|
|
|
|
result = self.commands.info('frick')
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
if "West" in result:
|
2018-07-22 23:56:07 +00:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
2018-07-24 01:12:23 +00:00
|
|
|
|
|
|
|
def test_tunnel(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-09-13 18:28:18 +00:00
|
|
|
|
|
|
|
self.assertRaises(NoLocationsInDatabase, self.commands.add_tunnel, "soUTH", 50, None,
|
|
|
|
discord_uuid='143072699567177728')
|
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
2018-07-24 01:12:23 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
self.commands.add_tunnel("soUTH", 50, None, discord_uuid='143072699567177728')
|
2018-07-24 01:12:23 +00:00
|
|
|
|
2018-09-10 14:24:15 +00:00
|
|
|
result = self.commands.tunnel('BirbHD')
|
2018-07-24 01:12:23 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
if "South" in result:
|
2018-07-24 01:12:23 +00:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
2018-07-29 13:59:11 +00:00
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
def test_edit_name(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
|
|
|
|
self.commands.edit_name('cool shop', 'test shop', discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
result = self.commands.info('cool shop')
|
|
|
|
|
|
|
|
if 'cool' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
def test_edit_pos(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
|
|
|
|
self.commands.edit_pos(500, 500, 'test shop', discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
result = self.commands.info('test shop')
|
|
|
|
|
|
|
|
if '500' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
2018-08-05 14:08:20 +00:00
|
|
|
self.commands.edit_pos(500, 500, None, discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
if '500' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
|
|
|
self.commands.delete(name='test shop', discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
self.assertRaises(LocationLookUpError, self.commands.edit_pos, 5, 5, None,
|
|
|
|
discord_uuid='143072699567177728')
|
|
|
|
|
2018-08-01 00:22:17 +00:00
|
|
|
def test_edit_tunnel(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
self.commands.edit_tunnel("West", 500, 'test shop', discord_uuid='143072699567177728')
|
2018-08-01 00:22:17 +00:00
|
|
|
|
|
|
|
result = self.commands.info('test shop')
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
if "West" in result:
|
2018-08-01 00:22:17 +00:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
2018-08-01 01:16:14 +00:00
|
|
|
def test_delete_item(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-01 01:16:14 +00:00
|
|
|
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('wood', 5, 5, shop_name='test shop', discord_uuid='143072699567177728')
|
|
|
|
|
2018-09-13 16:25:40 +00:00
|
|
|
self.commands.delete_item('dirt', None, discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
self.assertRaises(ItemNotFound, self.commands.selling, 'dirt')
|
2018-08-01 01:16:14 +00:00
|
|
|
|
|
|
|
|
2018-08-05 14:08:20 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop2', discord_uuid='143072699567177728')
|
|
|
|
self.assertRaises(EntryNameNotUniqueError, self.commands.delete_item, 'wood', None,
|
|
|
|
discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
self.commands.delete('test shop', discord_uuid='143072699567177728')
|
|
|
|
self.commands.delete('test shop2', discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
self.assertRaises(LocationLookUpError, self.commands.delete_item, 'wood', None,
|
|
|
|
discord_uuid='143072699567177728')
|
2018-08-10 23:03:30 +00:00
|
|
|
|
|
|
|
def test_me(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-10 23:03:30 +00:00
|
|
|
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
result = self.commands.me(discord_uuid='143072699567177728')
|
|
|
|
|
|
|
|
if 'test shop' in result:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.fail()
|
|
|
|
|
2018-08-11 19:20:27 +00:00
|
|
|
def test_update_mc_uuid(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-11 19:20:27 +00:00
|
|
|
|
2018-09-13 17:06:37 +00:00
|
|
|
self.commands.update_mc_uuid('143072699567177728', '0')
|
2018-08-11 19:20:27 +00:00
|
|
|
|
|
|
|
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
2018-08-11 23:02:50 +00:00
|
|
|
mc_uuid='fe7e84132570458892032b69ff188bc3')
|
2018-08-11 19:20:27 +00:00
|
|
|
|
|
|
|
def test_update_mc_name(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-11 19:20:27 +00:00
|
|
|
|
|
|
|
self.commands.update_mc_name('143072699567177728')
|
|
|
|
|
|
|
|
def test_update_discord_uuid(self):
|
2018-09-10 14:24:15 +00:00
|
|
|
self.commands.register('BirbHD', '143072699567177728')
|
2018-08-11 19:20:27 +00:00
|
|
|
|
|
|
|
self.commands.update_discord_uuid('143072699567177728', '0')
|
|
|
|
|
|
|
|
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
2018-08-11 23:02:50 +00:00
|
|
|
discord_uuid='143072699567177728')
|
2018-09-14 13:21:02 +00:00
|
|
|
|
|
|
|
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)
|