(20251114) Ready to start API testing.

This commit is contained in:
2025-11-14 18:20:54 +05:30
parent 6e19717e0b
commit 5ac5ad9ece
31 changed files with 32194 additions and 15 deletions
View File
View File
+115
View File
@@ -0,0 +1,115 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Fri, 14th Nov, 2025
OBJECTIVE:
To provide data model(s) for common elements of every REST APi request (like the headers).
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, AwareDatetime
from typing import Optional, Literal
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class SimpleCosecCredentialsHeaders(BaseModel):
cosecUrl: str = Field(
description = "The URL to Cosec's portal.",
frozen = True,
alias = "X-Cosec-URL"
)
cosecUsername: str = Field(
description = "The username on Cosec's portal.",
frozen = True,
alias = "X-Cosec-Username"
)
cosecPassword: str = Field(
description = "The password on Cosec's portal.",
frozen = True,
alias = "X-Cosec-Password"
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "allow"
def model_dump(self, *args, **kwargs):
return super().model_dump(*args, by_alias = True, **kwargs)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+137
View File
@@ -0,0 +1,137 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Fri, 14th Nov, 2025.
OBJECTIVE:
To provide data model(s) for receiving API requests to get In?Out Reports.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append("..")
sys.path.append("../..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, AwareDatetime
from typing import Optional, Literal, List
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class CosecInOutReportRequestData(BaseModel):
fromDate: AwareDatetime | None = Field(
description = "The start date from when the in-out report is desired.",
frozen = True,
default = None
)
toDate: AwareDatetime | None = Field(
description = "The end date till when the in-out report is desired.",
frozen = True,
default = None
)
groupIds: List[str] | str = Field(
description = "Each company/entity in Cosec's system is represented by a group id. This is a list of those ids.",
frozen = True,
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓┏
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗┛
@field_validator("fromDate", "toDate", mode = "before")
def parse_date_time(cls, value):
if value is None: value = date_time.get_current_utc_date_time(as_string = False)
value = date_time.parse_date_time(
input_value = value,
date_formats = [
"%Y%m%d",
"%Y-%m-%d",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M:%S%z",
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%dT%H:%M:%S%z",
],
timezone = date_time.TIMEZONE_UTC
)
return value
@field_validator("groupIds", mode = "after")
def parse_group_ids(cls, value):
if isinstance(value, str): value = value.split(",")
return value
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass