mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 21:47:13 +00:00
Add tests for http basic authentication in python client (#16488)
* add tests for http basic auth in python client * add new files
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Echo Server API
|
||||
*
|
||||
* Echo Server API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0
|
||||
* Contact: team@openapitools.org
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using RestSharp;
|
||||
using Xunit;
|
||||
|
||||
using Org.OpenAPITools.Client;
|
||||
using Org.OpenAPITools.Api;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing AuthApi
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the API endpoint.
|
||||
/// </remarks>
|
||||
public class AuthApiTests : IDisposable
|
||||
{
|
||||
private AuthApi instance;
|
||||
|
||||
public AuthApiTests()
|
||||
{
|
||||
instance = new AuthApi();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of AuthApi
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void InstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test 'IsType' AuthApi
|
||||
//Assert.IsType<AuthApi>(instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test TestAuthHttpBasic
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestAuthHttpBasicTest()
|
||||
{
|
||||
// TODO uncomment below to test the method and replace null with proper value
|
||||
//var response = instance.TestAuthHttpBasic();
|
||||
//Assert.IsType<string>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Echo Server API
|
||||
*
|
||||
* Echo Server API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0
|
||||
* Contact: team@openapitools.org
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using Org.OpenAPITools.Client;
|
||||
|
||||
namespace Org.OpenAPITools.Api
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public interface IAuthApiSync : IApiAccessor
|
||||
{
|
||||
#region Synchronous Operations
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test HTTP basic authentication
|
||||
/// </remarks>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <returns>string</returns>
|
||||
string TestAuthHttpBasic(int operationIndex = 0);
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test HTTP basic authentication
|
||||
/// </remarks>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <returns>ApiResponse of string</returns>
|
||||
ApiResponse<string> TestAuthHttpBasicWithHttpInfo(int operationIndex = 0);
|
||||
#endregion Synchronous Operations
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public interface IAuthApiAsync : IApiAccessor
|
||||
{
|
||||
#region Asynchronous Operations
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test HTTP basic authentication
|
||||
/// </remarks>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||
/// <returns>Task of string</returns>
|
||||
System.Threading.Tasks.Task<string> TestAuthHttpBasicAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test HTTP basic authentication
|
||||
/// </remarks>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||
/// <returns>Task of ApiResponse (string)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<string>> TestAuthHttpBasicWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||
#endregion Asynchronous Operations
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public interface IAuthApi : IAuthApiSync, IAuthApiAsync
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public partial class AuthApi : IAuthApi
|
||||
{
|
||||
private Org.OpenAPITools.Client.ExceptionFactory _exceptionFactory = (name, response) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthApi"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public AuthApi() : this((string)null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthApi"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public AuthApi(string basePath)
|
||||
{
|
||||
this.Configuration = Org.OpenAPITools.Client.Configuration.MergeConfigurations(
|
||||
Org.OpenAPITools.Client.GlobalConfiguration.Instance,
|
||||
new Org.OpenAPITools.Client.Configuration { BasePath = basePath }
|
||||
);
|
||||
this.Client = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
|
||||
this.AsynchronousClient = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
|
||||
this.ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthApi"/> class
|
||||
/// using Configuration object
|
||||
/// </summary>
|
||||
/// <param name="configuration">An instance of Configuration</param>
|
||||
/// <returns></returns>
|
||||
public AuthApi(Org.OpenAPITools.Client.Configuration configuration)
|
||||
{
|
||||
if (configuration == null) throw new ArgumentNullException("configuration");
|
||||
|
||||
this.Configuration = Org.OpenAPITools.Client.Configuration.MergeConfigurations(
|
||||
Org.OpenAPITools.Client.GlobalConfiguration.Instance,
|
||||
configuration
|
||||
);
|
||||
this.Client = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
|
||||
this.AsynchronousClient = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
|
||||
ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthApi"/> class
|
||||
/// using a Configuration object and client instance.
|
||||
/// </summary>
|
||||
/// <param name="client">The client interface for synchronous API access.</param>
|
||||
/// <param name="asyncClient">The client interface for asynchronous API access.</param>
|
||||
/// <param name="configuration">The configuration object.</param>
|
||||
public AuthApi(Org.OpenAPITools.Client.ISynchronousClient client, Org.OpenAPITools.Client.IAsynchronousClient asyncClient, Org.OpenAPITools.Client.IReadableConfiguration configuration)
|
||||
{
|
||||
if (client == null) throw new ArgumentNullException("client");
|
||||
if (asyncClient == null) throw new ArgumentNullException("asyncClient");
|
||||
if (configuration == null) throw new ArgumentNullException("configuration");
|
||||
|
||||
this.Client = client;
|
||||
this.AsynchronousClient = asyncClient;
|
||||
this.Configuration = configuration;
|
||||
this.ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client for accessing this underlying API asynchronously.
|
||||
/// </summary>
|
||||
public Org.OpenAPITools.Client.IAsynchronousClient AsynchronousClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The client for accessing this underlying API synchronously.
|
||||
/// </summary>
|
||||
public Org.OpenAPITools.Client.ISynchronousClient Client { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public string GetBasePath()
|
||||
{
|
||||
return this.Configuration.BasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration object
|
||||
/// </summary>
|
||||
/// <value>An instance of the Configuration</value>
|
||||
public Org.OpenAPITools.Client.IReadableConfiguration Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides a factory method hook for the creation of exceptions.
|
||||
/// </summary>
|
||||
public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported.");
|
||||
}
|
||||
return _exceptionFactory;
|
||||
}
|
||||
set { _exceptionFactory = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <returns>string</returns>
|
||||
public string TestAuthHttpBasic(int operationIndex = 0)
|
||||
{
|
||||
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = TestAuthHttpBasicWithHttpInfo();
|
||||
return localVarResponse.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <returns>ApiResponse of string</returns>
|
||||
public Org.OpenAPITools.Client.ApiResponse<string> TestAuthHttpBasicWithHttpInfo(int operationIndex = 0)
|
||||
{
|
||||
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
|
||||
|
||||
string[] _contentTypes = new string[] {
|
||||
};
|
||||
|
||||
// to determine the Accept header
|
||||
string[] _accepts = new string[] {
|
||||
"text/plain"
|
||||
};
|
||||
|
||||
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
|
||||
if (localVarContentType != null)
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
|
||||
}
|
||||
|
||||
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
|
||||
if (localVarAccept != null)
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
|
||||
}
|
||||
|
||||
|
||||
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBasic";
|
||||
localVarRequestOptions.OperationIndex = operationIndex;
|
||||
|
||||
// authentication (http_auth) required
|
||||
// http basic authentication required
|
||||
if (!string.IsNullOrEmpty(this.Configuration.Username) || !string.IsNullOrEmpty(this.Configuration.Password) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Org.OpenAPITools.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
|
||||
}
|
||||
|
||||
// make the HTTP request
|
||||
var localVarResponse = this.Client.Post<string>("/auth/http/basic", localVarRequestOptions, this.Configuration);
|
||||
if (this.ExceptionFactory != null)
|
||||
{
|
||||
Exception _exception = this.ExceptionFactory("TestAuthHttpBasic", localVarResponse);
|
||||
if (_exception != null)
|
||||
{
|
||||
throw _exception;
|
||||
}
|
||||
}
|
||||
|
||||
return localVarResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||
/// <returns>Task of string</returns>
|
||||
public async System.Threading.Tasks.Task<string> TestAuthHttpBasicAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = await TestAuthHttpBasicWithHttpInfoAsync(operationIndex, cancellationToken).ConfigureAwait(false);
|
||||
return localVarResponse.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test HTTP basic authentication To test HTTP basic authentication
|
||||
/// </summary>
|
||||
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||
/// <returns>Task of ApiResponse (string)</returns>
|
||||
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<string>> TestAuthHttpBasicWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
|
||||
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
|
||||
|
||||
string[] _contentTypes = new string[] {
|
||||
};
|
||||
|
||||
// to determine the Accept header
|
||||
string[] _accepts = new string[] {
|
||||
"text/plain"
|
||||
};
|
||||
|
||||
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
|
||||
if (localVarContentType != null)
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
|
||||
}
|
||||
|
||||
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
|
||||
if (localVarAccept != null)
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
|
||||
}
|
||||
|
||||
|
||||
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBasic";
|
||||
localVarRequestOptions.OperationIndex = operationIndex;
|
||||
|
||||
// authentication (http_auth) required
|
||||
// http basic authentication required
|
||||
if (!string.IsNullOrEmpty(this.Configuration.Username) || !string.IsNullOrEmpty(this.Configuration.Password) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
|
||||
{
|
||||
localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Org.OpenAPITools.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
|
||||
}
|
||||
|
||||
// make the HTTP request
|
||||
var localVarResponse = await this.AsynchronousClient.PostAsync<string>("/auth/http/basic", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (this.ExceptionFactory != null)
|
||||
{
|
||||
Exception _exception = this.ExceptionFactory("TestAuthHttpBasic", localVarResponse);
|
||||
if (_exception != null)
|
||||
{
|
||||
throw _exception;
|
||||
}
|
||||
}
|
||||
|
||||
return localVarResponse;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user