Added an interface layer for discord so discord uuids can be used for tracking player info. This will also alow a MC interface to be created when plugin support is added

doc_update
Joey Hines 2018-07-08 14:19:40 -05:00
parent 06f5feae4e
commit 1ca6603f2a
4 changed files with 248 additions and 129 deletions

View File

@ -2,7 +2,7 @@ from sqlalchemy import Column, Integer, String, ForeignKey, Enum
import enum
from sqlalchemy.ext.declarative import declarative_base
from BotErrors import *
from sqlalchemy import create_engine, exists, func
from sqlalchemy import create_engine, exists, literal
from sqlalchemy.orm import sessionmaker, relationship
import sqlalchemy
from MinecraftAccountInfoGrabber import *
@ -10,93 +10,82 @@ from MinecraftAccountInfoGrabber import *
SQL_Base = declarative_base()
class GeoffreyDatabase:
class DatabaseInterface:
def __init__(self, engine_arg):
self.engine = create_engine(engine_arg, echo=True)
Session = sessionmaker(bind=self.engine)
self.session = Session()
SQL_Base.metadata.create_all(self.engine)
def __init__(self, db_engine_arg):
self.database = GeoffreyDatabase(db_engine_arg)
def add_location(self, player_name, name, x_pos, y_pos, z_pos, args):
owner = self.add_player(player_name)
def add_location(self, owner, name, x_pos, y_pos, z_pos, args):
location = Location(name, x_pos, y_pos, z_pos, owner, args)
self.add_object(location)
self.database.add_object(location)
return location
def add_shop(self, player_name, name, x_pos, y_pos, z_pos, args):
owner = self.add_player(player_name)
def add_shop(self, owner, name, x_pos, y_pos, z_pos, args):
shop = Shop(name, x_pos, y_pos, z_pos, owner, args)
self.add_object(shop)
self.database.add_object(shop)
return shop
def add_item(self, player_name, shop_name, item_name, price, amount):
def add_item(self, owner, shop_name, item_name, price, amount):
try:
shop = self.find_shop_by_name_and_owner(player_name, shop_name)
shop = self.find_shop_by_name_and_owner(owner, shop_name)
item = ItemListing(item_name, price, amount, shop[0])
self.add_object(item)
self.database.add_object(item)
except IndexError:
raise LocationLookUpError
return item
def add_player(self, player_name):
def add_player(self, player_name, discord_id):
try:
player = self.find_player(player_name)
except PlayerNotFound:
try:
uuid = grab_UUID(player_name)
player = self.find_player_by_uuid(uuid)
player = self.find_player_by_mc_uuid(uuid)
except PlayerNotFound:
player = Player(player_name)
self.add_object(player)
self.database.add_object(player, discord_id)
finally:
player.name = player_name
self.session.commit()
self.database.session.commit()
return player
def add_object(self, obj):
ret = not self.session.query(exists().where(type(obj).id == obj.id))
if not ret:
self.session.add(obj)
self.session.commit()
def find_location_by_name(self, name):
expr = Location.name.ilike('%{}%'.format(name))
return self.query_by_filter(Location, expr)
return self.database.query_by_filter(Location, expr)
def find_shop_by_name(self, name):
expr = Location.name.ilike('%{}%'.format(name))
return self.query_by_filter(Shop, expr)
return self.database.query_by_filter(Shop, expr)
def find_location_by_owner(self, owner_name):
player = self.find_player(owner_name)
expr = Location.owner == player
return self.query_by_filter(Location, expr)
def find_location_by_owner(self, owner):
expr = Location.owner == owner
return self.database.query_by_filter(Location, expr)
def find_shop_by_name_and_owner(self, owner_name, name):
player = self.find_player(owner_name)
expr = (Shop.owner == player) & (Shop.name.ilike(name))
return self.query_by_filter(Shop, expr)
def find_location_by_owner_name(self, owner_name):
owner = self.find_player(owner_name)
return self.find_location_by_owner(owner)
def find_location_by_name_and_owner(self, owner_name, name):
player = self.find_player(owner_name)
expr = (Location.owner == player) & (Location.name.ilike(name))
return self.query_by_filter(Location, expr)
def find_shop_by_name_and_owner(self, owner, name):
expr = (Shop.owner == owner) & (Shop.name.ilike(name))
return self.database.query_by_filter(Shop, expr)
def find_location_by_name_and_owner(self, owner, name):
expr = (Location.owner == owner) & (Location.name.ilike(name))
return self.database.query_by_filter(Location, expr)
def find_location_around(self, x_pos, z_pos, radius):
radius = radius + 1 #gets a the correct area
expr = (Location.x < x_pos + radius) & (Location.x > x_pos - radius) & (Location.z < z_pos + radius) & \
(Location.z > z_pos - radius)
expr = (Location.x < x_pos + radius + 1) & (Location.x > x_pos - radius - 1) & (Location.z < z_pos + radius + 1) \
& (Location.z > z_pos - radius - 1)
return self.query_by_filter(Location, expr)
return self.database.query_by_filter(Location, expr)
def find_item(self, item_name):
expr = ItemListing.name.ilike('{}'.format(item_name))
return self.query_by_filter(ItemListing, expr)
expr = ItemListing.name.ilike('%{}%'.format(item_name))
return self.database.query_by_filter(ItemListing, expr)
def find_shop_selling_item(self, item_name):
listings = self.find_item(item_name)
@ -109,20 +98,30 @@ class GeoffreyDatabase:
return shops
def find_player(self, player_name):
expr = Player.name.like(player_name)
expr = Player.name.ilike(player_name)
try:
player = self.query_by_filter(Player, expr)[0]
player = self.database.query_by_filter(Player, expr)[0]
except IndexError:
raise PlayerNotFound
return player
def find_player_by_uuid(self, uuid):
def find_player_by_mc_uuid(self, uuid):
expr = Player.id == uuid
try:
player = self.query_by_filter(Player, expr)[0]
player = self.database.query_by_filter(Player, expr)[0]
except IndexError:
raise PlayerNotFound
return player
def find_player_by_discord_uuid(self, uuid):
expr = Player.discord_uuid == uuid
try:
player = self.database.query_by_filter(Player, expr)[0]
except IndexError:
raise PlayerNotFound
@ -131,18 +130,78 @@ class GeoffreyDatabase:
def get_shop_inventory(self, shop):
expr = ItemListing.shop == shop
return self.query_by_filter(ItemListing, expr)
return self.database.query_by_filter(ItemListing, expr)
def delete_location(self, owner, name):
expr = (Location.owner == owner) & (Location.name == name)
self.database.delete_entry(Location, expr)
class DiscordDatabaseInterface(DatabaseInterface):
def add_location(self, owner_uuid, name, x_pos, y_pos, z_pos, args):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.add_location(self, owner, name, x_pos, y_pos, z_pos, args)
def add_shop(self, owner_uuid, name, x_pos, y_pos, z_pos, args):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.add_shop(self, owner, name, x_pos, y_pos, z_pos, args)
def add_item(self, owner_uuid, shop_name, item_name, price, amount):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.add_item(self, owner, shop_name, item_name, price, amount)
def add_player(self, player_name, discord_id):
try:
player = self.find_player(player_name)
except PlayerNotFound:
try:
uuid = grab_UUID(player_name)
player = self.find_player_by_mc_uuid(uuid)
except PlayerNotFound:
player = Player(player_name, discord_id)
self.database.add_object(player)
finally:
player.name = player_name
self.database.session.commit()
return player
def find_location_by_owner_uuid(self, owner_uuid):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.find_location_by_owner(self, owner)
def find_shop_by_name_and_owner_uuid(self, owner_uuid, name):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.find_shop_by_name_and_owner(self, owner, name)
def find_location_by_name_and_owner_uuid(self, owner_uuid, name):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.find_location_by_name_and_owner(self, owner, name)
def delete_location(self, owner_uuid, name):
owner = DatabaseInterface.find_player_by_discord_uuid(self, owner_uuid)
return DatabaseInterface.delete_location(self, owner, name)
class GeoffreyDatabase:
def __init__(self, engine_arg):
self.engine = create_engine(engine_arg, echo=True)
Session = sessionmaker(bind=self.engine)
self.session = Session()
SQL_Base.metadata.create_all(self.engine)
def add_object(self, obj):
ret = not self.session.query(exists().where(type(obj).id == obj.id))
if not ret:
self.session.add(obj)
self.session.commit()
def query_by_filter(self, obj_type, * args):
filter_value = self.combine_filter(args)
return self.session.query(obj_type).filter(filter_value).all()
def delete_base(self, player_name, base_name):
player = self.find_player(player_name)
expr = (Location.owner == player) & (Location.name == base_name)
self.delete_entry(Location, expr)
def delete_entry(self, obj_type, * args):
filter_value = self.combine_filter(args)
entry = self.session.query(obj_type).filter(filter_value)
@ -216,16 +275,17 @@ class Dimension(enum.Enum):
raise ValueError
class Player(SQL_Base):
__tablename__ = 'Players'
id = Column(String, primary_key=True, autoincrement=False)
id = Column(Integer, primary_key=True, autoincrement=True)
mc_uuid = Column(String)
discord_uuid = Column(String)
name = Column(String)
locations = relationship("Location", back_populates="owner", lazy='dynamic')
def __init__(self, name):
self.id = grab_UUID(name)
def __init__(self, name, discord_id=None):
self.mc_uuid = grab_UUID(name)
self.discord_uuid = discord_id
self.name = name
@ -266,8 +326,9 @@ class Location(SQL_Base):
if len(args) > 3:
self.dimension = Dimension.str_to_dimension(args[3])
else:
self.dimension = Dimension.str_to_dimension("overworld")
if self.dimension is None:
self.dimension = Dimension.overworld
except (ValueError, IndexError):
raise LocationInitError

