mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 19:37:38 -02:30
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:
@@ -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
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user