update mocks to reflect new migration

* instead of mocking `created_or_epoch` (which no longer exists)
* .. mock `Unified_Job.has_unpartitioned_events`
This commit is contained in:
Jim Ladd
2021-03-24 13:50:15 -07:00
parent db6f565dca
commit 5c1a33382c
2 changed files with 12 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ import pytest
from unittest import mock from unittest import mock
from contextlib import contextmanager from contextlib import contextmanager
from awx.main.models import Credential from awx.main.models import Credential, UnifiedJob
from awx.main.tests.factories import ( from awx.main.tests.factories import (
create_organization, create_organization,
create_job_template, create_job_template,
@@ -149,3 +149,14 @@ def mock_external_credential_input_sources():
# test it explicitly. # test it explicitly.
with mock.patch.object(Credential, 'dynamic_input_fields', new=[]) as _fixture: with mock.patch.object(Credential, 'dynamic_input_fields', new=[]) as _fixture:
yield _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

View File

@@ -1,16 +1,10 @@
import pytest import pytest
from unittest import mock
from awx.api.versioning import reverse from awx.api.versioning import reverse
from awx.main.models import AdHocCommand, AdHocCommandEvent, JobEvent from awx.main.models import AdHocCommand, AdHocCommandEvent, JobEvent
from awx.main.models import Job 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.django_db
@pytest.mark.parametrize( @pytest.mark.parametrize(
'truncate, expected', '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 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.django_db
@pytest.mark.parametrize( @pytest.mark.parametrize(
'truncate, expected', 'truncate, expected',