Commit 9c96a3cb authored by lukas.burgey's avatar lukas.burgey

Remove get_deployment helpers for clarity

parent 00589692
......@@ -10,7 +10,7 @@ from rest_framework.test import APIClient
from feudal.backend.brokers import RabbitMQInstance
from feudal.backend.models import Site, Service
from feudal.backend.models.deployments import get_deployment, DEPLOYED
from feudal.backend.models.deployments import DEPLOYED, VODeployment, ServiceDeployment
from feudal.backend.models.users import User
from feudal.backend.models.auth import OIDCConfig
from feudal.backend.models.auth.vos import VO, Group, Entitlement
......@@ -187,7 +187,7 @@ def service(site, group, entitlement, vo):
# a deployment with a state
@pytest.fixture
def dep(user, service):
return get_deployment(user, service=service)
return ServiceDeployment.get_or_create(user, service)
@pytest.fixture
def dep_state(dep):
......@@ -261,9 +261,9 @@ def _typed_deployed_deployment(deployment_type, user, service, vo, downstream_te
# get a deployment for the user
dep = None
if deployment_type == 'vo':
dep = get_deployment(user, vo=vo)
dep = VODeployment.get_or_create(user, vo)
else:
dep = get_deployment(user, service=service)
dep = ServiceDeployment.get_or_create(user, service)
assert dep is not None
......@@ -320,10 +320,10 @@ def _typed_pending_deployment(deployment_type, user, service, vo):
# get a deployment for the user
dep = None
if deployment_type == 'vo':
dep = get_deployment(user, vo=vo)
dep = VODeployment.get_or_create(user, vo)
assert dep.vo == vo
else:
dep = get_deployment(user, service=service)
dep = ServiceDeployment.get_or_create(user, service)
assert dep is not None
......
......@@ -61,18 +61,6 @@ def user_info_default(): # pragma: no cover
return {}
def get_deployment(user, vo=None, service=None):
if vo is not None and service is None:
# get_deployment updates automatically
return VODeployment.get_deployment(user, vo)
if service is not None and vo is None:
# get_deployment updates automatically
return ServiceDeployment.get_deployment(user, service)
raise ValueError("Exactly one of 'vo' or 'service' must be set")
class Deployment(PolymorphicModel):
user = models.ForeignKey(
User,
......@@ -183,7 +171,7 @@ class VODeployment(Deployment):
return self.vo.services.all()
@classmethod
def get_deployment(cls, user, vo):
def get_or_create(cls, user, vo):
deployment, created = cls.objects.get_or_create(
user=user,
vo=vo,
......@@ -221,7 +209,7 @@ class ServiceDeployment(Deployment):
)
@classmethod
def get_deployment(cls, user, service):
def get_or_create(cls, user, service):
deployment, created = cls.objects.get_or_create(user=user, service=service)
if created:
......
......@@ -5,7 +5,7 @@ import logging
from feudal.backend.tests import BaseTestCase
from feudal.backend.models import Service
from feudal.backend.models.deployments import (
Deployment, get_deployment,
Deployment, VODeployment,
DEPLOYED, NOT_DEPLOYED, DEPLOYMENT_PENDING, REMOVAL_PENDING,
)
......@@ -130,22 +130,22 @@ class DeploymentTest(BaseTestCase):
self.assertEqual(deployment.state, NOT_DEPLOYED)
def test_group_with_no_service(self):
deployment = get_deployment(self.user, self.group_none)
deployment = VODeployment.get_or_create(self.user, self.group_none)
self.deployment_run(deployment, 0)
def test_group_with_service(self):
deployment = get_deployment(self.user, vo=self.group_one)
deployment = VODeployment.get_or_create(self.user, self.group_one)
self.deployment_run(deployment, 1)
def test_group_with_two_services(self):
deployment = get_deployment(self.user, vo=self.group_two)
deployment = VODeployment.get_or_create(self.user, self.group_two)
self.deployment_run(deployment, 2)
# a vo with one service gets another service *after* the user requested the deployment
def test_group_with_delayed_service(self):
deployment = get_deployment(self.user, self.group_one)
deployment = VODeployment.get_or_create(self.user, self.group_one)
self.deployment_run_delayed_service(deployment, self.group_one, 1)
# a vo with two services loses one service *after* the user requested the deployment
def test_group_with_vanishing_service(self):
get_deployment(self.user, vo=self.group_two)
VODeployment.get_or_create(self.user, self.group_two)
......@@ -211,14 +211,7 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
if self.kwargs['type'] == 'vo':
try:
vo = self.request.user.vos.get(id=dep_id)
dep, created = VODeployment.objects.get_or_create(
user=self.request.user,
vo=vo,
defaults={},
)
if created:
LOGGER.debug('Created new VO deployment')
return dep
return VODeployment.get_or_create(self.request.user, vo)
except VO.DoesNotExist:
raise exceptions.ValidationError('You have no VO with id "{}"'.format(dep_id))
......@@ -234,15 +227,7 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
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
return ServiceDeployment.get_or_create(self.request.user, service)
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