Merge pull request #3900 from AlanCoding/fewer_type_methods

Remove duplicated type methods and old Django logic

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-05-23 12:50:35 +00:00
committed by GitHub
6 changed files with 53 additions and 71 deletions

View File

@@ -3,14 +3,10 @@ import pytest
import copy
import json
from django.db import DatabaseError
from awx.main.utils.common import (
model_instance_diff,
model_to_dict,
get_model_for_type
model_to_dict
)
from awx.main import models
@pytest.mark.django_db
@@ -62,20 +58,3 @@ def test_model_instance_diff(alice, bob):
assert hasattr(alice, 'is_superuser')
assert hasattr(bob, 'is_superuser')
assert 'is_superuser' not in output_dict
@pytest.mark.django_db
def test_get_model_for_invalid_type():
with pytest.raises(DatabaseError) as exc:
get_model_for_type('foobar')
assert 'not a valid AWX model' in str(exc)
@pytest.mark.django_db
@pytest.mark.parametrize("model_type,model_class", [
('inventory', models.Inventory),
('job_template', models.JobTemplate),
('unified_job_template', models.UnifiedJobTemplate)
])
def test_get_model_for_valid_type(model_type, model_class):
assert get_model_for_type(model_type) == model_class

View File

@@ -22,7 +22,11 @@ from awx.main.models import (
InventoryUpdate,
ProjectUpdate,
SystemJob,
WorkflowJob
WorkflowJob,
Inventory,
JobTemplate,
UnifiedJobTemplate,
UnifiedJob
)
@@ -92,19 +96,40 @@ def test_set_environ():
assert key not in os.environ
# Cases relied on for scheduler dependent jobs list
@pytest.mark.parametrize('model,name', [
TEST_MODELS = [
(Job, 'job'),
(AdHocCommand, 'ad_hoc_command'),
(InventoryUpdate, 'inventory_update'),
(ProjectUpdate, 'project_update'),
(SystemJob, 'system_job'),
(WorkflowJob, 'workflow_job')
])
(WorkflowJob, 'workflow_job'),
(UnifiedJob, 'unified_job'),
(Inventory, 'inventory'),
(JobTemplate, 'job_template'),
(UnifiedJobTemplate, 'unified_job_template')
]
# Cases relied on for scheduler dependent jobs list
@pytest.mark.parametrize('model,name', TEST_MODELS)
def test_get_type_for_model(model, name):
assert common.get_type_for_model(model) == name
@pytest.mark.django_db
def test_get_model_for_invalid_type():
with pytest.raises(LookupError):
common.get_model_for_type('foobar')
@pytest.mark.django_db
@pytest.mark.parametrize("model_type,model_class", [
(name, cls) for cls, name in TEST_MODELS
])
def test_get_model_for_valid_type(model_type, model_class):
assert common.get_model_for_type(model_type) == model_class
@pytest.fixture
def memoized_function(mocker, mock_cache):
with mock.patch('awx.main.utils.common.get_memoize_cache', return_value=mock_cache):