qyrusai 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qyrusai/__init__.py +3 -0
- qyrusai/_clients.py +29 -0
- qyrusai/_exceptions.py +24 -0
- qyrusai/_rest.py +77 -0
- qyrusai/_types.py +48 -0
- qyrusai/api_assertions/__init__.py +22 -0
- qyrusai/api_assertions/all_assertions.py +99 -0
- qyrusai/api_assertions/headers.py +96 -0
- qyrusai/api_assertions/json_body.py +97 -0
- qyrusai/api_assertions/json_path.py +96 -0
- qyrusai/api_assertions/json_schema.py +97 -0
- qyrusai/api_builder/__init__.py +11 -0
- qyrusai/api_builder/api_builder.py +94 -0
- qyrusai/base/__init__.py +0 -0
- qyrusai/base/base.py +9 -0
- qyrusai/configs.py +48 -0
- qyrusai/data_amplifier/__init__.py +11 -0
- qyrusai/data_amplifier/data_amplifier.py +100 -0
- qyrusai/nova/__init__.py +17 -0
- qyrusai/nova/nova.py +202 -0
- qyrusai/vision_nova/__init__.py +13 -0
- qyrusai/vision_nova/vision_nova.py +181 -0
- qyrusai-0.0.1.dist-info/METADATA +87 -0
- qyrusai-0.0.1.dist-info/RECORD +31 -0
- qyrusai-0.0.1.dist-info/WHEEL +5 -0
- qyrusai-0.0.1.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/test_all_services.py +557 -0
- tests/test_api_builder.py +164 -0
- tests/test_data_amplifier.py +99 -0
- tests/test_functions.py +46 -0
qyrusai/__init__.py
ADDED
qyrusai/_clients.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# from nova import AsyncNova
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from .nova import AsyncNova, SyncNova
|
|
4
|
+
from .api_builder.api_builder import AsyncApiBuilder,SyncApiBuilder
|
|
5
|
+
from .data_amplifier.data_amplifier import AsyncDataAmplifier, SyncDataAmplifier
|
|
6
|
+
from .api_assertions import AsyncAssertions, SyncAssertions
|
|
7
|
+
from .vision_nova import Async_Vision_Nova, Sync_Vision_Nova
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AsyncQyrusAI:
|
|
11
|
+
|
|
12
|
+
# def __init__(self, api_key: str, base_url: Optional[str] = None) -> None:
|
|
13
|
+
def __init__(self, api_key: str) -> None:
|
|
14
|
+
self.nova = AsyncNova(api_key)
|
|
15
|
+
self.api_builder = AsyncApiBuilder(api_key)
|
|
16
|
+
self.data_amplifier = AsyncDataAmplifier(api_key)
|
|
17
|
+
self.api_assertions = AsyncAssertions(api_key)
|
|
18
|
+
self.vision_nova = Async_Vision_Nova(api_key)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SyncQyrusAI:
|
|
22
|
+
|
|
23
|
+
# def __init__(self, api_key: str, base_url: Optional[str] = None) -> None:
|
|
24
|
+
def __init__(self, api_key: str) -> None:
|
|
25
|
+
self.nova = SyncNova(api_key)
|
|
26
|
+
self.api_builder = SyncApiBuilder(api_key)
|
|
27
|
+
self.data_amplifier = SyncDataAmplifier(api_key)
|
|
28
|
+
self.api_assertions = SyncAssertions(api_key)
|
|
29
|
+
self.vision_nova = Sync_Vision_Nova(api_key)
|
qyrusai/_exceptions.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# exceptions.py
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CustomException(Exception):
|
|
5
|
+
|
|
6
|
+
def __init__(self, exce_msg):
|
|
7
|
+
super().__init__(exce_msg)
|
|
8
|
+
self.message = exce_msg
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AuthorizationException(CustomException):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RequestException(CustomException):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ErrorException(CustomException):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class EntityException(CustomException):
|
|
24
|
+
pass
|
qyrusai/_rest.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
import asyncio
|
|
3
|
+
from ._exceptions import AuthorizationException, RequestException, ErrorException, EntityException
|
|
4
|
+
from fastapi.responses import JSONResponse
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AsyncHTTPClient:
|
|
8
|
+
|
|
9
|
+
async def post(self, url, data, headers=None):
|
|
10
|
+
# print("\nURL (ASYNC) : ", url)
|
|
11
|
+
# print("\nDATA for Service Call (ASYNC) : ", data)
|
|
12
|
+
async with httpx.AsyncClient(timeout=600) as client:
|
|
13
|
+
try:
|
|
14
|
+
response = await client.post(url, json=data, headers=headers)
|
|
15
|
+
print(f"Response status code: {response.status_code}")
|
|
16
|
+
if response.status_code == 200:
|
|
17
|
+
return response.json()
|
|
18
|
+
elif response.status_code == 401:
|
|
19
|
+
raise AuthorizationException(
|
|
20
|
+
"Unauthorized: Access is denied due to invalid credentials. Please provide valid authentication details to access this resource."
|
|
21
|
+
)
|
|
22
|
+
elif response.status_code == 500:
|
|
23
|
+
raise RequestException(
|
|
24
|
+
"Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request."
|
|
25
|
+
)
|
|
26
|
+
elif response.status_code in [422, 400]:
|
|
27
|
+
raise EntityException(
|
|
28
|
+
"Bad Request: The server could not understand the request due to invalid syntax or incorrect input data."
|
|
29
|
+
)
|
|
30
|
+
else:
|
|
31
|
+
raise ErrorException("An unexpected error occurred")
|
|
32
|
+
# except httpx.HTTPStatusError as e:
|
|
33
|
+
# # print(f"HTTPStatusError: {e}")
|
|
34
|
+
except httpx.RequestError as e:
|
|
35
|
+
print(f"RequestError: {e}")
|
|
36
|
+
raise
|
|
37
|
+
except asyncio.TimeoutError:
|
|
38
|
+
print("Request timed out")
|
|
39
|
+
raise
|
|
40
|
+
except Exception as e:
|
|
41
|
+
print(f"An unexpected error occurred: {e}")
|
|
42
|
+
raise
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class SyncHTTPClient:
|
|
46
|
+
|
|
47
|
+
def post(self, url, data, headers=None):
|
|
48
|
+
# print("\nURL (SYNC) : ", url)
|
|
49
|
+
# print("\nDATA for Service Call (SYNC) : ", data)
|
|
50
|
+
with httpx.Client(timeout=600) as client:
|
|
51
|
+
try:
|
|
52
|
+
response = client.post(url, json=data, headers=headers)
|
|
53
|
+
if response.status_code == 200:
|
|
54
|
+
return response.json()
|
|
55
|
+
elif response.status_code == 401:
|
|
56
|
+
raise AuthorizationException(
|
|
57
|
+
"Unauthorized: Access is denied due to invalid credentials. Please provide valid authentication details to access this resource."
|
|
58
|
+
)
|
|
59
|
+
elif response.status_code == 500:
|
|
60
|
+
raise RequestException(
|
|
61
|
+
"Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request."
|
|
62
|
+
)
|
|
63
|
+
elif response.status_code in [422, 400]:
|
|
64
|
+
raise EntityException(
|
|
65
|
+
"Bad Request: The server could not understand the request due to invalid syntax or incorrect input data."
|
|
66
|
+
)
|
|
67
|
+
else:
|
|
68
|
+
raise ErrorException("An unexpected error occurred")
|
|
69
|
+
except httpx.RequestError as e:
|
|
70
|
+
print(f"RequestError: {e}")
|
|
71
|
+
raise
|
|
72
|
+
except asyncio.TimeoutError:
|
|
73
|
+
print("Request timed out")
|
|
74
|
+
raise
|
|
75
|
+
except Exception as e:
|
|
76
|
+
print(f"An unexpected error occurred: {e}")
|
|
77
|
+
raise
|
qyrusai/_types.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import List, Optional, Dict, Union
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Pydantic for Input and Response
|
|
6
|
+
class Scenario(BaseModel):
|
|
7
|
+
test_script_name: str
|
|
8
|
+
test_script_objective: str
|
|
9
|
+
reason_to_test: str
|
|
10
|
+
criticality_description: str
|
|
11
|
+
criticality_score: int
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CreateScenariosResponse(BaseModel):
|
|
15
|
+
ok: bool
|
|
16
|
+
message: str
|
|
17
|
+
scenarios: Optional[List[Scenario]] = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class JiraDetails(BaseModel):
|
|
21
|
+
jira_endpoint: str
|
|
22
|
+
jira_api_token: str
|
|
23
|
+
jira_username: str
|
|
24
|
+
jira_id: str
|
|
25
|
+
|
|
26
|
+
class UserDescription(BaseModel):
|
|
27
|
+
user_description: str
|
|
28
|
+
|
|
29
|
+
class ApiBuilderResponse(BaseModel):
|
|
30
|
+
swagger_dictionary: dict
|
|
31
|
+
|
|
32
|
+
class DataAmplifierResponse(BaseModel):
|
|
33
|
+
data: Optional[Dict] = None
|
|
34
|
+
status: bool
|
|
35
|
+
message: str
|
|
36
|
+
|
|
37
|
+
class AssertionHeaderRequest(BaseModel):
|
|
38
|
+
headers: Union[List, Dict, str]
|
|
39
|
+
|
|
40
|
+
# class AssertionHeaderResponse(BaseModel):
|
|
41
|
+
# assertions: Union[List, Dict, str]
|
|
42
|
+
class AssertionResponseRequest(BaseModel):
|
|
43
|
+
response: Union[List, Dict, str]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class AssertionAllRequest(BaseModel):
|
|
47
|
+
headers: Union[List, Dict, str]
|
|
48
|
+
response: Union[List, Dict, str]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from .headers import AsyncHeaderAssertions,SyncHeaderAssertions
|
|
3
|
+
from .json_body import AsyncJSONBodyAssertions,SyncJSONBodyAssertions
|
|
4
|
+
from .json_path import AsyncJSONPathAssertions,SyncJSONPathAssertions
|
|
5
|
+
from .json_schema import AsyncJSONSchemaAssertions,SyncJSONSchemaAssertions
|
|
6
|
+
from .all_assertions import AsyncAllAssertions,SyncAllAssertions
|
|
7
|
+
|
|
8
|
+
class AsyncAssertions:
|
|
9
|
+
def __init__(self, api_key: str) -> None:
|
|
10
|
+
self.headers = AsyncHeaderAssertions(api_key)
|
|
11
|
+
self.jsonbody = AsyncJSONBodyAssertions(api_key)
|
|
12
|
+
self.jsonpath = AsyncJSONPathAssertions(api_key)
|
|
13
|
+
self.jsonschema = AsyncJSONSchemaAssertions(api_key)
|
|
14
|
+
self.all_assertions = AsyncAllAssertions(api_key)
|
|
15
|
+
|
|
16
|
+
class SyncAssertions:
|
|
17
|
+
def __init__(self, api_key: str) -> None:
|
|
18
|
+
self.headers = SyncHeaderAssertions(api_key)
|
|
19
|
+
self.jsonbody = SyncJSONBodyAssertions(api_key)
|
|
20
|
+
self.jsonpath = SyncJSONPathAssertions(api_key)
|
|
21
|
+
self.jsonschema = SyncJSONSchemaAssertions(api_key)
|
|
22
|
+
self.all_assertions = SyncAllAssertions(api_key)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
from qyrusai.configs import Configurations
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
from qyrusai._rest import AsyncHTTPClient,SyncHTTPClient
|
|
6
|
+
from qyrusai._types import AssertionAllRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AsyncAllAssertions:
|
|
10
|
+
def __init__(self, api_key: str):
|
|
11
|
+
self.api_key = api_key
|
|
12
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
13
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
14
|
+
if not token_valid:
|
|
15
|
+
raise Exception("401")
|
|
16
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
17
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
18
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
19
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
20
|
+
|
|
21
|
+
async def create(self, headers:str, response:str):
|
|
22
|
+
"""Generate Header, JSON Assertions.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
response (AssertionResponseRequest): response
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
_type_: Returns the list of JSON key ,value and desriptions.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("all"))
|
|
32
|
+
|
|
33
|
+
data = {
|
|
34
|
+
"headers": headers,
|
|
35
|
+
"response": response
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
headers = {
|
|
39
|
+
'Content-Type': 'application/json',
|
|
40
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
41
|
+
'Custom': self.api_key
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async_client = AsyncHTTPClient()
|
|
45
|
+
response_data = await async_client.post(url, data, headers)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# print(f"response_data [ASYNC] (ALL Assertions) : {response_data}")
|
|
49
|
+
# print(
|
|
50
|
+
# f"response_data [ASYNC] (ALL Assertions) TYPE == >> : {type(response_data)}"
|
|
51
|
+
# )
|
|
52
|
+
|
|
53
|
+
return response_data
|
|
54
|
+
|
|
55
|
+
class SyncAllAssertions:
|
|
56
|
+
def __init__(self, api_key: str):
|
|
57
|
+
self.api_key = api_key
|
|
58
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
59
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
60
|
+
if not token_valid:
|
|
61
|
+
raise Exception("401")
|
|
62
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
63
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
64
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
65
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
66
|
+
|
|
67
|
+
def create(self, headers:str, response:str):
|
|
68
|
+
"""Generate Header, JSON Assertions.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
response (AssertionResponseRequest): response
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
_type_: Returns the list of header and JSON assertions
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("all"))
|
|
78
|
+
|
|
79
|
+
data = {
|
|
80
|
+
"headers": headers,
|
|
81
|
+
"response": response
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
headers = {
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
87
|
+
'Custom': self.api_key
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sync_client = SyncHTTPClient()
|
|
91
|
+
response_data = sync_client.post(url, data, headers)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# print(f"response_data [SYNC] (ALL Assertions) : {response_data}")
|
|
95
|
+
# print(
|
|
96
|
+
# f"response_data [SYNC] (ALL Assertions) TYPE == >> : {type(response_data)}"
|
|
97
|
+
# )
|
|
98
|
+
|
|
99
|
+
return response_data
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from qyrusai.configs import Configurations
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from urllib.parse import urljoin
|
|
4
|
+
from qyrusai._rest import AsyncHTTPClient,SyncHTTPClient
|
|
5
|
+
from qyrusai._types import AssertionHeaderRequest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AsyncHeaderAssertions:
|
|
9
|
+
def __init__(self, api_key: str):
|
|
10
|
+
self.api_key = api_key
|
|
11
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
12
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
13
|
+
if not token_valid:
|
|
14
|
+
raise Exception("401")
|
|
15
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
16
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
17
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
18
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
19
|
+
|
|
20
|
+
async def create(self, headers: AssertionHeaderRequest):
|
|
21
|
+
"""Generate Header Assertions.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
headers (AssertionHeaderRequest): headers
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
_type_: Returns the list of header's key ,value and desriptions.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("headers"))
|
|
31
|
+
|
|
32
|
+
data = {
|
|
33
|
+
"headers": headers
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
headers = {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
39
|
+
'Custom': self.api_key
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async_client = AsyncHTTPClient()
|
|
43
|
+
response_data = await async_client.post(url, data, headers)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# print(f"response_data [ASYNC] (Header Assertions) : {response_data}")
|
|
47
|
+
# print(
|
|
48
|
+
# f"response_data [ASYNC] (Header Assertions) TYPE == >> : {type(response_data)}"
|
|
49
|
+
# )
|
|
50
|
+
|
|
51
|
+
return response_data
|
|
52
|
+
|
|
53
|
+
class SyncHeaderAssertions:
|
|
54
|
+
def __init__(self, api_key: str):
|
|
55
|
+
self.api_key = api_key
|
|
56
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
57
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
58
|
+
if not token_valid:
|
|
59
|
+
raise Exception("401")
|
|
60
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
61
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
62
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
63
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
64
|
+
|
|
65
|
+
def create(self, headers: AssertionHeaderRequest):
|
|
66
|
+
"""Generate Header Assertions.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
headers (AssertionHeaderRequest): headers
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
_type_: Returns the list of header's key ,value and desriptions.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("headers"))
|
|
76
|
+
|
|
77
|
+
data = {
|
|
78
|
+
"headers": headers
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
headers = {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
84
|
+
'Custom': self.api_key
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
sync_client = SyncHTTPClient()
|
|
88
|
+
response_data = sync_client.post(url, data, headers)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# print(f"response_data [SYNC] (Header Assertions) : {response_data}")
|
|
92
|
+
# print(
|
|
93
|
+
# f"response_data [SYNC] (Header Assertions) TYPE == >> : {type(response_data)}"
|
|
94
|
+
# )
|
|
95
|
+
|
|
96
|
+
return response_data
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
|
|
2
|
+
from qyrusai.configs import Configurations
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
from qyrusai._rest import AsyncHTTPClient,SyncHTTPClient
|
|
6
|
+
from qyrusai._types import AssertionResponseRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AsyncJSONBodyAssertions:
|
|
10
|
+
def __init__(self, api_key: str):
|
|
11
|
+
self.api_key = api_key
|
|
12
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
13
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
14
|
+
if not token_valid:
|
|
15
|
+
raise Exception("401")
|
|
16
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
17
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
18
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
19
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
20
|
+
|
|
21
|
+
async def create(self, response: AssertionResponseRequest):
|
|
22
|
+
"""Generate JSONBODY Assertions.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
response (AssertionResponseRequest): response
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
_type_: Returns the list of header's key ,value and desriptions.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("jsonbody"))
|
|
32
|
+
|
|
33
|
+
data = {
|
|
34
|
+
"response": response
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
headers = {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
40
|
+
'Custom': self.api_key
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async_client = AsyncHTTPClient()
|
|
44
|
+
response_data = await async_client.post(url, data, headers)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# print(f"response_data [ASYNC] (JSON Body Assertions) : {response_data}")
|
|
48
|
+
# print(
|
|
49
|
+
# f"response_data [ASYNC] (JSON Body Assertions) TYPE == >> : {type(response_data)}"
|
|
50
|
+
# )
|
|
51
|
+
|
|
52
|
+
return response_data
|
|
53
|
+
|
|
54
|
+
class SyncJSONBodyAssertions:
|
|
55
|
+
def __init__(self, api_key: str):
|
|
56
|
+
self.api_key = api_key
|
|
57
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
58
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
59
|
+
if not token_valid:
|
|
60
|
+
raise Exception("401")
|
|
61
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
62
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
63
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
64
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
65
|
+
|
|
66
|
+
def create(self, response: AssertionResponseRequest):
|
|
67
|
+
"""Generate JSONBODY Assertions.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
response (AssertionResponseRequest): response
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
_type_: Returns the list of header's key ,value and desriptions.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("jsonbody"))
|
|
77
|
+
|
|
78
|
+
data = {
|
|
79
|
+
"response": response
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
headers = {
|
|
83
|
+
'Content-Type': 'application/json',
|
|
84
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
85
|
+
'Custom': self.api_key
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sync_client = SyncHTTPClient()
|
|
89
|
+
response_data = sync_client.post(url, data, headers)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# print(f"response_data [SYNC] (JSON Body Assertions) : {response_data}")
|
|
93
|
+
# print(
|
|
94
|
+
# f"response_data [SYNC] (JSON Body Assertions) TYPE == >> : {type(response_data)}"
|
|
95
|
+
# )
|
|
96
|
+
|
|
97
|
+
return response_data
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
from qyrusai.configs import Configurations
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
from qyrusai._rest import AsyncHTTPClient,SyncHTTPClient
|
|
6
|
+
from qyrusai._types import AssertionResponseRequest
|
|
7
|
+
|
|
8
|
+
class AsyncJSONPathAssertions:
|
|
9
|
+
def __init__(self, api_key: str):
|
|
10
|
+
self.api_key = api_key
|
|
11
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
12
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
13
|
+
if not token_valid:
|
|
14
|
+
raise Exception("401")
|
|
15
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
16
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
17
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
18
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
19
|
+
|
|
20
|
+
async def create(self, response: AssertionResponseRequest):
|
|
21
|
+
"""Generate JSONPATH Assertions.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
response (AssertionResponseRequest): response
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
_type_: Returns the list of JSON key ,value and desriptions.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("jsonpath"))
|
|
31
|
+
|
|
32
|
+
data = {
|
|
33
|
+
"response": response
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
headers = {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
39
|
+
'Custom': self.api_key
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async_client = AsyncHTTPClient()
|
|
43
|
+
response_data = await async_client.post(url, data, headers)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# print(f"response_data [ASYNC] (JSON Path Assertions) : {response_data}")
|
|
47
|
+
# print(
|
|
48
|
+
# f"response_data [ASYNC] (JSON Path Assertions) TYPE == >> : {type(response_data)}"
|
|
49
|
+
# )
|
|
50
|
+
|
|
51
|
+
return response_data
|
|
52
|
+
|
|
53
|
+
class SyncJSONPathAssertions:
|
|
54
|
+
def __init__(self, api_key: str):
|
|
55
|
+
self.api_key = api_key
|
|
56
|
+
# token_valid = asyncio.run(Configurations.verifyToken(api_key)) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
57
|
+
token_valid = Configurations.verifyToken(api_key) # If True is stored, well and good otherwise an Exception will have been raised already if something goes wrong.
|
|
58
|
+
if not token_valid:
|
|
59
|
+
raise Exception("401")
|
|
60
|
+
gatewayDetails = Configurations.getDefaultGateway(api_key)
|
|
61
|
+
# gatewayDetails = asyncio.run(Configurations.getDefaultGateway(api_key))
|
|
62
|
+
self.base_url = gatewayDetails.get("gatewayUrl")
|
|
63
|
+
self.gateway_token = gatewayDetails.get("gatewayToken")
|
|
64
|
+
|
|
65
|
+
def create(self, response: AssertionResponseRequest):
|
|
66
|
+
"""Generate JSONPATH Assertions.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
response (AssertionResponseRequest): response
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
_type_: Returns the list of header's key ,value and desriptions.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
url = urljoin(self.base_url,Configurations.getAPIAssertions("jsonpath"))
|
|
76
|
+
|
|
77
|
+
data = {
|
|
78
|
+
"response": response
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
headers = {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
'Authorization': "Bearer "+self.gateway_token,
|
|
84
|
+
'Custom': self.api_key
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
sync_client = SyncHTTPClient()
|
|
88
|
+
response_data = sync_client.post(url, data, headers)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# print(f"response_data [SYNC] (JSON Path Assertions) : {response_data}")
|
|
92
|
+
# print(
|
|
93
|
+
# f"response_data [SYNC] (JSON Path Assertions) TYPE == >> : {type(response_data)}"
|
|
94
|
+
# )
|
|
95
|
+
|
|
96
|
+
return response_data
|