(20250619) Test vcard URL ready.
This commit is contained in:
@@ -0,0 +1,173 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
AUTHOR:
|
||||||
|
|
||||||
|
Khushal P Soonderji
|
||||||
|
|
||||||
|
DATE:
|
||||||
|
|
||||||
|
Wednesday, 19th Jun., 2025
|
||||||
|
|
||||||
|
OBJECTIVE:
|
||||||
|
|
||||||
|
To have simple tests.
|
||||||
|
|
||||||
|
REFERENCES:
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
DOWNLOADS:
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
# ***** ****
|
||||||
|
# *** IMPORT ***
|
||||||
|
# ***** ****
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# To make sibling directories accessible for imports:
|
||||||
|
import sys
|
||||||
|
sys.path.append(".")
|
||||||
|
sys.path.append("..")
|
||||||
|
|
||||||
|
# For using Quart:
|
||||||
|
from quart import Blueprint, current_app, Response
|
||||||
|
|
||||||
|
# Common:
|
||||||
|
from shared import constants
|
||||||
|
|
||||||
|
# My utils:
|
||||||
|
from utils_v2.string import json
|
||||||
|
from utils_v2.date_time import date_time
|
||||||
|
from utils_v2.security.otp import HashedOTP
|
||||||
|
from utils_v2.api.response import ResponseModel
|
||||||
|
from utils_v2.api.codes import StatusCodes, HttpCodes
|
||||||
|
from utils_v2.api.async_quart import (
|
||||||
|
log_request_to_mongo,
|
||||||
|
only_whitelisted_ips,
|
||||||
|
should_not_be_under_maintenance,
|
||||||
|
read_input,
|
||||||
|
limit_rate,
|
||||||
|
validate_input,
|
||||||
|
set_api_version,
|
||||||
|
log_chain_to_mongo,
|
||||||
|
handle_cancelled_request
|
||||||
|
)
|
||||||
|
|
||||||
|
# Data models:
|
||||||
|
from models.otp.timed_otp import GenerateTimedOTP, VerifyTimedOTP
|
||||||
|
|
||||||
|
# For asynchronous activities:
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
# ***** ****
|
||||||
|
# *** MACROS / ONE-TIME INIT ***
|
||||||
|
# ***** ****
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# Related to Quart:
|
||||||
|
test_bp = Blueprint("test_bp", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
# ***** ****
|
||||||
|
# *** VARIABLES ***
|
||||||
|
# ***** ****
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# --- Nothing Yet
|
||||||
|
|
||||||
|
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
# ***** ****
|
||||||
|
# *** FUNCTIONS ***
|
||||||
|
# ***** ****
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
@test_bp.record_once
|
||||||
|
def init(blueprint_setup_state):
|
||||||
|
|
||||||
|
# This gets called when the blueprint is registered.
|
||||||
|
# Consider this to be a one-time setup for the whole blueprint:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@test_bp.route("/vcard", methods = ["GET"])
|
||||||
|
@set_api_version(api_version = "1.0.0")
|
||||||
|
@read_input(sanitize_headers = True, sanitize_data = True)
|
||||||
|
@log_request_to_mongo(
|
||||||
|
attr_name = "logs_mongo",
|
||||||
|
project = constants.PROJECT_NAME,
|
||||||
|
log_type = "test",
|
||||||
|
operation = "vcard",
|
||||||
|
log_input = True,
|
||||||
|
log_output = True,
|
||||||
|
sensitive_keys = None
|
||||||
|
)
|
||||||
|
@log_chain_to_mongo(attr_name = "logs_mongo")
|
||||||
|
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||||
|
# @only_whitelisted_ips(attr_name = "whitelisted_ips")
|
||||||
|
@validate_input(data_validator = None)
|
||||||
|
@handle_cancelled_request()
|
||||||
|
async def test_vcard(
|
||||||
|
inbound_headers: dict = None,
|
||||||
|
inbound_data: dict = None,
|
||||||
|
inbound_files: dict = None,
|
||||||
|
log_id: str = None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Delivers a dummy VCard.
|
||||||
|
:param inbound_headers: auto-extracted by the decorators from 'async_quart.py'.
|
||||||
|
:param inbound_data: auto-extracted by the decorators from 'async_quart.py'.
|
||||||
|
:param inbound_files: auto-extracted by the decorators from 'async_quart.py'.
|
||||||
|
:param log_id: An identifier for the logs (if logging is enabled).
|
||||||
|
:return: A standard response structure from the function in 'async_quart.py'.
|
||||||
|
"""
|
||||||
|
|
||||||
|
vcard_str = (
|
||||||
|
"BEGIN:VCARD\n"
|
||||||
|
"VERSION:3.0\n"
|
||||||
|
"N:Doe;John;;;\n"
|
||||||
|
"FN:John Doe\n"
|
||||||
|
"TEL;TYPE=CELL:+91-9876543210\n"
|
||||||
|
"EMAIL;TYPE=INTERNET:john.doe@example.com\n"
|
||||||
|
"END:VCARD"
|
||||||
|
)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "text/x-vcard; charset=utf-8",
|
||||||
|
"Content-Disposition": 'inline; filename="test_vcard.vcf"',
|
||||||
|
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||||||
|
}
|
||||||
|
return Response(vcard_str, headers = headers)
|
||||||
|
|
||||||
|
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
# ***** ****
|
||||||
|
# *** MAIN PROGRAM ***
|
||||||
|
# ***** ****
|
||||||
|
# *****************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
pass
|
||||||
@@ -76,6 +76,7 @@ from api_v2.blueprints.cred_and_data.blueprint import cred_and_data_bp
|
|||||||
from api_v2.blueprints.logs.blueprint import logs_bp
|
from api_v2.blueprints.logs.blueprint import logs_bp
|
||||||
from api_v2.blueprints.otp.blueprint import otp_bp
|
from api_v2.blueprints.otp.blueprint import otp_bp
|
||||||
from api_v2.blueprints.servers.blueprint import servers_bp
|
from api_v2.blueprints.servers.blueprint import servers_bp
|
||||||
|
from api_v2.blueprints.test.blueprint import test_bp
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
# *****************************************************************************************************************
|
||||||
@@ -104,6 +105,7 @@ app.register_blueprint(cred_and_data_bp, url_prefix = f"/{MODULE_BASE}")
|
|||||||
app.register_blueprint(logs_bp, url_prefix = f"/{MODULE_BASE}/logs")
|
app.register_blueprint(logs_bp, url_prefix = f"/{MODULE_BASE}/logs")
|
||||||
app.register_blueprint(otp_bp, url_prefix = f"/{MODULE_BASE}/otp")
|
app.register_blueprint(otp_bp, url_prefix = f"/{MODULE_BASE}/otp")
|
||||||
app.register_blueprint(servers_bp, url_prefix = f"/{MODULE_BASE}/servers")
|
app.register_blueprint(servers_bp, url_prefix = f"/{MODULE_BASE}/servers")
|
||||||
|
app.register_blueprint(test_bp, url_prefix = f"/{MODULE_BASE}/test")
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
# *****************************************************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user