Commit c1b50096 authored by lukas.burgey's avatar lukas.burgey

Modernize the tests for views.rest

parent 2f344d63
Pipeline #110789 passed with stage
in 1 minute and 37 seconds
......@@ -574,6 +574,7 @@ class UserPreferences(models.Model):
DEPLOYMENT_MODE_BOTH = 'both'
DEPLOYMENT_MODE_SERVICES_ONLY = 'services-only'
DEPLOYMENT_MODE_VOS_ONLY = 'vos-only'
DEPLOYMENT_MODE_DEFAULT = DEPLOYMENT_MODE_BOTH
DEPLOYMENT_MODE_CHOICES = (
(DEPLOYMENT_MODE_BOTH, 'Pick a combination of services and VOs for deployment.'),
......@@ -584,5 +585,5 @@ class UserPreferences(models.Model):
deployment_mode = models.CharField(
max_length=20,
choices=DEPLOYMENT_MODE_CHOICES,
default=DEPLOYMENT_MODE_BOTH,
default=DEPLOYMENT_MODE_DEFAULT,
)
......@@ -93,19 +93,3 @@ class BaseTestCase(TestCase):
user=cls.user,
).save()
# the user is logged in using session authentication
class LoggedInTest(BaseTestCase):
client = None
def setUp(self):
self.client = Client()
user = authenticate(
username=self.USER_NAME,
password=self.USER_PASSWORD,
)
self.assertIsNotNone(user)
self.client.force_login(
user=user,
)
......@@ -112,8 +112,10 @@ class ServiceView(generics.RetrieveAPIView):
serializer_class = ServiceSerializer
def get_object(self):
available_services = Service.objects.filter(vos__user=self.request.user).distinct()
LOGGER.debug('Available services: %s', available_services)
return get_object_or_404(
Service.objects.filter(vos__user=self.request.user),
available_services,
id=self.kwargs['id'],
)
......@@ -213,10 +215,8 @@ class DeploymentView(generics.RetrieveUpdateAPIView):
service = None
for s in self.request.user.services:
if s.id == int(dep_id):
if service is None:
service = s
else:
raise Exception('user has multiple services with identical id')
service = s
break
if service is None:
raise exceptions.ValidationError('You are not permitted to access a service with id "{}"'.format(dep_id))
......@@ -283,22 +283,23 @@ URLPATTERNS = [
path('user-prefs', UserPreferencesView.as_view(), name='user-prefs'),
path('services', ServiceListView.as_view(), name='user-services'),
path('services', ServiceListView.as_view(), name='user-service-list'),
re_path(r'^service/(?P<id>[0-9]+)$', ServiceView.as_view(), name='user-service'),
path('vos', VOListView.as_view(), name='user-vos'),
path('vos', VOListView.as_view(), name='user-vo-list'),
re_path(r'^vo/(?P<id>[0-9]+)$', VOView.as_view(), name='user-vo'),
path('ssh-keys', SSHPublicKeyListView.as_view(), name='user-sshkeys'),
re_path(r'^ssh-key/(?P<id>[0-9]+)$', SSHPublicKeyView.as_view(), name='user-sshkey'),
path('ssh-keys', SSHPublicKeyListView.as_view(), name='user-ssh-key-list'),
re_path(r'^ssh-key/(?P<id>[0-9]+)$', SSHPublicKeyView.as_view(), name='user-ssh-key'),
# type is either 'vo' or 'service'
re_path(r'^deployments/?(?P<type>.+)?$', DeploymentListView.as_view(), name='user-deps'),
re_path(r'^deployments/?(?P<type>.+)?$', DeploymentListView.as_view(), name='user-dep-list'),
re_path(r'^deployment/(?P<type>.+)/(?P<id>[0-9]+)$', DeploymentView.as_view(), name='user-dep'),
path('states', DeploymentStateListView.as_view(), name='user-dep-states'),
path('states', DeploymentStateListView.as_view(), name='user-dep-state-list'),
re_path(r'^state/(?P<id>[0-9]+)$', DeploymentStateView.as_view(), name='user-dep-state'),
# this catch all must be last in the list!
path('', HelpView.as_view(), name='user-help'),
re_path(r'.*$', HelpView.as_view()),
]
This diff is collapsed.
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