Skip to content

Commit

Permalink
add filtering cloud host api by service form service env
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekBleschke committed Aug 21, 2020
1 parent 2e9864f commit ca53e67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ralph/virtual/api.py
Expand Up @@ -255,6 +255,12 @@ class CloudHostViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
),
]

filter_fields = [
'service_env__service__uid',
'service_env__service__name',
'service_env__service__id',
]


class CloudProjectViewSet(RalphAPIViewSet):
queryset = CloudProject.objects.all()
Expand Down
12 changes: 12 additions & 0 deletions src/ralph/virtual/tests/test_api.py
Expand Up @@ -140,6 +140,18 @@ def test_get_cloudhost_detail(self):
response.data['technical_owners'][0]['username'], 'user2'
)

def test_filter_cloudhost_by_service_uid(self):
cloud_host = CloudHostFactory()
url = (
reverse('cloudhost-list') +
'?service_env__service__uid={}'.format(cloud_host.service_env.service.uid)
)
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data['count'], 1
)

def test_get_cloudproject_detail(self):
url = reverse('cloudproject-detail', args=(self.cloud_project.id,))
response = self.client.get(url, format='json')
Expand Down

0 comments on commit ca53e67

Please sign in to comment.