-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added project into remote repository
- Loading branch information
0 parents
commit 6693261
Showing
70 changed files
with
3,660 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "morpheus", | ||
"job": "leader" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "morpheus", | ||
"job": "zion resident" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"data": { | ||
"id": 2, | ||
"email": "[email protected]", | ||
"first_name": "Janet", | ||
"last_name": "Weaver", | ||
"avatar": "https://reqres.in/img/faces/2-image.jpg" | ||
}, | ||
"support": { | ||
"url": "https://reqres.in/#support-heading", | ||
"text": "To keep ReqRes free, contributions towards server costs are appreciated!" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Auth_Details: | ||
""" | ||
A utility class for handling authentication details like username and password. | ||
This class provides static methods to retrieve the username and password | ||
for authentication purposes. These methods can be used to fetch credentials | ||
when making API requests or connecting to services that require authentication. | ||
""" | ||
|
||
@staticmethod | ||
def get_username(): | ||
""" | ||
Retrieve the username for authentication. | ||
:return: A string representing the username. | ||
""" | ||
username = "kunal.sontakke" | ||
return username | ||
|
||
@staticmethod | ||
def get_password(): | ||
""" | ||
Retrieve the password for authentication. | ||
:return: A string representing the password. | ||
""" | ||
|
||
password = " " | ||
return password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import json | ||
import os.path | ||
from conf.conftest import logger | ||
|
||
|
||
def save_json_to_file(response,file_path,response_dir='API_Requests/Data/Response_Body'): | ||
""" | ||
Prepare the response data and save it to a JSON file. | ||
:param response_dir: The response directory where all response file will be stored | ||
:param response: The response data to be saved, can be a dict, list, tuple, or string. | ||
:param file_path: Path to the file where the JSON data will be saved. | ||
""" | ||
|
||
def handle_tuple(data): | ||
return data[0] | ||
|
||
def handle_list(data): | ||
return data | ||
|
||
def handle_string(data): | ||
return json.loads(data) | ||
|
||
def handle_dict(data): | ||
return data | ||
# Mapping of types to their corresponding handling functions | ||
handler_mapping = { | ||
tuple: handle_tuple, | ||
list : handle_list, | ||
str : handle_string, | ||
dict : handle_dict | ||
} | ||
|
||
try: | ||
# Select the handler based on the type of response | ||
handler = handler_mapping.get(type(response)) | ||
if not handler: | ||
raise TypeError("Unsupported response type") | ||
json_data = handler(response) | ||
# Save the JSON data to the specified file | ||
full_path = os.path.join(response_dir, file_path) | ||
with open(full_path,'w') as file: | ||
json.dump(json_data, file, indent=4, separators=(',',': ')) | ||
logger.info(f"JSON data successfully saved to {full_path}") | ||
except (json.JSONDecodeError, TypeError) as e: | ||
logger.error(f"An error occurred while preparing JSON data:{e}") | ||
raise e | ||
except OSError as e: | ||
logger.error(f"An error occurred while saving JSON data:{e}") | ||
raise e | ||
|
||
|
||
def read_json_from_file(file_path,request_dir='API_Requests/Data/Request_Body'): | ||
""" Static method to read JSON data from a file. | ||
:param request_dir: directory where the request json data is stored. | ||
:param file_path: Path to the file from which the JSON data will be read. | ||
:return: Parsed JSON data (as a dictionary or list). | ||
""" | ||
try: | ||
full_path = os.path.join(request_dir,file_path) | ||
with open(full_path, 'r') as file: | ||
data = json.load(file) | ||
logger.info(f"JSON data successfully read from {full_path}") | ||
return data | ||
except json.JSONDecodeError as e: | ||
logger.error(f"Failed to decode JSON: {e}") | ||
raise e | ||
except FileNotFoundError as e: | ||
logger.error(f"File not found: {e}") | ||
raise e | ||
except Exception as e: | ||
logger.exception(f"An error occurred while reading JSON data: {e}") | ||
raise e |
Oops, something went wrong.