1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-05 11:46:57 +00:00

Move modules and module_utils unit tests to correct place (#81)

* Move modules and module_utils unit tests to correct place.

* Update ignore.txt

* Fix imports.

* Fix typos.

* Fix more typos.
This commit is contained in:
Felix Fontein 2020-03-31 10:42:38 +02:00 committed by GitHub
parent ab3c2120fb
commit be191cce6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1170 changed files with 732 additions and 751 deletions

View file

@ -0,0 +1,215 @@
{
"mock_create_res": {
"ansible_facts": {
"avi_api_context": {
"192.0.2.97:admin:None": {
"csrftoken": "qG23CCARDL3rh1KZ66XXPIeUYCUCOZ4q",
"session_id": "h5nynf9u9nompp5byai7vii2v8bbn9kd"
}
}
},
"api_context": null,
"changed": true,
"invocation": {
"module_args": {
"access": [{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant/********#********",
"all_tenants": false
}],
"api_context": null,
"api_version": "18.2.5",
"avi_api_update_method": "put",
"avi_credentials": null,
"avi_disable_session_cache_as_fact": false,
"avi_login_info": null,
"controller": "192.0.2.97",
"default_tenant_ref": "/api/tenant?name=********",
"email": "test@abc.com",
"is_active": true,
"is_superuser": true,
"name": "testuser",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"state": "present",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"obj": {
"_last_modified": "1559736767460818",
"access": [{
"all_tenants": false,
"role_ref": "https://192.0.2.97/api/tenant/********/role/role-ff851004-bd75-485b-87ec-2fe1d6a03fb9#Tenant-Admin",
"tenant_ref": "https://192.0.2.97/api/tenant/********#********"
}],
"default_tenant_ref": "https://192.0.2.97/api/tenant/********#********",
"email": "test@abc.com",
"full_name": "testuser",
"is_active": true,
"is_superuser": true,
"local": true,
"name": "testuser",
"obj_password": "<sensitive>",
"obj_username": "testuser",
"password": "<sensitive>",
"uid": 2004,
"url": "https://192.0.2.97/api/user/user-7087578f-4dfe-4e06-a153-495a91824a1d#testuser",
"user_profile_ref": "https://192.0.2.97/api/useraccountprofile/useraccountprofile-78063e7c-b443-48d6-b34c-5253ae1fcd2a#Default-User-Account-Profile",
"username": "testuser",
"uuid": "user-7087578f-4dfe-4e06-a153-495a91824a1d"
},
"old_obj": null
},
"mock_put_res": {
"obj": {
"username": "testuser",
"user_profile_ref": "https://192.0.2.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"name": "testuser",
"url": "https://192.0.2.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"is_active": true,
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a",
"email": "newemail@abc.com",
"access": [{
"tenant_ref": "https://192.0.2.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin",
"all_tenants": false,
"role_ref": "https://192.0.2.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin"
}],
"is_superuser": true,
"obj_username": "testuser",
"full_name": "testuser",
"_last_modified": "1559802772203285",
"password": "<sensitive>",
"local": true,
"obj_password": "<sensitive>",
"default_tenant_ref": "https://192.0.2.97/api/tenant/********#********",
"uid": 2002
},
"changed": true,
"api_context": null,
"invocation": {
"module_args": {
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"api_version": "18.2.5",
"name": "testuser",
"state": "present",
"is_active": true,
"api_context": null,
"avi_disable_session_cache_as_fact": false,
"controller": "192.0.2.97",
"avi_api_patch_op": null,
"access": [{
"tenant_ref": "/api/tenant?name=Test-Admin",
"all_tenants": false,
"role_ref": "/api/role?name=Tenant-Admin"
}],
"is_superuser": true,
"avi_credentials": null,
"email": "newemail@abc.com",
"default_tenant_ref": "/api/tenant?name=********",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"avi_api_update_method": "put",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"ansible_facts": {
"avi_api_context": {
"192.0.2.97:admin:None": {
"csrftoken": "Y7CET6zaIC9VZAzBqEW4cWo1N26jPg55",
"session_id": "364n7o0p3o5so63b9rzd47v6ehya6xg7"
}
}
},
"old_obj": {
"username": "testuser",
"user_profile_ref": "https://192.0.2.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"name": "testuser",
"url": "https://192.0.2.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"is_active": true,
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a",
"access": [{
"tenant_ref": "https://192.0.2.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin",
"all_tenants": false,
"role_ref": "https://192.0.2.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin"
}],
"is_superuser": true,
"full_name": "testuser",
"ui_property": "",
"password": "<sensitive>",
"local": true,
"email": "test@abc.com",
"default_tenant_ref": "https://192.0.2.97/api/tenant/********#********",
"uid": 2002
}
},
"mock_del_res": {
"ansible_facts": {
"avi_api_context": {
"192.0.2.97:admin:None": {
"csrftoken": "Vtkx9GeS2lsrld5yX83cmJqbZO3MAimb",
"session_id": "ix3t1dja8yzwb155de59viyn96hibn6b"
}
}
},
"api_context": null,
"changed": true,
"invocation": {
"module_args": {
"access": [{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant/********#********"
}],
"api_context": null,
"api_version": "18.2.5",
"avi_api_update_method": "put",
"avi_credentials": null,
"avi_disable_session_cache_as_fact": false,
"avi_login_info": null,
"controller": "192.0.2.97",
"default_tenant_ref": "/api/tenant?name=********",
"email": "test@abc.com",
"is_active": true,
"is_superuser": true,
"name": "testuser",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"state": "absent",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"obj": null,
"old_obj": {
"_last_modified": "1559803346264869",
"access": [{
"all_tenants": false,
"role_ref": "https://192.0.2.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin",
"tenant_ref": "https://192.0.2.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin"
}],
"default_tenant_ref": "https://192.0.2.97/api/tenant/********#********",
"email": "newemail@abc.com",
"full_name": "testuser",
"is_active": true,
"is_superuser": true,
"local": true,
"name": "testuser",
"password": "<sensitive>",
"ui_property": "",
"uid": 2002,
"url": "https://192.0.2.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"user_profile_ref": "https://192.0.2.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"username": "testuser",
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a"
}
}
}

View file

@ -0,0 +1,101 @@
import os
import json
from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import Mock
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.plugins.modules.network.avi import avi_user
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
with open(fixture_path + '/avi_user.json') as json_file:
data = json.load(json_file)
class TestAviUser(unittest.TestCase):
def test_create_user(self):
set_module_args({
"avi_credentials": {
"controller": "192.0.2.13",
"username": "username",
"password": "fakepassword",
"api_version": "18.2.5"
},
"state": "present",
"name": "testuser",
"obj_username": "testuser",
"obj_password": "test123",
"email": "test@abc.com",
"access": [
{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant?name=Test-Admin",
"all_tenants": False
}
],
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"is_active": True,
"is_superuser": True,
"default_tenant_ref": "/api/tenant?name=admin"
})
avi_user.avi_ansible_api = Mock(return_value=data['mock_create_res'])
response = avi_user.main()
assert response['changed']
def test_put_on_user(self):
set_module_args({
"avi_credentials": {
"controller": "192.0.2.13",
"username": "username",
"password": "fakepassword",
"api_version": "18.2.5"
},
"state": "present",
"avi_api_update_method": "put",
"name": "testuser",
"obj_username": "testuser",
"obj_password": "test123",
"email": "newemail@abc.com",
"access": [{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant?name=Test-Admin",
"all_tenants": False
}],
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"is_active": True,
"is_superuser": True,
"default_tenant_ref": "/api/tenant?name=admin"
})
avi_user.avi_ansible_api = Mock(return_value=data['mock_put_res'])
response = avi_user.main()
assert response['changed']
assert response['obj']
assert response['old_obj']
def test_delete_user(self):
set_module_args({
"avi_credentials": {
"controller": "192.0.2.13",
"username": "username",
"password": "fakepassword",
"api_version": "18.2.5"
},
"name": "testuser",
"obj_username": "testuser",
"obj_password": "test123",
"email": "test@abc.com",
"access": [{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant?name=Test-Admin",
"all_tenants": False
}],
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"is_active": True,
"is_superuser": True,
"default_tenant_ref": "/api/tenant?name=admin"
})
avi_user.avi_ansible_api = Mock(return_value=data['mock_del_res'])
response = avi_user.main()
assert response['changed']
assert not response['obj']
assert response['old_obj']