View File

@ -37,14 +37,18 @@ async def on_command_error(error, ctx):
elif isinstance(error, commands.UserInputError):
error_str = 'Invalid syntax for {} you ding dong, please read ?help {}.'\
.format(ctx.invoked_with, ctx.invoked_with)
database_interface.database.session.rollback()
elif isinstance(error.original, UsernameLookupFailed):
error_str = error.original.__doc__
elif isinstance(error.original, OverflowError):
error_str = 'Wow buddy, that\'s a big number. Please don\'t do that.'
database.session.rollback()
database_interface.database.session.rollback()
elif isinstance(error.original, PlayerNotFound):
error_str = 'Make sure to use ?register first you ding dong.'
database_interface.database.session.rollback()
elif isinstance(error.original, sqlite3.IntegrityError):
error_str = 'Off, the fuck did you do? Try the command again but be less of a ding dong with it.'
database.session.rollback()
database_interface.database.session.rollback()
else:
error_str = bad_error_message.format(ctx.invoked_with, error)
@ -58,6 +62,22 @@ async def test():
'''
await bot.say('I\'m here you ding dong')
@bot.command(pass_context=True)
async def register(ctx):
'''
Registers your discord and minecraft account with the the database. You must do this before adding entries to
the database.
'''
player_name = get_nickname(ctx.message.author)
try:
database_interface.add_player(player_name, ctx.message.author.id)
except LocationInitError:
raise commands.UserInputError
await bot.say('{}, you have been added to the database.'.format(ctx.message.author.mention))
@bot.command(pass_context=True)
async def addbase(ctx, name: str, x_pos: int, y_pos: int, z_pos: int, * args):
@ -65,13 +85,14 @@ async def addbase(ctx, name: str, x_pos: int, y_pos: int, z_pos: int, * args):
Add your base to the database.
The tunnel address is optional.
The default dimension is the overworld. Valid options: overworld, nether, end
?addbase [Base Name] [X Coordinate] [Y Coordinate] [Z Coordinate] [Tunnel Color] [Tunnel Position] [Side] [Dimension]
?addbase [Base Name] [X Coordinate] [Y Coordinate] [Z Coordinate] [Tunnel Color]
[Tunnel Position] [Side] [Dimension]
'''
player_name = get_nickname(ctx.message.author)
try:
base = database.add_location(player_name, name, x_pos, y_pos, z_pos, args)
base = database_interface.add_location(ctx.message.author.id, name, x_pos, y_pos, z_pos, args)
except LocationInitError:
raise commands.UserInputError
@ -84,18 +105,19 @@ async def addshop(ctx, name: str, x_pos: int, y_pos: int, z_pos: int, * args):
Adds a shop to the database.
The tunnel address is optional.
The default dimension is the overworld. Valid options: overworld, nether, end
?addbase [Base Name] [X Coordinate] [Y Coordinate] [Z Coordinate] [Tunnel Color] [Tunnel Position] [Side] {Dimension]
?addbase [Base Name] [X Coordinate] [Y Coordinate] [Z Coordinate] [Tunnel Color]
[Tunnel Position] [Side] {Dimension]
'''
player_name = get_nickname(ctx.message.author)
try:
base = database.add_shop(player_name, name, x_pos, y_pos, z_pos, args)
shop = database_interface.add_shop(ctx.message.author.id, name, x_pos, y_pos, z_pos, args)
except LocationInitError:
raise commands.UserInputError
await bot.say('{}, your shop named **{}** located at {} has been added.'
' to the database.'.format(ctx.message.author.mention, base.name, base.pos_to_str()))
' to the database.'.format(ctx.message.author.mention, shop.name, shop.pos_to_str()))
@bot.command(pass_context=True)
@ -106,7 +128,7 @@ async def find(ctx, name: str):
'''
try:
loc_list = database.find_location_by_owner(name)
loc_list = database_interface.find_location_by_owner_name(name)
loc_string = loc_list_to_string(loc_list, '{} \n{}')
await bot.say('{}, **{}** has **{}** locations(s): \n {}'.format(ctx.message.author.mention, name, len(loc_list),
@ -123,7 +145,7 @@ async def delete(ctx, name: str):
player_name = get_nickname(ctx.message.author)
try:
database.delete_base(player_name, name)
database_interface.delete_base(player_name, name)
await bot.say('{}, your location named **{}** has been deleted.'.format(ctx.message.author.mention, name))
except (DeleteEntryError, PlayerNotFound):
await bot.say('{}, you do not have a location named **{}**.'.format(ctx.message.author.mention, name))
@ -144,7 +166,7 @@ async def findaround(ctx, x_pos: int, z_pos: int, * args):
except ValueError:
raise commands.UserInputError
base_list = database.find_location_around(x_pos, z_pos, radius)
base_list = database_interface.find_location_around(x_pos, z_pos, radius)
if len(base_list) != 0:
base_string = loc_list_to_string(base_list, '{} \n{}')
@ -165,7 +187,7 @@ async def additem(ctx, shop_name: str, item_name: str, amount: int, diamond_pric
try:
player_name = get_nickname(ctx.message.author)
database.add_item(player_name, shop_name, item_name, diamond_price, amount)
database_interface.add_item(ctx.message.author.id, shop_name, item_name, diamond_price, amount)
await bot.say('{}, **{}** has been added to the inventory of **{}**.'.format(ctx.message.author.mention,
item_name, shop_name))
@ -182,7 +204,7 @@ async def selling(ctx, item_name: str):
Lists all the shops selling an item
?selling [item]
'''
shop_list = database.find_shop_selling_item(item_name)
shop_list = database_interface.find_shop_selling_item(item_name)
shop_list_str = loc_list_to_string(shop_list)
await bot.say('The following shops sell {}: \n {}'.format(item_name, shop_list_str))
@ -194,8 +216,8 @@ async def shopinfo(ctx, shop_name: str):
Lists the information and inventory of a shop
?shopinfo [Shop Name]
'''
shop = database.find_shop_by_name(shop_name)[0]
inv_list = database.get_shop_inventory(shop)
shop = database_interface.find_shop_by_name(shop_name)[0]
inv_list = database_interface.get_shop_inventory(shop)
item_list = ''
for item in inv_list:
@ -265,7 +287,7 @@ else:
else:
engine_arg = get_engine_arg(config)
database = GeoffreyDatabase(engine_arg)
database_interface = DiscordDatabaseInterface(engine_arg)
#WebInterface('127.0.0.1', 8081, database)
bot.run(TOKEN)

View File

@ -2,6 +2,7 @@ import requests
from json import JSONDecodeError
from BotErrors import UsernameLookupFailed
uuid_lookup_url = 'https://api.mojang.com/users/profiles/minecraft/{}'
username_lookup_url = 'https://api.mojang.com/user/profiles/{}/names'
@ -17,9 +18,8 @@ def grab_UUID(username):
except JSONDecodeError:
raise UsernameLookupFailed
def grab_playername(uuid):
player_data = grab_json(username_lookup_url.format(uuid))
return player_data[0]['name']

View File

@ -3,130 +3,164 @@ from DatabaseModels import *
from BotErrors import *
from MinecraftAccountInfoGrabber import *
class TestGeoffreyDatabase(TestCase):
def setUp(self):
self.database = GeoffreyDatabase('sqlite:///:memory:')
self.owner = Player('ZeroHD')
self.loc = Location('test', 1, 2, 3, self.owner, ['Green', 0, 'Right'])
self.interface = DiscordDatabaseInterface('sqlite:///:memory:')
self.owner = Player('ZeroHD', '143072699567177728')
self.loc = Location('test', 1, 2, 3, self.owner, ['Green', 0, 'Right', 'Nether'])
def test_add_object(self):
self.database.add_object(self.loc)
self.database.add_object(self.owner)
self.interface.database.add_object(self.loc)
self.interface.database.add_object(self.owner)
uuid = grab_UUID('ZeroHD')
expr = Player.id == uuid
p = self.database.query_by_filter(Player, expr)[0]
expr = Player.mc_uuid == uuid
p = self.interface.database.query_by_filter(Player, expr)[0]
expr = Location.owner == p
loc2 = self.database.query_by_filter(Location, expr)[0]
loc2 = self.interface.database.query_by_filter(Location, expr)[0]
self.assertEqual(self.loc.id, loc2.id)
def test_query_by_filter(self):
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.x == 0)
loc2 = self.database.query_by_filter(Location, expr)
self.assertEqual(len(loc2), 0)
self.interface.database.add_object(self.loc)
self.interface.database.add_object(self.owner)
expr = (Location.owner == self.owner)
loc2 = self.interface.database.query_by_filter(Location, expr)[0]
self.assertEqual(loc2.id, self.loc.id)
def test_delete_entry(self):
self.database.add_object(self.loc)
self.database.add_object(self.owner)
self.interface.database.add_object(self.loc)
self.interface.database.add_object(self.owner)
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.name == 'test')
self.database.delete_entry(Location, expr)
expr = Location.owner == self.owner
self.interface.database.delete_entry(Location, expr)
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.x == 0)
loc2 = self.database.query_by_filter(Location, expr)
loc2 = self.interface.database.query_by_filter(Location, expr)
self.assertEqual(len(loc2), 0)
self.assertRaises(DeleteEntryError, self.database.delete_entry, Location, expr)
self.assertRaises(DeleteEntryError, self.interface.database.delete_entry, Location, expr)
def test_add_shop(self):
shop = self.database.add_shop('ZeroHD', 'test', 1, 2, 3, ['Green', 0, 'Right'])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
shop = self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, ['Green', 0, 'Right', 'Nether'])
self.assertEqual(type(shop), Shop)
def test_add_two_shops(self):
shop1 = self.database.add_shop('ZeroHD', 'test', 1, 2, 3, ['Green', 0, 'Right'])
shop2 = self.database.add_shop('ZeroHD', 'no u', 1, 2, 3, ['Green', 0, 'Right'])
shop_list = self.interface.find_shop_by_name('test')
self.assertEqual(shop_list[0].dimension, shop.dimension)
self.assertEqual(shop_list[0].tunnel_side, shop.tunnel_side)
loc_list = self.database.find_location_by_owner('ZeroHD')
def test_add_two_shops(self):
owner = self.interface.add_player('ZeroHD', '143072699567177728')
shop1 = self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, ['Green', 0, 'Right', 'Nether'])
shop2 = self.interface.add_shop('143072699567177728', 'no u', 1, 2, 3, ['Green', 0, 'Right', 'Nether'])
loc_list = self.interface.find_location_by_owner_uuid('143072699567177728')
self.assertEqual(loc_list[1].id, shop2.id)
def test_add_item(self):
self.database.add_shop('ZeroHD', 'test', 1, 2, 3, ['Green', 0, "Right"])
self.database.add_item('ZeroHD', 'test', 'dirt', 1, 15)
owner = self.interface.add_player('ZeroHD', '143072699567177728')
self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, ['Green', 0, "Right"])
self.interface.add_item('143072699567177728', 'test', 'dirt', 1, 15)
shops = self.database.find_shop_selling_item('dirt')
shops = self.interface.find_shop_selling_item('dirt')
self.assertEqual(shops[0].name, 'test')
def test_find_location_by_owner(self):
shop = self.database.add_shop('ZeroHD', 'test', 1, 2, 3, ['Green', 0, "Right"])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
shop = self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, ['Green', 0, "Right"])
loc_list = self.database.find_location_by_owner('ZeroHD')
loc_list = self.interface.find_location_by_owner(owner)
self.assertEqual(loc_list[0].id, shop.id)
def test_find_location_by_name_and_owner(self):
shop = self.database.add_shop('ZeroHD', 'test', 1, 2, 3, ['Green', 0, "Right"])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
shop = self.interface.add_shop('143072699567177728', 'test', 1, 2, 3, ['Green', 0, "Right"])
loc_list = self.database.find_location_by_name_and_owner('ZeroHD','test')
loc_list = self.interface.find_location_by_name_and_owner_uuid('143072699567177728', 'test')
self.assertEqual(loc_list[0].id, shop.id)
def test_delete_base(self):
self.database.add_location('ZeroHD', 'test', 1, 2, 3, ['Green', 0, "Right"])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
self.interface.add_location('143072699567177728', 'test', 1, 2, 3, ['Green', 0, "Right"])
self.database.delete_base('ZeroHD', 'test')
self.interface.delete_location('143072699567177728', 'test')
loc_list = self.database.find_location_by_name_and_owner('ZeroHD', 'test')
loc_list = self.interface.find_location_by_name_and_owner_uuid('143072699567177728', 'test')
self.assertEqual(len(loc_list), 0)
def test_find_location_around(self):
loc = self.database.add_location('ZeroHD', 'test', 0, 0, 0, ['Green', 0, "Right"])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
loc = self.interface.add_location('143072699567177728', 'test', 0, 0, 0, ['Green', 0, "Right"])
loc_list = self.database.find_location_around(100, 100, 100)
loc_list = self.interface.find_location_around(100, 100, 100)
self.assertEqual(loc_list[0].name, loc.name)
loc_list = self.database.find_location_around(200, 200, 100)
loc_list = self.interface.find_location_around(200, 200, 100)
self.assertEqual(len(loc_list), 0)
def test_find_location_by_name(self):
loc = self.database.add_location('ZeroHD', 'test', 0, 0, 0, ['Green', 0, "Right"])
loc_list = self.interface.find_location_around(-100, -100, 100)
loc_list = self.database.find_location_by_name('test')
self.assertEqual(loc_list[0].name, loc.name)
loc_list = self.interface.find_location_around(100, -100, 100)
self.assertEqual(loc_list[0].name, loc.name)
loc_list = self.interface.find_location_around(-100, 100, 100)
self.assertEqual(loc_list[0].name, loc.name)
loc_list = self.interface.find_location_around(50, -50, 100)
self.assertEqual(loc_list[0].name, loc.name)
def test_find_location_by_name(self):
owner = self.interface.add_player('ZeroHD', '143072699567177728')
loc = self.interface.add_location('143072699567177728', 'test', 0, 0, 0, ['Green', 0, "Right"])
loc_list = self.interface.find_location_by_name('test')
self.assertEqual(loc_list[0].name, loc.name)
def test_wrong_case(self):
loc = self.database.add_location('ZeroHD', 'test', 0, 0, 0, ['Green', 0, "right"])
owner = self.interface.add_player('ZeroHD', '143072699567177728')
loc = self.interface.add_location('143072699567177728', 'test', 0, 0, 0, ['Green', 0, "right"])
loc_list = self.database.find_location_by_owner('zerohd')
loc_list = self.interface.find_location_by_owner_name('zerohd')
self.assertEqual(loc_list[0].id, loc.id)
self.database.add_shop('ZeroHD', 'testshop', 1, 2, 3, ['Green', 0, "lEft", "neThEr"])
self.interface.add_shop('143072699567177728', 'testshop', 1, 2, 3, ['Green', 0, "lEft", "neThEr"])
self.database.add_item('ZeroHD', 'testshop', 'dirt', 1, 15)
self.interface.add_item('143072699567177728', 'testshop', 'dirts', 1, 15)
shops = self.database.find_shop_selling_item('Dirts')
shops = self.interface.find_shop_selling_item('Dirt')
self.assertEqual(shops[0].name, 'testshop')
loc_list = self.database.find_location_by_name('TEST')
#shops = self.database.find_shop_selling_item('sDirt')
#self.assertEqual(shops[0].name, 'testshop')
loc_list = self.interface.find_location_by_name('TEST')
self.assertEqual(loc_list[0].name, 'test')
def test_big_input(self):
loc = self.database.add_location('ZeroHD',
owner = self.interface.add_player('ZeroHD', '143072699567177728')
loc = self.interface.add_location('143072699567177728',
'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT', 0, 0, 0, ['Green', 0, "Right"])
loc_list = self.database.find_location_by_owner('zerohd')
loc_list = self.interface.find_location_by_owner(owner)
self.assertEqual(loc_list[0].id, loc.id)
@ -134,3 +168,5 @@ class TestGeoffreyDatabase(TestCase):