Skip to content

Commit eeab1df

Browse files
author
Matthew Fisher
committed
Merge pull request #3308 from bacongobbler/3239-domain-removes-latest
fix(controller): retrieve requested domain from .get_object
2 parents 7d04f3a + f934dbe commit eeab1df

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

controller/api/tests/test_domain.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from django.test import TestCase
1313
from rest_framework.authtoken.models import Token
1414

15+
from api.models import Domain
16+
1517

1618
class DomainTest(TestCase):
1719

@@ -78,6 +80,26 @@ def test_manage_domain(self):
7880
HTTP_AUTHORIZATION='token {}'.format(self.token))
7981
self.assertEqual(0, response.data['count'], msg)
8082

83+
def test_delete_domain_does_not_remove_latest(self):
84+
"""https://github.com/deis/deis/issues/3239"""
85+
url = '/v1/apps/{app_id}/domains'.format(app_id=self.app_id)
86+
test_domains = [
87+
'test-domain.example.com',
88+
'django.paas-sandbox',
89+
]
90+
for domain in test_domains:
91+
body = {'domain': domain}
92+
response = self.client.post(url, json.dumps(body), content_type='application/json',
93+
HTTP_AUTHORIZATION='token {}'.format(self.token))
94+
self.assertEqual(response.status_code, 201)
95+
url = '/v1/apps/{app_id}/domains/{domain}'.format(domain=test_domains[0],
96+
app_id=self.app_id)
97+
response = self.client.delete(url, content_type='application/json',
98+
HTTP_AUTHORIZATION='token {}'.format(self.token))
99+
self.assertEqual(response.status_code, 204)
100+
with self.assertRaises(Domain.DoesNotExist):
101+
Domain.objects.get(domain=test_domains[0])
102+
81103
def test_manage_domain_invalid_app(self):
82104
url = '/v1/apps/{app_id}/domains'.format(app_id="this-app-does-not-exist")
83105
body = {'domain': 'test-domain.example.com'}

controller/api/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ class DomainViewSet(AppResourceViewSet):
218218
model = models.Domain
219219
serializer_class = serializers.DomainSerializer
220220

221+
def get_object(self, **kwargs):
222+
return self.get_queryset(**kwargs)
223+
221224

222225
class KeyViewSet(BaseDeisViewSet):
223226
"""A viewset for interacting with Key objects."""

0 commit comments

Comments
 (0)