|
6 | 6 | from django.contrib.auth.models import User |
7 | 7 | from django.test.utils import override_settings |
8 | 8 | from rest_framework.authtoken.models import Token |
9 | | -from api.tests import DeisTestCase |
| 9 | +from api.tests import TEST_ROOT, DeisTestCase |
| 10 | +from api.models import Certificate |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class AuthTest(DeisTestCase): |
@@ -242,6 +243,18 @@ def test_cancel(self): |
242 | 243 | HTTP_AUTHORIZATION='token {}'.format(self.admin_token)) |
243 | 244 | self.assertEqual(response.status_code, 409) |
244 | 245 |
|
| 246 | + # user can not be deleted if it has a downstream object owned by them, like a certificate |
| 247 | + domain_name = 'foo.com' |
| 248 | + with open('{}/certs/{}.key'.format(TEST_ROOT, domain_name)) as f: |
| 249 | + key = f.read() |
| 250 | + with open('{}/certs/{}.cert'.format(TEST_ROOT, domain_name)) as f: |
| 251 | + cert = f.read() |
| 252 | + |
| 253 | + Certificate.objects.create(owner=self.admin, certificate=cert, key=key) |
| 254 | + response = self.client.delete(url, {'username': str(self.admin)}, |
| 255 | + HTTP_AUTHORIZATION='token {}'.format(self.admin_token)) |
| 256 | + self.assertEqual(response.status_code, 409, response.data) |
| 257 | + |
245 | 258 | def test_passwd(self): |
246 | 259 | """Test that a registered user can change the password.""" |
247 | 260 | # test registration workflow |
|
0 commit comments