Update Django to 1.8 and DRF to 3.3, add new Django migrations, update serializers/pagination/metadata, update browsable API styling.

This commit is contained in:
Chris Church
2016-02-02 14:50:42 -05:00
parent 6242df1a07
commit 60224cdbe4
140 changed files with 2694 additions and 1375 deletions

View File

@@ -31,6 +31,7 @@ class ActivityStreamTest(BaseTest):
self.options(url, expect=200)
self.head(url, expect=200)
response = self.get(url, expect=200)
print response
self.check_pagination_and_size(response, 1, previous=None, next=None)
def test_basic_fields(self):

View File

@@ -18,6 +18,7 @@ from crum import impersonate
# AWX
from awx.main.utils import * # noqa
from awx.main.models import * # noqa
from awx.main.conf import tower_settings
from awx.main.tests.base import BaseJobExecutionTest
from awx.main.tests.data.ssh import (
TEST_SSH_KEY_DATA,
@@ -746,11 +747,15 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
# Try to relaunch ad hoc command when module has been removed from
# allowed list of modules.
with self.settings(AD_HOC_COMMANDS=[]):
try:
ad_hoc_commands = tower_settings.AD_HOC_COMMANDS
tower_settings.AD_HOC_COMMANDS = []
with self.current_user('admin'):
response = self.get(url, expect=200)
self.assertEqual(response['passwords_needed_to_start'], [])
response = self.post(url, {}, expect=400)
finally:
tower_settings.AD_HOC_COMMANDS = ad_hoc_commands
# Try to relaunch after the inventory has been marked inactive.
self.inventory.mark_inactive()

View File

@@ -14,7 +14,6 @@ import urlparse
import unittest2 as unittest
# Django
import django
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management import call_command
@@ -1066,8 +1065,6 @@ class InventoryImportTest(BaseCommandMixin, BaseLiveServerTest):
self.assertNotEqual(new_inv.total_groups, 0)
self.assertElapsedLessThan(30)
@unittest.skipIf(hasattr(django.db.backend, 'sqlite3'),
'Skip this test if we are on sqlite')
def test_splunk_inventory(self):
new_inv = self.organizations[0].inventories.create(name='splunk')
self.assertEqual(new_inv.hosts.count(), 0)

View File

@@ -535,7 +535,7 @@ 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)))
group = Group.objects.get(id=1)
group = Group.objects.order_by('pk')[0]
vdata1_url = reverse('api:group_variable_data', args=(group.pk,))
@@ -1330,6 +1330,18 @@ class InventoryUpdatesTest(BaseTransactionTest):
self.delete(inv_up_url, expect=204)
self.get(inv_up_url, expect=404)
def print_group_tree(self, group, depth=0):
print (' ' * depth) + '+ ' + group.name
for host in group.hosts.order_by('name'):
print (' ' * depth) + ' - ' + host.name
for child in group.children.order_by('name'):
self.print_group_tree(child, depth + 1)
def print_inventory_tree(self, inventory):
# Print out group/host tree for debugging.
for group in inventory.root_groups.order_by('name'):
self.print_group_tree(group)
def test_put_inventory_source_detail_with_regions(self):
creds_url = reverse('api:credential_list')
inv_src_url1 = reverse('api:inventory_source_detail',
@@ -1749,6 +1761,7 @@ class InventoryUpdatesTest(BaseTransactionTest):
# its own child).
self.assertTrue(self.group in self.inventory.root_groups)
# Verify that returned groups are nested:
#self.print_inventory_tree(self.inventory)
child_names = self.group.children.values_list('name', flat=True)
for name in child_names:
self.assertFalse(name.startswith('us-'))
@@ -1766,7 +1779,10 @@ class InventoryUpdatesTest(BaseTransactionTest):
self.assertTrue('tags' in child_names)
self.assertTrue('images' in child_names)
self.assertFalse('tag_none' in child_names)
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
# Only check for tag_none as a child of tags if there is a tag_none group;
# the test inventory *may* have tags set for all hosts.
if self.inventory.groups.filter(name='tag_none').exists():
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
self.assertFalse('instances' in child_names)
# Make sure we clean up the cache path when finished (when one is not
# provided explicitly via source_vars).
@@ -1816,7 +1832,10 @@ class InventoryUpdatesTest(BaseTransactionTest):
self.assertTrue(self.group.children.get(name='security_groups').children.filter(active=True).count())
self.assertTrue('tags' in child_names)
self.assertTrue(self.group.children.get(name='tags').children.filter(active=True).count())
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
# Only check for tag_none as a child of tags if there is a tag_none group;
# the test inventory *may* have tags set for all hosts.
if self.inventory.groups.filter(name='tag_none').exists():
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
self.assertTrue('images' in child_names)
self.assertTrue(self.group.children.get(name='images').children.filter(active=True).count())
self.assertTrue('instances' in child_names)
@@ -1840,21 +1859,9 @@ class InventoryUpdatesTest(BaseTransactionTest):
# Replacement text should not be left in inventory source name.
self.assertFalse(InventorySource.objects.filter(name__icontains='__replace_').exists())
# Inventory update name should be based on inventory/group names and need not have the inventory source pk.
print InventoryUpdate.objects.values_list('name', 'inventory_source__name')
#print InventoryUpdate.objects.values_list('name', 'inventory_source__name')
for inventory_update in InventoryUpdate.objects.all():
self.assertFalse(inventory_update.name.endswith(inventory_update.inventory_source.name), inventory_update.name)
return
# Print out group/host tree for debugging.
print
def draw_tree(g, d=0):
print (' ' * d) + '+ ' + g.name
for h in g.hosts.order_by('name'):
print (' ' * d) + ' - ' + h.name
for c in g.children.order_by('name'):
draw_tree(c, d + 1)
for g in self.inventory.root_groups.order_by('name'):
draw_tree(g)
def test_update_from_rax(self):
source_username = getattr(settings, 'TEST_RACKSPACE_USERNAME', '')

View File

@@ -15,7 +15,7 @@ import django.test
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from django.utils.encoding import smart_str
from django.utils.encoding import smart_text
# Requests
import requests
@@ -216,26 +216,26 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
# due to being an org admin for that project and no credential assigned to that template
with self.current_user(self.user_bob):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 3)
# Chuck has permission to see all Eng Job Templates as Lead Engineer
# Note: Since chuck is an org admin he can also see the support scan template
with self.current_user(self.user_chuck):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 3)
# Doug is in engineering but can only run scan jobs so he can only see the one Job Template
with self.current_user(self.user_doug):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 1)
# Juan can't see any job templates in Engineering because he lacks the inventory read permission
with self.current_user(self.user_juan):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 0)
# We give Juan inventory permission and he can see both Job Templates because he already has deploy permission
@@ -248,19 +248,19 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
)
with self.current_user(self.user_juan):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 2)
# Randall is on the ops testers team that has permission to run a single check playbook on ops west
with self.current_user(self.user_randall):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 1)
# Holly is on the ops east team and can see all of that team's job templates
with self.current_user(self.user_holly):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 3)
# Chuck is temporarily assigned to ops east team to help them running some playbooks
@@ -268,7 +268,7 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
self.team_ops_east.users.add(self.user_chuck)
with self.current_user(self.user_chuck):
resp = self.get(url, expect=200)
print [x['name'] for x in resp['results']]
#print [x['name'] for x in resp['results']]
self.assertEquals(resp['count'], 6)
@@ -313,7 +313,7 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
self.assertEqual(jt.inventory.pk, data['inventory'])
self.assertEqual(jt.credential, None)
self.assertEqual(jt.project.pk, data['project'])
self.assertEqual(smart_str(jt.playbook), data['playbook'])
self.assertEqual(smart_text(jt.playbook), data['playbook'])
# Test that all required fields are really required.
data['name'] = 'another new job template'
@@ -903,8 +903,10 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase):
# Set a limit on the job template to verify the callback job limit is
# set to the intersection of this limit and the host name.
job_template.limit = 'bakers:slicers:packagers'
job_template.save(update_fields=['limit'])
# job_template.limit = 'bakers:slicers:packagers'
# job_template.save(update_fields=['limit'])
JobTemplate.objects.filter(pk=job_template.pk).update(limit='bakers:slicers:packagers')
job_template = JobTemplate.objects.get(pk=job_template.pk)
# Try when hostname is also an IP address, even if a different one is
# specified via ansible_ssh_host.

