Commit 496c6eb1 authored by lukas.burgey's avatar lukas.burgey
Browse files

Detect if a service does not exist

parent 5e8cf4ed
Pipeline #81769 failed with stage
in 1 minute and 46 seconds
......@@ -94,8 +94,9 @@ class BaseTestCase(TestCase):
user=cls.user,
).save()
# only needed to manually tear down the test data
@classmethod
def tearDownTestData(cls):
def manualTearDownTestData(cls):
# delete in reverse order
for member in [
'key',
......@@ -113,8 +114,8 @@ class BaseTestCase(TestCase):
if hasattr(cls, member):
try:
getattr(cls, member).delete()
# pylint: disable=bare-except
except:
# pylint: disable=bare-except
pass
......
......@@ -190,28 +190,26 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
raise exceptions.ValidationError('You have no VO with id "{}"'.format(dep_id))
if self.kwargs['type'] == 'service':
try:
# find service with id dep_id
service = None
for s in self.request.user.services:
if s.id == dep_id:
if service is None:
service = s
else:
raise Exception('user has multiple services with identical id')
dep, created = ServiceDeployment.objects.get_or_create(
user=self.request.user,
service=service,
defaults={},
)
if created:
LOGGER.debug('Created new ServiceDeployment')
return dep
except Service.DoesNotExist:
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
# find service with id dep_id
service = None
for s in self.request.user.services:
if s.id == dep_id:
if service is None:
service = s
else:
raise Exception('user has multiple services with identical id')
if service is None:
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
dep, created = ServiceDeployment.objects.get_or_create(
user=self.request.user,
service=service,
defaults={},
)
if created:
LOGGER.debug('Created new ServiceDeployment')
return dep
raise exceptions.ValidationError('Type must be either "service" or "vo"')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment