Added add_owner command

+add_owner can add additional owners to a location
+added tests for add_owner
+updated some help messages
doc_update
Joey Hines 2019-02-02 09:34:49 -06:00
parent 095e00cb72
commit b744385a23
2 changed files with 44 additions and 4 deletions

View File

@ -46,9 +46,12 @@ def command(type):
def parse_help(func):
try:
match = re.search(".*:help:.*", func.__doc__)
return match.group(0).partition(":help: ")[-1]
except:
return ''
def get_player(discord_uuid=None, mc_uuid=None):
@ -135,7 +138,7 @@ def add_base(x_pos, z_pos, name=None, discord_uuid=None, mc_uuid=None):
:param mc_uuid: Minecraft UUID
:return: JSON representation of the new base
:raises: EntryNameNotUniqueError, PlayerNotFound, LocationLookupError
:help: Adds your base to the database. The base name is optional if this is your first base
:help: Adds your base to the database.
'''
return add_location(x_pos, z_pos, name=name, discord_uuid=discord_uuid, mc_uuid=mc_uuid, loc_type=Base)
@ -169,7 +172,7 @@ def add_tunnel(tunnel_direction, tunnel_number, location_name=None, discord_uuid
:param mc_uuid: Minecraft UUID
:return: JSON Representation of the Tunnel
:raises: PlayerNotFound, LocationHasTunnelError, EntryNameNotUniqueError, NoLocationsInDatabase, InvalidTunnelError
:help: Adds your tunnel to the database. If you only have one location, you do not need to specify a location name
:help: Adds your tunnel to the database.
'''
player = get_player(discord_uuid, mc_uuid)
if location_name is None:
@ -228,6 +231,7 @@ def delete(name, discord_uuid=None, mc_uuid=None):
return name
@command("GET")
def find_around(x_pos, z_pos, radius=200):
'''
@ -515,3 +519,30 @@ def restock(item_name, shop_name=None, discord_uuid=None, mc_uuid=None):
item.save()
return objects_list_to_json(items)
@command("POST")
def add_owner(new_owner_name, location_name, discord_uuid=None, mc_uuid=None):
'''
:request: POST
:param new_owner_name: The MC username of the new owner
:param location_name: The name of the location to add them to
:param discord_uuid: Discord UUID of the current owner
:param mc_uuid: MC UUID of the current owner
:return: Updated Location
:raises: PlayerNotFound, LocationLookupError
'''
owner = get_player(discord_uuid, mc_uuid)
try:
new_owner = Player.objects.get(name__iexact=new_owner_name)
except Player.DoesNotExist:
raise PlayerNotFound("New Owner Not in DB")
location = get_location(owner, location_name, Location)
location.owner.add(new_owner)
location.save()
return location.json

View File

@ -157,3 +157,12 @@ class CommandsAPITestCase(TestCase):
old_item = ItemListing.objects.get(item_name="sed")
self.assertGreater(old_item.date_restocked, new_item.date_restocked)
def test_add_owner(self):
self.populate()
new_owner = Player.objects.create(name="Vakky", mc_uuid="5", discord_uuid="5")
add_owner(new_owner.name, self.shop.name, discord_uuid=DISCORD_UUID)
shop = Shop.objects.get(owner__name__icontains="Vakky")
self.assertEquals(shop.id, self.shop.id)