mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Add unit test, update lookup method to favor ID over name
This commit is contained in:
@@ -4,6 +4,7 @@ __metaclass__ = type
|
||||
import json
|
||||
import sys
|
||||
|
||||
from awx.main.models import Organization, Team
|
||||
from requests.models import Response
|
||||
from unittest import mock
|
||||
|
||||
@@ -102,3 +103,25 @@ def test_no_templated_values(collection_import):
|
||||
'The inventory plugin FQCN is templated when the collection is built '
|
||||
'and the code should retain the default of awx.awx.'
|
||||
)
|
||||
|
||||
|
||||
def test_conflicting_name_and_id(run_module, admin_user):
|
||||
"""In the event that 2 related items match our search criteria in this way:
|
||||
one item has an id that matches input
|
||||
one item has a name that matches input
|
||||
We should preference the id over the name.
|
||||
Otherwise, the universality of the tower_api lookup plugin is compromised.
|
||||
"""
|
||||
org_by_id = Organization.objects.create(name='foo')
|
||||
slug = str(org_by_id.id)
|
||||
org_by_name = Organization.objects.create(name=slug)
|
||||
result = run_module('tower_team', {
|
||||
'name': 'foo_team', 'description': 'fooin around',
|
||||
'organization': slug
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result.get('msg', result)
|
||||
team = Team.objects.filter(name='foo_team').first()
|
||||
assert str(team.organization_id) == slug, (
|
||||
'Lookup by id should be preferenced over name in cases of conflict.'
|
||||
)
|
||||
assert team.organization.name == 'foo'
|
||||
|
||||
Reference in New Issue
Block a user