Files
awx/awx_collection/test/awx/test_project.py
Rick Elrod 0815f935ca [collection] remove module defaults where API defaults are the same (#13037)
Providing defaults for API parameters where the API already provides
defaults leads to some confusing scenarios, because we end up always
sending those collection-defaulted fields in the request even if the
field isn't provided by the user.

For example, we previously set the `scm_type` default to 'manual' and
someone using the collection to update a project who does not explicitly
include the `scm_type` every time they call the module, would
inadvertently change the `scm_type` of the project back to 'manual'
which is surprising behavior.

This change removes the collection defaults for API parameters, unless
they differed from the API default. We let the API handle the defaults
or otherwise ignore fields not given by the user so that the user does
not end up changing unexpected fields when they use a module.

Signed-off-by: Rick Elrod <rick@elrod.me>
2023-02-01 15:37:08 -06:00

51 lines
1.7 KiB
Python

from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from awx.main.models import Project
@pytest.mark.django_db
def test_create_project(run_module, admin_user, organization, silence_warning):
result = run_module(
'project',
dict(name='foo', organization=organization.name, scm_type='git', scm_url='https://foo.invalid', wait=False, scm_update_cache_timeout=5),
admin_user,
)
silence_warning.assert_called_once_with('scm_update_cache_timeout will be ignored since scm_update_on_launch was not set to true')
assert result.pop('changed', None), result
proj = Project.objects.get(name='foo')
assert proj.scm_url == 'https://foo.invalid'
assert proj.organization == organization
result.pop('invocation')
assert result == {'name': 'foo', 'id': proj.id}
@pytest.mark.django_db
def test_create_project_copy_from(run_module, admin_user, organization, silence_warning):
'''Test the copy_from functionality'''
result = run_module(
'project',
dict(name='foo', organization=organization.name, scm_type='git', scm_url='https://foo.invalid', wait=False, scm_update_cache_timeout=5),
admin_user,
)
assert result.pop('changed', None), result
proj_name = 'bar'
result = run_module(
'project',
dict(name=proj_name, copy_from='foo', scm_type='git', wait=False),
admin_user,
)
assert result.pop('changed', None), result
result = run_module(
'project',
dict(name=proj_name, copy_from='foo', scm_type='git', wait=False),
admin_user,
)
silence_warning.assert_called_with("A project with the name {0} already exists.".format(proj_name))