Adding sensible ordering to common models.

https://trello.com/c/tTwRM2VV/102-tower-api-teams-endpoint-does-not-sort-consistently
This commit is contained in:
Luke Sneeringer 2014-07-24 11:48:55 -05:00
parent ef89737845
commit 627c6f029e
7 changed files with 12 additions and 4 deletions

View File

@ -40,6 +40,7 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique):
class Meta:
app_label = 'main'
unique_together = [('user', 'team', 'kind', 'name')]
ordering = ('kind', 'name')
user = models.ForeignKey(
'auth.User',

View File

@ -50,6 +50,7 @@ class Inventory(CommonModel):
app_label = 'main'
verbose_name_plural = _('inventories')
unique_together = [('name', 'organization')]
ordering = ('name',)
organization = models.ForeignKey(
'Organization',
@ -329,6 +330,7 @@ class Host(CommonModelNameNotUnique):
class Meta:
app_label = 'main'
unique_together = (("name", "inventory"),) # FIXME: Add ('instance_id', 'inventory') after migration.
ordering = ('inventory', 'name')
inventory = models.ForeignKey(
'Inventory',
@ -463,6 +465,7 @@ class Group(CommonModelNameNotUnique):
class Meta:
app_label = 'main'
unique_together = (("name", "inventory"),)
ordering = ('name',)
inventory = models.ForeignKey(
'Inventory',

View File

@ -138,6 +138,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
class Meta:
app_label = 'main'
ordering = ('name',)
host_config_key = models.CharField(
max_length=1024,
@ -195,6 +196,7 @@ class Job(UnifiedJob, JobOptions):
class Meta:
app_label = 'main'
ordering = ('id',)
job_template = models.ForeignKey(
'JobTemplate',

View File

@ -29,6 +29,7 @@ class Organization(CommonModel):
class Meta:
app_label = 'main'
ordering = ('name',)
users = models.ManyToManyField(
'auth.User',
@ -61,6 +62,7 @@ class Team(CommonModelNameNotUnique):
class Meta:
app_label = 'main'
unique_together = [('organization', 'name')]
ordering = ('organization__name', 'name')
users = models.ManyToManyField(
'auth.User',

View File

@ -206,6 +206,7 @@ class Project(UnifiedJobTemplate, ProjectOptions):
class Meta:
app_label = 'main'
ordering = ('id',)
scm_delete_on_next_update = models.BooleanField(
default=False,

View File

@ -501,10 +501,9 @@ class InventoryTest(BaseTest):
vars_a = dict(asdf=7777, dog='droopy', cat='battlecat', unstructured=dict(a=[1,1,1],b=dict(x=1,y=2)))
vars_b = dict(asdf=8888, dog='snoopy', cat='cheshire', unstructured=dict(a=[2,2,2],b=dict(x=3,y=4)))
vars_c = dict(asdf=9999, dog='pluto', cat='five', unstructured=dict(a=[3,3,3],b=dict(z=5)))
groups = Group.objects.all()
group = Group.objects.get(id=1)
vdata1_url = reverse('api:group_variable_data', args=(groups[0].pk,))
vdata2_url = reverse('api:group_variable_data', args=(groups[1].pk,))
vdata1_url = reverse('api:group_variable_data', args=(group.pk,))
# a super user can associate variable objects with groups
got = self.get(vdata1_url, expect=200, auth=self.get_super_credentials())

View File

@ -288,7 +288,7 @@ class InventoryScriptTest(BaseScriptTest):
# Valid host, but not part of the specified inventory.
inventory = self.inventories[0]
self.assertTrue(inventory.active)
host = Host.objects.exclude(inventory=inventory)[0]
host = Host.objects.get(id=12)
self.assertTrue(host.active)
os.environ['INVENTORY_ID'] = str(inventory.pk)
rc, stdout, stderr = self.run_inventory_script(host=host.name)