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)