def test_all_datastore_parameters(self, mocker): sync_mock = mocker.patch.object(datastore, "sync") sync_mock.return_value = True, {} set_module_args( name="test_datastore", dsn="my-dsn", pool_size=543, ) with pytest.raises(AnsibleExitJson): datastore.main() state, _client, list_path, resource_path, payload, check_mode = ( sync_mock.call_args[0]) assert state == "present" assert resource_path == "/api/enterprise/store/v1/provider/test_datastore" assert list_path == "/api/enterprise/store/v1/provider" assert payload == dict( type="PostgresConfig", api_version="store/v1", spec=dict( metadata=dict(name="test_datastore", ), dsn="my-dsn", pool_size=543, ), ) assert check_mode is False
def test_failure(self, mocker): sync_mock = mocker.patch.object(datastore, "sync") sync_mock.side_effect = errors.Error("Bad error") set_module_args( name="test_datastore", dsn="my-dsn", ) with pytest.raises(AnsibleFailJson): datastore.main()
def test_minimal_datastore_parameters_absent(self, mocker): sync_mock = mocker.patch.object(datastore, "sync") sync_mock.return_value = True, {} set_module_args( name="test_datastore", state="absent", ) with pytest.raises(AnsibleExitJson): datastore.main() state, _client, list_path, resource_path, _payload, check_mode = ( sync_mock.call_args[0]) assert state == "absent" assert resource_path == "/api/enterprise/store/v1/provider/test_datastore" assert list_path == "/api/enterprise/store/v1/provider" assert check_mode is False