From 5c1a33382c92b33a8d8a9035d6ffc0b6118339c0 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Wed, 24 Mar 2021 13:50:15 -0700 Subject: [PATCH] update mocks to reflect new migration * instead of mocking `created_or_epoch` (which no longer exists) * .. mock `Unified_Job.has_unpartitioned_events` --- awx/main/tests/conftest.py | 13 ++++++++++++- awx/main/tests/functional/api/test_events.py | 11 ----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/awx/main/tests/conftest.py b/awx/main/tests/conftest.py index 15474505c2..da361c9346 100644 --- a/awx/main/tests/conftest.py +++ b/awx/main/tests/conftest.py @@ -3,7 +3,7 @@ import pytest from unittest import mock from contextlib import contextmanager -from awx.main.models import Credential +from awx.main.models import Credential, UnifiedJob from awx.main.tests.factories import ( create_organization, create_job_template, @@ -149,3 +149,14 @@ def mock_external_credential_input_sources(): # test it explicitly. with mock.patch.object(Credential, 'dynamic_input_fields', new=[]) as _fixture: yield _fixture + + +@pytest.fixture(scope='session', autouse=True) +def mock_has_unpartitioned_events(): + # has_unpartitioned_events determines if there are any events still + # left in the old, unpartitioned job events table. In order to work, + # this method looks up when the partition migration occurred. When + # Django's unit tests run, however, there will be no record of the migration. + # We mock this out to circumvent the migration query. + with mock.patch.object(UnifiedJob, 'has_unpartitioned_events', new=False) as _fixture: + yield _fixture diff --git a/awx/main/tests/functional/api/test_events.py b/awx/main/tests/functional/api/test_events.py index 4579d6eab3..dea7cafad2 100644 --- a/awx/main/tests/functional/api/test_events.py +++ b/awx/main/tests/functional/api/test_events.py @@ -1,16 +1,10 @@ import pytest -from unittest import mock from awx.api.versioning import reverse from awx.main.models import AdHocCommand, AdHocCommandEvent, JobEvent from awx.main.models import Job -# Job.created_or_epoch is used to help retrieve events that were -# created before job event tables were partitioned. -# This test can safely behave as if all job events were created -# after the migration, in which case Job.created_or_epoch == Job.created -@mock.patch('awx.main.models.Job.created_or_epoch', Job.created) @pytest.mark.django_db @pytest.mark.parametrize( 'truncate, expected', @@ -33,11 +27,6 @@ def test_job_events_sublist_truncation(get, organization_factory, job_template_f assert (len(response.data['results'][0]['stdout']) == 1025) == expected -# Job.created_or_epoch is used to help retrieve events that were -# created before job event tables were partitioned. -# This test can safely behave as if all job events were created -# after the migration, in which case Job.created_or_epoch == Job.created -@mock.patch('awx.main.models.ad_hoc_commands.AdHocCommand.created_or_epoch', Job.created) @pytest.mark.django_db @pytest.mark.parametrize( 'truncate, expected',