Skip to content

Commit a36a8f6

Browse files
authored
Merge pull request #931 from helgi/ordering
fix(models): add more sensible ordering to various API responses
2 parents 1e90c0c + d7c4632 commit a36a8f6

7 files changed

Lines changed: 25 additions & 2 deletions

File tree

rootfs/api/models/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class App(UuidAuditedModel):
8787

8888
class Meta:
8989
permissions = (('use_app', 'Can use app'),)
90+
ordering = ['id']
9091

9192
def save(self, *args, **kwargs):
9293
if not self.id:

rootfs/api/models/certificate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class Certificate(AuditedModel):
9191
issuer = models.TextField(editable=False)
9292
subject = models.TextField(editable=False)
9393

94+
class Meta:
95+
ordering = ['name', 'common_name', 'expires']
96+
9497
@property
9598
def domains(self):
9699
domains = []

rootfs/api/models/domain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Domain(AuditedModel):
2020
null=True
2121
)
2222

23+
class Meta:
24+
ordering = ['domain', 'certificate']
25+
2326
def save(self, *args, **kwargs):
2427
app = str(self.app)
2528
domain = str(self.domain)

rootfs/api/models/key.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Key(UuidAuditedModel):
3232
class Meta:
3333
verbose_name = 'SSH Key'
3434
unique_together = (('owner', 'fingerprint'))
35+
ordering = ['public']
3536

3637
def __str__(self):
3738
return "{}...{}".format(self.public[:18], self.public[-31:])

rootfs/api/tests/deployments/test_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_strip_dot(self):
7575
url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id)
7676
response = self.client.get(url)
7777
expected = [data['domain'] for data in response.data['results']]
78-
self.assertEqual([self.app_id, domain], expected, msg)
78+
self.assertEqual(sorted([self.app_id, domain]), expected, msg)
7979

8080
def test_manage_idn_domain(self):
8181
url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id)

rootfs/api/tests/test_app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,21 @@ def _raise_exception(request, ctx):
523523
self.assertEqual(mr.called, True)
524524
self.assertEqual(mr.call_count, 10)
525525

526+
def test_list_ordering(self, mock_requests):
527+
"""
528+
Test that a list of apps is sorted by name
529+
"""
530+
for name in ['zulu', 'tango', 'alpha', 'foxtrot']:
531+
response = self.client.post('/v2/apps', {'id': name})
532+
self.assertEqual(response.status_code, 201, response.data)
533+
534+
response = self.client.get('/v2/apps')
535+
apps = response.data['results']
536+
self.assertEqual(apps[0]['id'], 'alpha')
537+
self.assertEqual(apps[1]['id'], 'foxtrot')
538+
self.assertEqual(apps[2]['id'], 'tango')
539+
self.assertEqual(apps[3]['id'], 'zulu')
540+
526541
FAKE_LOG_DATA = """
527542
2013-08-15 12:41:25 [33454] [INFO] Starting gunicorn 17.5
528543
2013-08-15 12:41:25 [33454] [INFO] Listening at: http://0.0.0.0:5000 (33454)

rootfs/api/tests/test_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_strip_dot(self):
7373
url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id)
7474
response = self.client.get(url)
7575
expected = [data['domain'] for data in response.data['results']]
76-
self.assertEqual([self.app_id, domain], expected, msg)
76+
self.assertEqual(sorted([self.app_id, domain]), expected, msg)
7777

7878
def test_manage_idn_domain(self):
7979
url = '/v2/apps/{app_id}/domains'.format(app_id=self.app_id)

0 commit comments

Comments
 (0)