mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-21 23:41:49 -05:00
Removed dup tests, moved old api tests into main/tests/old/api
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .decorator_paginated import PaginatedDecoratorTests # noqa
|
||||
from .job_tasks import JobTasksTests # noqa
|
||||
@@ -1,75 +0,0 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
import json
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.test import APIRequestFactory
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from awx.api.utils.decorators import paginated
|
||||
|
||||
|
||||
class PaginatedDecoratorTests(TestCase):
|
||||
"""A set of tests for ensuring that the "paginated" decorator works
|
||||
in the way we expect.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.rf = APIRequestFactory()
|
||||
|
||||
# Define an uninteresting view that we can use to test
|
||||
# that the paginator wraps in the way we expect.
|
||||
class View(APIView):
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
@paginated
|
||||
def get(self, request, limit, ordering, offset):
|
||||
return ['a', 'b', 'c', 'd', 'e'], 26, None
|
||||
self.view = View.as_view()
|
||||
|
||||
def test_implicit_first_page(self):
|
||||
"""Establish that if we get an implicit request for the first page
|
||||
(e.g. no page provided), that it is returned appropriately.
|
||||
"""
|
||||
# Create a request, and run the paginated function.
|
||||
request = self.rf.get('/dummy/', {'page_size': 5})
|
||||
response = self.view(request)
|
||||
|
||||
# Ensure the response looks like what it should.
|
||||
r = json.loads(response.rendered_content)
|
||||
self.assertEqual(r['count'], 26)
|
||||
self.assertEqual(r['next'], '/dummy/?page=2&page_size=5')
|
||||
self.assertEqual(r['previous'], None)
|
||||
self.assertEqual(r['results'], ['a', 'b', 'c', 'd', 'e'])
|
||||
|
||||
def test_mid_page(self):
|
||||
"""Establish that if we get a request for a page in the middle, that
|
||||
the paginator causes next and prev to be set appropriately.
|
||||
"""
|
||||
# Create a request, and run the paginated function.
|
||||
request = self.rf.get('/dummy/', {'page': 3, 'page_size': 5})
|
||||
response = self.view(request)
|
||||
|
||||
# Ensure the response looks like what it should.
|
||||
r = json.loads(response.rendered_content)
|
||||
self.assertEqual(r['count'], 26)
|
||||
self.assertEqual(r['next'], '/dummy/?page=4&page_size=5')
|
||||
self.assertEqual(r['previous'], '/dummy/?page=2&page_size=5')
|
||||
self.assertEqual(r['results'], ['a', 'b', 'c', 'd', 'e'])
|
||||
|
||||
def test_last_page(self):
|
||||
"""Establish that if we get a request for the last page, that the
|
||||
paginator picks up on it and sets `next` to None.
|
||||
"""
|
||||
# Create a request, and run the paginated function.
|
||||
request = self.rf.get('/dummy/', {'page': 6, 'page_size': 5})
|
||||
response = self.view(request)
|
||||
|
||||
# Ensure the response looks like what it should.
|
||||
r = json.loads(response.rendered_content)
|
||||
self.assertEqual(r['count'], 26)
|
||||
self.assertEqual(r['next'], None)
|
||||
self.assertEqual(r['previous'], '/dummy/?page=5&page_size=5')
|
||||
self.assertEqual(r['results'], ['a', 'b', 'c', 'd', 'e'])
|
||||
@@ -1,44 +0,0 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import LiveServerTestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from awx.main.tests.job_base import BaseJobTestMixin
|
||||
|
||||
|
||||
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||
ANSIBLE_TRANSPORT='local')
|
||||
class JobTasksTests(BaseJobTestMixin, LiveServerTestCase):
|
||||
"""A set of tests to ensure that the job_tasks endpoint, available at
|
||||
`/api/v1/jobs/{id}/job_tasks/`, works as expected.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(JobTasksTests, self).setUp()
|
||||
settings.INTERNAL_API_URL = self.live_server_url
|
||||
|
||||
def test_tasks_endpoint(self):
|
||||
"""Establish that the `job_tasks` endpoint shows what we expect,
|
||||
which is a rollup of information about each of the corresponding
|
||||
job events.
|
||||
"""
|
||||
# Create a job
|
||||
job = self.make_job(self.jt_ops_east_run, self.user_sue, 'new')
|
||||
job.signal_start()
|
||||
|
||||
# Get the initial job event.
|
||||
event = job.job_events.get(event='playbook_on_play_start')
|
||||
|
||||
# Actually make the request for the job tasks.
|
||||
with self.current_user(self.user_sue):
|
||||
url = '/api/v1/jobs/%d/job_tasks/?event_id=%d' % (job.id, event.id)
|
||||
response = self.get(url)
|
||||
|
||||
# Test to make sure we got back what we expected.
|
||||
result = response['results'][0]
|
||||
self.assertEqual(result['host_count'], 7)
|
||||
self.assertEqual(result['changed_count'], 7)
|
||||
self.assertFalse(result['failed'])
|
||||
self.assertTrue(result['changed'])
|
||||
Reference in New Issue
Block a user