Updated DatabaseInterface unit tests to have better code coverage.

doc_update
Joey Hines 2018-09-19 15:41:32 -05:00
parent 5f3d80683c
commit 63970bdbef
3 changed files with 40 additions and 11 deletions

View File

@ -117,7 +117,7 @@ class DatabaseInterface:
return player
def find_player_by_mc_uuid(self, session, uuid):
expr = Player.id == uuid
expr = Player.mc_uuid == uuid
try:
player = self.database.query_by_filter(session, Player, expr)[0]
@ -173,15 +173,6 @@ class DatabaseInterface:
self.database.delete_entry(session, Location, expr)
def check_similarity(a, b):
ratio = SequenceMatcher(None, a, b).ratio()
if (ratio > 0.6) or (a[0] == b[0]):
return True
else:
return False
def list_to_string(loc_list, str_format='{}\n{}'):
loc_string = ''

View File

@ -1 +1 @@
__version__ = '1.0.3'
__version__ = '1.1.0dev'

View File

@ -74,6 +74,11 @@ class TestGeoffreyDatabase(TestCase):
self.assertRaises(DeleteEntryError, self.interface.database.delete_entry, self.session, Location, expr)
def test_add_player(self):
self.add_player()
self.assertRaises(PlayerInDBError, self.interface.add_player, self.session, 'BirbHD',
discord_uuid='143072699567177728')
def test_add_shop(self):
owner = self.add_player()
shop = self.add_shop(owner)
@ -99,6 +104,21 @@ class TestGeoffreyDatabase(TestCase):
tunnel2 = self.interface.find_tunnel_by_owner_name(self.session, 'BirbHD')[0]
self.assertEqual(tunnel1, tunnel2)
self.assertRaises(EntryNameNotUniqueError, self.interface.add_tunnel, self.session, player, "South", 155, None)
loc = self.add_loc(player)
tunnel3 = self.interface.add_tunnel(self.session, player, "South", 155, 'test')
tunnel4 = self.interface.find_tunnel_by_owner_name(self.session, 'BirbHD')[0]
self.assertEqual(tunnel3, tunnel4)
self.assertRaises(LocationHasTunnelError, self.interface.add_tunnel, self.session, player, "South", 155,
'test')
self.assertRaises(LocationLookUpError, self.interface.add_tunnel, self.session, player, "South", 155,
'no u')
def test_add_item(self):
owner = self.add_player()
self.add_shop(owner)
@ -107,6 +127,24 @@ class TestGeoffreyDatabase(TestCase):
shops = self.interface.find_shop_selling_item(self.session, 'dirt')
self.assertGreater(len(shops), 0)
self.assertRaises(LocationLookUpError, self.interface.add_item, self.session, owner, 'no u', 'dirt', 1, 15)
def test_find_player_by_discord_uuid(self):
p1 = self.add_player()
p2 = self.interface.find_player_by_discord_uuid(self.session, 143072699567177728)
self.assertEquals(p1, p2)
self.assertRaises(PlayerNotFound, self.interface.find_player_by_discord_uuid, self.session, 143072698)
def test_find_player_by_mc_uuid(self):
p1 = self.add_player()
p2 = self.interface.find_player_by_mc_uuid(self.session, 'fe7e84132570458892032b69ff188bc3')
self.assertEquals(p1, p2)
self.assertRaises(PlayerNotFound, self.interface.find_player_by_discord_uuid, self.session, 143072698)
def test_find_location_by_owner(self):
owner = self.add_player()
shop = self.add_shop(owner)