View File

@@ -287,10 +287,7 @@ class ProjectsTest(BaseTransactionTest):
# can list playbooks for projects
proj_playbooks = reverse('api:project_playbooks', args=(self.projects[2].pk,))
got = self.get(proj_playbooks, expect=200, auth=self.get_super_credentials())
got_new = []
for g in got:
got_new.append(g.encode('utf-8'))
self.assertEqual(got_new, self.projects[2].playbooks)
self.assertEqual(got, self.projects[2].playbooks)
# can list member organizations for projects
proj_orgs = reverse('api:project_organizations_list', args=(self.projects[0].pk,))

View File

@@ -288,8 +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.get(id=12)
self.assertTrue(host.active)
host = Host.objects.filter(active=True).exclude(inventory=inventory)[0]
os.environ['INVENTORY_ID'] = str(inventory.pk)
rc, stdout, stderr = self.run_inventory_script(host=host.name)
self.assertNotEqual(rc, 0, stderr)

View File

@@ -83,6 +83,9 @@ class SettingsTest(BaseTest):
self.set_setting('TEST_SETTING_INT', 2)
setting_int = self.get_individual_setting('TEST_SETTING_INT')
self.assertEqual(setting_int['value'], 2)
self.set_setting('TEST_SETTING_INT', 3)
setting_int = self.get_individual_setting('TEST_SETTING_INT')
self.assertEqual(setting_int['value'], 3)
self.post(settings_reset, data={"key": 'TEST_SETTING_INT'}, expect=204)
setting_int = self.get_individual_setting('TEST_SETTING_INT')
self.assertEqual(setting_int['value'], TEST_TOWER_SETTINGS_MANIFEST['TEST_SETTING_INT']['default'])

View File

@@ -947,8 +947,8 @@ class LdapTest(BaseTest):
return user
def test_ldap_auth(self):
self.use_test_setting('USER_SEARCH')
self.use_test_setting('ALWAYS_UPDATE_USER')
for name in ('USER_SEARCH', 'ALWAYS_UPDATE_USER', 'GROUP_TYPE', 'GROUP_SEARCH'):
self.use_test_setting(name)
self.assertEqual(User.objects.filter(username=self.ldap_username).count(), 0)
# Test logging in, user should be created with no flags or fields set.
user = self.check_login()