def test_callback_find_matching_hosts(mocker, get, job_template_prompts,
                                      admin_user):
    job_template = job_template_prompts(False)
    job_template.host_config_key = "foo"
    job_template.save()
    host_with_alias = Host(name='localhost', inventory=job_template.inventory)
    host_with_alias.save()
    with mocker.patch('awx.main.access.BaseAccess.check_license'):
        r = get(reverse('api:job_template_callback',
                        kwargs={'pk': job_template.pk}),
                user=admin_user,
                expect=200)
        assert tuple(r.data['matching_hosts']) == ('localhost', )
def test_callback_extra_var_takes_priority_over_host_name(
        mocker, get, job_template_prompts, admin_user):
    job_template = job_template_prompts(False)
    job_template.host_config_key = "foo"
    job_template.save()
    host_with_alias = Host(name='localhost',
                           variables={'ansible_host': 'foobar'},
                           inventory=job_template.inventory)
    host_with_alias.save()
    with mocker.patch('awx.main.access.BaseAccess.check_license'):
        r = get(reverse('api:job_template_callback',
                        kwargs={'pk': job_template.pk}),
                user=admin_user,
                expect=200)
        assert not r.data['matching_hosts']
 def handler(name, groups):
     h = Host(name=name, inventory=inventory)
     h.save()
     h = Host.objects.get(name=name, inventory=inventory)
     for g in groups:
         h.groups.add(g)
     h.save()
     h = Host.objects.get(name=name, inventory=inventory)
     return h
Пример #4
0
def test_pagination_cap_page_size(get, admin, inventory):
    for i in range(20):
        Host(name='host-{}'.format(i), inventory=inventory).save()

    def host_list_url(params):
        request_qs = '?' + urlencode(params)
        return reverse('api:host_list', kwargs={'version': 'v2'}) + request_qs

    with patch('awx.api.pagination.Pagination.max_page_size', 5):
        resp = get(host_list_url({'page': '2', 'page_size': '10'}), user=admin)
        jdata = json.loads(resp.content)

        assert jdata['previous'] == host_list_url({
            'page': '1',
            'page_size': '5'
        })
        assert jdata['next'] == host_list_url({'page': '3', 'page_size': '5'})