mirror of
https://github.com/ansible/awx.git
synced 2026-01-22 06:58:06 -03:30
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
This commit is contained in:
parent
0921de5d2b
commit
4d2fcfd8c1
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
19
awx/main/tests/functional/test_execution_environments.py
Normal file
19
awx/main/tests/functional/test_execution_environments.py
Normal file
@ -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'
|
||||
@ -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):
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user