Skip to content

Commit

Permalink
added project into remote repository
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalSontakke committed Sep 5, 2024
0 parents commit 6693261
Show file tree
Hide file tree
Showing 70 changed files with 3,660 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/JazzX.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions API_Requests/Data/Request_Body/post_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "morpheus",
"job": "leader"
}
4 changes: 4 additions & 0 deletions API_Requests/Data/Request_Body/put_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "morpheus",
"job": "zion resident"
}
13 changes: 13 additions & 0 deletions API_Requests/Data/Response_Body/get_data.json
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!"
}
}
26 changes: 26 additions & 0 deletions API_Requests/Lib/Auth_details.py
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
74 changes: 74 additions & 0 deletions API_Requests/Lib/File_Operations.py
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
Loading

0 comments on commit 6693261

Please sign in to comment.