From 4d2fcfd8c1b9678e1b9d6a9e317e28d0083474e8 Mon Sep 17 00:00:00 2001 From: Rebeccah Date: Fri, 12 Feb 2021 15:55:32 -0500 Subject: [PATCH] add a functional test for creating an EE, remove bum copy function because it's not needed, copy works from the base class moved AWXKit pull additions to separate PR and made some changes that were causing linting errors in tests and add copy to show_capabilities for the ee serializer --- awx/api/serializers.py | 2 +- awx/main/models/execution_environments.py | 17 ----------------- awx/main/tests/functional/conftest.py | 6 ++++++ .../functional/test_execution_environments.py | 19 +++++++++++++++++++ awx/main/tests/functional/test_rbac_team.py | 8 +------- awx/main/tests/functional/test_rbac_user.py | 2 +- 6 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 awx/main/tests/functional/test_execution_environments.py diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 523171e43d..dce312a5a8 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1361,7 +1361,7 @@ class ProjectOptionsSerializer(BaseSerializer): class ExecutionEnvironmentSerializer(BaseSerializer): - show_capabilities = ['edit', 'delete'] + show_capabilities = ['edit', 'delete', 'copy'] managed_by_tower = serializers.ReadOnlyField() class Meta: diff --git a/awx/main/models/execution_environments.py b/awx/main/models/execution_environments.py index b0fd2bb857..eabd0cce7c 100644 --- a/awx/main/models/execution_environments.py +++ b/awx/main/models/execution_environments.py @@ -3,7 +3,6 @@ from django.utils.translation import ugettext_lazy as _ from awx.api.versioning import reverse from awx.main.models.base import CommonModel -from awx.main.utils import copy_model_by_class, copy_m2m_relationships __all__ = ['ExecutionEnvironment'] @@ -50,21 +49,5 @@ class ExecutionEnvironment(CommonModel): help_text=_('Pull image before running?'), ) - def copy_execution_environment(self): - ''' - Returns saved object, including related fields. - Create a copy of this unified job template. - ''' - execution_environment_class = self.__class__ - fields = (f.name for f in self.Meta.fields) - execution_environment_copy = copy_model_by_class(self, execution_environment_class, fields, {}) - - time_now = now() - execution_environment_copy.name = execution_environment_copy.name.split('@', 1)[0] + ' @ ' + time_now.strftime('%I:%M:%S %p') - - execution_environment_copy.save() - copy_m2m_relationships(self, execution_environment_copy, fields) - return execution_environment_copy - def get_absolute_url(self, request=None): return reverse('api:execution_environment_detail', kwargs={'pk': self.pk}, request=request) diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index 7111950003..4cbd5a40d3 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -52,6 +52,7 @@ from awx.main.models.events import ( from awx.main.models.workflow import WorkflowJobTemplate from awx.main.models.ad_hoc_commands import AdHocCommand from awx.main.models.oauth import OAuth2Application as Application +from awx.main.models.execution_environments import ExecutionEnvironment __SWAGGER_REQUESTS__ = {} @@ -850,3 +851,8 @@ def slice_job_factory(slice_jt_factory): node.save() return slice_job return r + + +@pytest.fixture +def execution_environment(organization): + return ExecutionEnvironment.objects.create(name="test-ee", description="test-ee", organization=organization) diff --git a/awx/main/tests/functional/test_execution_environments.py b/awx/main/tests/functional/test_execution_environments.py new file mode 100644 index 0000000000..5f1e430fe8 --- /dev/null +++ b/awx/main/tests/functional/test_execution_environments.py @@ -0,0 +1,19 @@ +import pytest + +from awx.main.models import (ExecutionEnvironment) + + +@pytest.mark.django_db +def test_execution_environment_creation(execution_environment, organization): + execution_env = ExecutionEnvironment.objects.create( + name='Hello Environment', + image='', + organization=organization, + managed_by_tower=False, + credential=None, + pull='missing' + ) + assert type(execution_env) is type(execution_environment) + assert execution_env.organization == organization + assert execution_env.name == 'Hello Environment' + assert execution_env.pull == 'missing' diff --git a/awx/main/tests/functional/test_rbac_team.py b/awx/main/tests/functional/test_rbac_team.py index ed76e7e4a8..a18a69a94b 100644 --- a/awx/main/tests/functional/test_rbac_team.py +++ b/awx/main/tests/functional/test_rbac_team.py @@ -2,7 +2,7 @@ import pytest from unittest import mock from awx.main.access import TeamAccess -from awx.main.models import Project, Organization, Team, ExecutionEnvironment +from awx.main.models import Project, Organization, Team @pytest.mark.django_db @@ -143,12 +143,6 @@ def test_team_member_org_role_access_inventory(team, rando, inventory, organizat team.member_role.children.add(organization.inventory_admin_role) assert rando in inventory.admin_role -# @pytest.mark.django_db -# def test_team_member_org_role_access_execution_environment(team, rando, execution_environment, organization): -# team.member_role.members.add(rando) -# assert rando not in execution_environment.read_role -# team.member_role.children.add(organization.execution_environment_admin_role) -# assert rando in execution_environment.admin_role @pytest.mark.django_db def test_org_admin_team_access(organization, team, user, project): diff --git a/awx/main/tests/functional/test_rbac_user.py b/awx/main/tests/functional/test_rbac_user.py index 376272bdfe..b62a0db25f 100644 --- a/awx/main/tests/functional/test_rbac_user.py +++ b/awx/main/tests/functional/test_rbac_user.py @@ -4,7 +4,7 @@ from unittest import mock from django.test import TransactionTestCase from awx.main.access import UserAccess, RoleAccess, TeamAccess -from awx.main.models import User, Organization, Inventory, Role, ExecutionEnvironment +from awx.main.models import User, Organization, Inventory, Role class TestSysAuditorTransactional(TransactionTestCase):