From 0cda503d6cd90a634d13470c04a06b93cfb5c5b6 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 2 Feb 2019 10:21:44 -0600 Subject: [PATCH] Added error to add_owner for when the new owner is already an owner --- api/commands.py | 5 ++++- test/test_commands.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/commands.py b/api/commands.py index 190779c..4d065c1 100644 --- a/api/commands.py +++ b/api/commands.py @@ -530,7 +530,7 @@ def add_owner(new_owner_name, location_name, discord_uuid=None, mc_uuid=None): :param discord_uuid: Discord UUID of the current owner :param mc_uuid: MC UUID of the current owner :return: Updated Location - :raises: PlayerNotFound, LocationLookupError + :raises: PlayerNotFound, LocationLookupError, PlayerInDBError ''' owner = get_player(discord_uuid, mc_uuid) @@ -541,6 +541,9 @@ def add_owner(new_owner_name, location_name, discord_uuid=None, mc_uuid=None): location = get_location(owner, location_name, Location) + if location.owner.filter(location__owner__name__iexact=new_owner_name): + raise PlayerInDBError + location.owner.add(new_owner) location.save() diff --git a/test/test_commands.py b/test/test_commands.py index 1296af0..30e9258 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -166,3 +166,5 @@ class CommandsAPITestCase(TestCase): shop = Shop.objects.get(owner__name__icontains="Vakky") self.assertEquals(shop.id, self.shop.id) + + self.assertRaises(PlayerInDBError, add_owner, new_owner.name, self.shop.name, discord_uuid=DISCORD_UUID)