brand: remove all poona references and standardize on XYZ Hospital
This commit is contained in:
@@ -2,7 +2,7 @@ import logging
|
||||
from sqlalchemy.engine import Engine
|
||||
from ..models import Base
|
||||
|
||||
logger = logging.getLogger("poona_ams")
|
||||
logger = logging.getLogger("xyz_ams")
|
||||
|
||||
|
||||
def run_sqlite_migrations(engine: Engine) -> None:
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ logging.basicConfig(
|
||||
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
|
||||
level=logging.INFO,
|
||||
)
|
||||
logger = logging.getLogger("poona_ams")
|
||||
logger = logging.getLogger("xyz_ams")
|
||||
|
||||
|
||||
def _scheduled_alert_job() -> None:
|
||||
@@ -86,7 +86,7 @@ async def lifespan(app: FastAPI):
|
||||
scheduler.start()
|
||||
logger.info("APScheduler daily alert check started (06:00 %s).", app_settings.TIMEZONE)
|
||||
|
||||
logger.info("Poona Hospital AMS started.")
|
||||
logger.info("XYZ Hospital AMS started.")
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
@@ -96,7 +96,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Poona Hospital AMS",
|
||||
title="XYZ Hospital AMS",
|
||||
version="0.1.0",
|
||||
docs_url="/docs",
|
||||
lifespan=lifespan,
|
||||
|
||||
@@ -5,4 +5,4 @@ router = APIRouter(tags=["health"])
|
||||
|
||||
@router.get("/health")
|
||||
def health_check():
|
||||
return {"status": "ok", "service": "Poona Hospital AMS", "version": "0.1.0"}
|
||||
return {"status": "ok", "service": "XYZ Hospital AMS", "version": "0.1.0"}
|
||||
|
||||
+15
-15
@@ -65,7 +65,7 @@ def _make_placeholder_jpeg(dest: Path, label: str, bg_rgb: tuple[int, int, int])
|
||||
img = Image.new("RGB", (640, 480), color=bg_rgb)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.rectangle([20, 20, 620, 460], outline=(255, 255, 255), width=3)
|
||||
draw.text((40, 200), "Poona Hospital & Research Centre", fill=(255, 255, 255))
|
||||
draw.text((40, 200), "XYZ Hospital", fill=(255, 255, 255))
|
||||
draw.text((40, 240), label, fill=(240, 240, 240))
|
||||
img.save(dest, format="JPEG", quality=80)
|
||||
return dest.stat().st_size
|
||||
@@ -205,17 +205,17 @@ def seed_database(db: Session, upload_dir: Path | None = None) -> dict[str, int]
|
||||
# 7. Users (11: 5 demo + 6 realistic hospital staff)
|
||||
demo_pw_hash = hash_password("Demo@123")
|
||||
user_specs = [
|
||||
("Dr. Rajesh Kulkarni", "admin@poona.demo", "system_admin", None),
|
||||
("Suresh Deshmukh", "bio@poona.demo", "biomedical", None),
|
||||
("Sister Kavita Joshi", "dept@poona.demo", "department_user", departments[0].id), # ICU
|
||||
("Dr. Anjali Gokhale", "mgmt@poona.demo", "management", None),
|
||||
("Priya Patwardhan", "coord@poona.demo", "coordinator", None),
|
||||
("Vikram Shinde", "vikram.shinde@poona.demo", "biomedical", None),
|
||||
("Sneha Kulkarni", "sneha.kulkarni@poona.demo", "biomedical", None),
|
||||
("Dr. Amit Bhosale", "dr.amit.bhosale@poona.demo", "department_user", departments[1].id), # OT
|
||||
("Meera Nair", "meera.nair@poona.demo", "department_user", departments[2].id), # RAD
|
||||
("Rohit Deshpande", "rohit.deshpande@poona.demo", "department_user", departments[3].id), # CARD
|
||||
("Neha Chavan", "neha.chavan@poona.demo", "coordinator", None),
|
||||
("Dr. Rajesh Kulkarni", "admin@xyz.demo", "system_admin", None),
|
||||
("Suresh Deshmukh", "bio@xyz.demo", "biomedical", None),
|
||||
("Sister Kavita Joshi", "dept@xyz.demo", "department_user", departments[0].id), # ICU
|
||||
("Dr. Anjali Gokhale", "mgmt@xyz.demo", "management", None),
|
||||
("Priya Patwardhan", "coord@xyz.demo", "coordinator", None),
|
||||
("Vikram Shinde", "vikram.shinde@xyz.demo", "biomedical", None),
|
||||
("Sneha Kulkarni", "sneha.kulkarni@xyz.demo", "biomedical", None),
|
||||
("Dr. Amit Bhosale", "dr.amit.bhosale@xyz.demo", "department_user", departments[1].id), # OT
|
||||
("Meera Nair", "meera.nair@xyz.demo", "department_user", departments[2].id), # RAD
|
||||
("Rohit Deshpande", "rohit.deshpande@xyz.demo", "department_user", departments[3].id), # CARD
|
||||
("Neha Chavan", "neha.chavan@xyz.demo", "coordinator", None),
|
||||
]
|
||||
users: list[User] = []
|
||||
for uname, uemail, urole, udept in user_specs:
|
||||
@@ -337,7 +337,7 @@ def seed_database(db: Session, upload_dir: Path | None = None) -> dict[str, int]
|
||||
criticality=criticality,
|
||||
requires_calibration=needs_cal,
|
||||
insurance_applicable=needs_ins,
|
||||
remarks="Procured under Poona Hospital capital equipment budget." if not is_rented else "Leased medical equipment on monthly rental.",
|
||||
remarks="Procured under XYZ Hospital capital equipment budget." if not is_rented else "Leased medical equipment on monthly rental.",
|
||||
created_by_id=admin_user.id,
|
||||
updated_by_id=admin_user.id,
|
||||
)
|
||||
@@ -716,7 +716,7 @@ def seed_database(db: Session, upload_dir: Path | None = None) -> dict[str, int]
|
||||
description=issue_descriptions[idx % len(issue_descriptions)],
|
||||
breakdown_details=f"Reported by {asset.department.code} nursing/technical staff during routine shift.",
|
||||
priority=priority,
|
||||
notes="Logged via Poona AMS helpdesk.",
|
||||
notes="Logged via XYZ AMS helpdesk.",
|
||||
registered_at=reg_at,
|
||||
registered_by_id=reg_user.id,
|
||||
received_by_id=recv_user.id,
|
||||
@@ -820,7 +820,7 @@ def seed_database(db: Session, upload_dir: Path | None = None) -> dict[str, int]
|
||||
for p in range(6):
|
||||
fname = f"seed_doc_{p + 1:02d}.pdf"
|
||||
fpath = target_upload_dir / fname
|
||||
pdf_bytes = _make_minimal_pdf(f"Poona Hospital Service / Calibration Report #{p + 1}")
|
||||
pdf_bytes = _make_minimal_pdf(f"XYZ Hospital Service / Calibration Report #{p + 1}")
|
||||
fpath.write_bytes(pdf_bytes)
|
||||
db.add(
|
||||
Attachment(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Poona Hospital Asset Management System
|
||||
XYZ Hospital Asset Management System
|
||||
Bulk Import Template Builders for Contracts, Calibration Plans, and Insurance Policies.
|
||||
"""
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ def _write_styled_sheet(ws, report_payload: dict[str, Any]) -> None:
|
||||
# Explicitly show grid lines in Excel view
|
||||
ws.views.sheetView[0].showGridLines = True
|
||||
|
||||
title_text = f"Poona Hospital & Research Centre \u2014 {report_payload['title']}"
|
||||
title_text = f"XYZ Hospital \u2014 {report_payload['title']}"
|
||||
meta_text = (
|
||||
f"Generated: {format_datetime(utc_now())} IST | "
|
||||
f"Filters: {_format_filters_echo(report_payload.get('filters_applied', {}))}"
|
||||
@@ -218,7 +218,7 @@ def _write_styled_sheet(ws, report_payload: dict[str, Any]) -> None:
|
||||
ws.page_setup.fitToHeight = 0
|
||||
ws.sheet_properties.pageSetUpPr.fitToPage = True
|
||||
ws.print_title_rows = f"{header_row}:{header_row}"
|
||||
ws.oddHeader.left.text = "&BPoona Hospital & Research Centre&B"
|
||||
ws.oddHeader.left.text = "&BXYZ Hospital&B"
|
||||
ws.oddHeader.right.text = report_payload.get("title", "Operational Report")
|
||||
ws.oddFooter.left.text = "Confidential • Biomedical Asset Management System"
|
||||
ws.oddFooter.right.text = "Page &P of &N"
|
||||
@@ -315,7 +315,7 @@ def build_csv(report_payload: dict[str, Any]) -> BytesIO:
|
||||
sio = StringIO()
|
||||
writer = csv.writer(sio)
|
||||
|
||||
writer.writerow([f"Poona Hospital & Research Centre - {report_payload['title']}"])
|
||||
writer.writerow([f"XYZ Hospital - {report_payload['title']}"])
|
||||
writer.writerow(
|
||||
[
|
||||
f"Generated: {format_datetime(utc_now())} IST",
|
||||
|
||||
@@ -262,7 +262,7 @@ SETTINGS_SCHEMA: list[dict[str, Any]] = [
|
||||
"type": "str",
|
||||
"default": "",
|
||||
"label": "SMTP Host",
|
||||
"description": "Hospital outbound mail server hostname (e.g. smtp.poonahospital.org).",
|
||||
"description": "Hospital outbound mail server hostname (e.g. smtp.xyzhospital.org).",
|
||||
"min": None,
|
||||
"max": None,
|
||||
"options": None,
|
||||
@@ -280,7 +280,7 @@ SETTINGS_SCHEMA: list[dict[str, Any]] = [
|
||||
{
|
||||
"key": "smtp_from_email",
|
||||
"type": "str",
|
||||
"default": "ams-alerts@poonahospital.org",
|
||||
"default": "ams-alerts@xyzhospital.org",
|
||||
"label": "SMTP From Email Address",
|
||||
"description": "Sender email address displayed on alert notifications.",
|
||||
"min": None,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Poona Hospital Asset Management System (AMS)
|
||||
XYZ Hospital Asset Management System (AMS)
|
||||
Database & Attachments Backup and Disaster Recovery Utility.
|
||||
|
||||
Features:
|
||||
@@ -277,7 +277,7 @@ def run_restore(
|
||||
def main() -> int:
|
||||
default_db, default_uploads, default_backups = get_default_paths()
|
||||
|
||||
parser = argparse.ArgumentParser(description="Poona Hospital AMS Backup & Recovery Utility")
|
||||
parser = argparse.ArgumentParser(description="XYZ Hospital AMS Backup & Recovery Utility")
|
||||
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
|
||||
|
||||
# Backup command
|
||||
|
||||
@@ -168,8 +168,8 @@ def test_sqlite_migration_adds_cost_columns_to_old_db(tmp_path):
|
||||
|
||||
|
||||
def test_department_user_never_receives_cost_fields(client):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
# 1. /api/assets
|
||||
res_assets = client.get("/api/assets?page_size=20", headers=dept_headers)
|
||||
@@ -217,12 +217,12 @@ def test_department_user_never_receives_cost_fields(client):
|
||||
|
||||
|
||||
def test_repair_cost_and_cost_editing_role_permissions(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
|
||||
# Find an ICU complaint visible to dept@poona.demo
|
||||
# Find an ICU complaint visible to dept@xyz.demo
|
||||
comp = (
|
||||
db.query(Complaint)
|
||||
.join(Asset, Complaint.asset_id == Asset.id)
|
||||
@@ -279,7 +279,7 @@ def test_repair_cost_and_cost_editing_role_permissions(client, db):
|
||||
|
||||
|
||||
def test_new_ai_cost_settings_present_and_validated(client):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
res = client.get("/api/settings", headers=admin_headers)
|
||||
assert res.status_code == 200
|
||||
by_key = {item["key"]: item for item in res.json()["items"]}
|
||||
@@ -389,7 +389,7 @@ def test_seed_data_meets_cost_and_ai_prerequisites(db):
|
||||
|
||||
|
||||
def test_asset_and_contract_bulk_import_cost_columns(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
cat = db.query(Category).first()
|
||||
vendor = db.query(Vendor).filter(Vendor.is_active.is_(True)).first()
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ def test_coverage_priority_and_expiry_boundaries_and_superseded(db):
|
||||
|
||||
|
||||
def test_complaint_coverage_snapshot_persists_after_contract_expires(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
asset = _create_isolated_asset(db, "PHRC-COV-0002")
|
||||
vendor = db.query(Vendor).filter(Vendor.is_active.is_(True)).first()
|
||||
today = effective_today(db)
|
||||
@@ -224,7 +224,7 @@ def test_complaint_coverage_snapshot_persists_after_contract_expires(client, db)
|
||||
|
||||
|
||||
def test_pm_outsourced_auto_fill_and_no_active_contract_warning(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
vendor = db.query(Vendor).filter(Vendor.is_active.is_(True)).first()
|
||||
today = effective_today(db)
|
||||
|
||||
@@ -279,7 +279,7 @@ def test_pm_outsourced_auto_fill_and_no_active_contract_warning(client, db):
|
||||
|
||||
|
||||
def test_department_user_reads_coverage_tag_without_cost_fields(client, db):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
icu_asset = db.query(Asset).filter(Asset.department_id == 1).first()
|
||||
assert icu_asset is not None
|
||||
|
||||
|
||||
@@ -269,8 +269,8 @@ def test_breakdown_frequency_and_efficiency_pure_math_and_zero_division():
|
||||
|
||||
|
||||
def test_db_loader_department_scoping_and_demo_clock(client, db):
|
||||
admin = db.query(User).filter(User.email == "admin@poona.demo").first()
|
||||
dept_user = db.query(User).filter(User.email == "dept@poona.demo").first()
|
||||
admin = db.query(User).filter(User.email == "admin@xyz.demo").first()
|
||||
dept_user = db.query(User).filter(User.email == "dept@xyz.demo").first()
|
||||
|
||||
today = effective_today(db)
|
||||
ds_all = load_ai_dataset(db, admin, today - timedelta(days=365), today)
|
||||
@@ -284,7 +284,7 @@ def test_db_loader_department_scoping_and_demo_clock(client, db):
|
||||
# Unassigned department_user -> 0 assets
|
||||
unassigned = User(
|
||||
name="Unassigned Dept",
|
||||
email="unassigned.ai3@poona.demo",
|
||||
email="unassigned.ai3@xyz.demo",
|
||||
password_hash="x",
|
||||
role="department_user",
|
||||
department_id=None,
|
||||
@@ -298,7 +298,7 @@ def test_db_loader_department_scoping_and_demo_clock(client, db):
|
||||
cmp_now = compute_comparison_from_dataset(ds_all)
|
||||
assert len(cmp_now["rows"]) == 10
|
||||
|
||||
admin_res = client.post("/api/auth/login", json={"email": "admin@poona.demo", "password": "Demo@123"})
|
||||
admin_res = client.post("/api/auth/login", json={"email": "admin@xyz.demo", "password": "Demo@123"})
|
||||
headers = {"Authorization": f"Bearer {admin_res.json()['access_token']}"}
|
||||
try:
|
||||
future_date = today + timedelta(days=365 * 2)
|
||||
|
||||
@@ -278,7 +278,7 @@ def test_rule_s8_fully_depreciated_and_low_efficiency():
|
||||
|
||||
def test_seeded_db_produces_expected_suggestions(db, tmp_path):
|
||||
seed_database(db, upload_dir=tmp_path)
|
||||
admin = db.query(User).filter(User.email == "admin@poona.demo").first()
|
||||
admin = db.query(User).filter(User.email == "admin@xyz.demo").first()
|
||||
today = effective_today(db)
|
||||
ds = load_ai_dataset(db, admin, today - timedelta(days=365), today)
|
||||
res = generate_suggestions(ds)
|
||||
|
||||
@@ -291,7 +291,7 @@ def test_ai5_cache_hit_invalidation_and_audit_log(db):
|
||||
|
||||
def test_ai5_privacy_no_pii_or_free_text_in_prompt(db):
|
||||
secret_user = "Dr. Rajesh Deshmukh"
|
||||
secret_email = "rajesh.deshmukh@poonahospital.org"
|
||||
secret_email = "rajesh.deshmukh@xyzhospital.org"
|
||||
secret_desc = "Patient monitor alarm speaker cracked during ICU night shift"
|
||||
secret_remark = "Confidential nurse note about ward staff conflict"
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ AI_EXPORT_SECTIONS = [
|
||||
|
||||
|
||||
def test_ai6_role_matrix_department_user_403_and_viewers_200(client):
|
||||
dept_hdr = _auth_headers(client, "dept@poona.demo")
|
||||
dept_hdr = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
# department_user must get 403 on EVERY /api/ai/* route
|
||||
for url in AI_GET_ENDPOINTS:
|
||||
@@ -61,9 +61,9 @@ def test_ai6_role_matrix_department_user_403_and_viewers_200(client):
|
||||
|
||||
# management, coordinator, biomedical get 200 on all GETs, 403 on regenerate
|
||||
for email in (
|
||||
"mgmt@poona.demo",
|
||||
"coord@poona.demo",
|
||||
"bio@poona.demo",
|
||||
"mgmt@xyz.demo",
|
||||
"coord@xyz.demo",
|
||||
"bio@xyz.demo",
|
||||
):
|
||||
hdr = _auth_headers(client, email)
|
||||
for url in AI_GET_ENDPOINTS:
|
||||
@@ -77,7 +77,7 @@ def test_ai6_role_matrix_department_user_403_and_viewers_200(client):
|
||||
assert r_regen.status_code == 403, f"Expected 403 for {email} on regenerate"
|
||||
|
||||
# system_admin gets 200 on all GETs AND 200 on regenerate
|
||||
admin_hdr = _auth_headers(client, "admin@poona.demo")
|
||||
admin_hdr = _auth_headers(client, "admin@xyz.demo")
|
||||
for url in AI_GET_ENDPOINTS:
|
||||
r = client.get(url, headers=admin_hdr)
|
||||
assert r.status_code == 200, f"Expected 200 for admin on {url}: {r.text}"
|
||||
@@ -95,7 +95,7 @@ def test_ai6_role_matrix_department_user_403_and_viewers_200(client):
|
||||
|
||||
|
||||
def test_ai6_scoping_department_category_and_custom_period(client, db):
|
||||
mgmt_hdr = _auth_headers(client, "mgmt@poona.demo")
|
||||
mgmt_hdr = _auth_headers(client, "mgmt@xyz.demo")
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
cat = db.query(Category).first()
|
||||
assert icu is not None and cat is not None
|
||||
@@ -131,7 +131,7 @@ def test_ai6_scoping_department_category_and_custom_period(client, db):
|
||||
def test_ai6_default_none_provider_shapes_and_real_seeded_data(client, monkeypatch):
|
||||
from app.core.config import settings
|
||||
monkeypatch.setattr(settings, "AI_PROVIDER", "none")
|
||||
admin_hdr = _auth_headers(client, "admin@poona.demo")
|
||||
admin_hdr = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
status_res = client.get("/api/ai/status", headers=admin_hdr)
|
||||
assert status_res.status_code == 200
|
||||
@@ -169,7 +169,7 @@ def test_ai6_default_none_provider_shapes_and_real_seeded_data(client, monkeypat
|
||||
|
||||
|
||||
def test_ai6_exports_xlsx_three_sheets_and_csv(client):
|
||||
biomed_hdr = _auth_headers(client, "bio@poona.demo")
|
||||
biomed_hdr = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
for sec in AI_EXPORT_SECTIONS:
|
||||
r_xlsx = client.get(f"/api/ai/{sec}/export?format=xlsx&period=12m", headers=biomed_hdr)
|
||||
|
||||
@@ -33,10 +33,10 @@ def _make_xlsx_bytes(headers: list[str], rows: list[list[object]]) -> bytes:
|
||||
|
||||
|
||||
def test_import_template_download_and_rbac(client):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
for email in ("dept@poona.demo", "coord@poona.demo", "mgmt@poona.demo"):
|
||||
for email in ("dept@xyz.demo", "coord@xyz.demo", "mgmt@xyz.demo"):
|
||||
h = _auth_headers(client, email)
|
||||
assert client.get("/api/assets/import-template", headers=h).status_code == 403
|
||||
assert (
|
||||
@@ -66,7 +66,7 @@ def test_import_template_download_and_rbac(client):
|
||||
|
||||
|
||||
def test_bulk_import_dry_run_validation_and_commit(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
# Read a valid sample from template so we match real seeded department/location/category
|
||||
tmpl_res = client.get("/api/assets/import-template", headers=bio_headers)
|
||||
|
||||
@@ -59,8 +59,8 @@ def test_alert_state_and_coverage_status():
|
||||
|
||||
|
||||
def test_asset_crud_and_duplicate_code(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
loc = db.query(Location).filter(Location.department_id == icu.id).first()
|
||||
cat = db.query(Category).first()
|
||||
@@ -139,7 +139,7 @@ def test_asset_crud_and_duplicate_code(client, db):
|
||||
|
||||
|
||||
def test_department_user_scoping_on_assets(client, db):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
ot = db.query(Department).filter(Department.code == "OT").first()
|
||||
other_asset = db.query(Asset).filter(Asset.department_id == ot.id).first()
|
||||
@@ -164,7 +164,7 @@ def test_department_user_scoping_on_assets(client, db):
|
||||
|
||||
|
||||
def test_coordinator_field_level_patch_restrictions(client, db):
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
asset = db.query(Asset).first()
|
||||
|
||||
ok_patch = client.patch(
|
||||
@@ -195,9 +195,9 @@ def test_coordinator_field_level_patch_restrictions(client, db):
|
||||
def test_attachments_upload_download_delete_and_security(client, db, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(settings, "UPLOAD_DIR", str(tmp_path))
|
||||
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
ot = db.query(Department).filter(Department.code == "OT").first()
|
||||
|
||||
@@ -39,30 +39,30 @@ def _auth_headers(client, email: str, password: str = "Demo@123") -> dict[str, s
|
||||
|
||||
|
||||
def test_login_valid_and_invalid(client, db):
|
||||
res = client.post("/api/auth/login", json={"email": "admin@poona.demo", "password": "Demo@123"})
|
||||
res = client.post("/api/auth/login", json={"email": "admin@xyz.demo", "password": "Demo@123"})
|
||||
assert res.status_code == 200
|
||||
body = res.json()
|
||||
assert body["token_type"] == "bearer"
|
||||
assert body["access_token"]
|
||||
assert body["user"]["email"] == "admin@poona.demo"
|
||||
assert body["user"]["email"] == "admin@xyz.demo"
|
||||
assert body["user"]["role"] == "system_admin"
|
||||
assert body["user"]["demo_as_of_date"] is None
|
||||
|
||||
bad_pw = client.post("/api/auth/login", json={"email": "admin@poona.demo", "password": "wrong"})
|
||||
bad_pw = client.post("/api/auth/login", json={"email": "admin@xyz.demo", "password": "wrong"})
|
||||
assert bad_pw.status_code == 401
|
||||
|
||||
bad_email = client.post("/api/auth/login", json={"email": "nobody@poona.demo", "password": "Demo@123"})
|
||||
bad_email = client.post("/api/auth/login", json={"email": "nobody@xyz.demo", "password": "Demo@123"})
|
||||
assert bad_email.status_code == 401
|
||||
|
||||
# Inactive user rejected
|
||||
user = db.query(User).filter(User.email == "neha.chavan@poona.demo").first()
|
||||
user = db.query(User).filter(User.email == "neha.chavan@xyz.demo").first()
|
||||
assert user is not None
|
||||
user.is_active = False
|
||||
db.commit()
|
||||
try:
|
||||
res_inactive = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "neha.chavan@poona.demo", "password": "Demo@123"},
|
||||
json={"email": "neha.chavan@xyz.demo", "password": "Demo@123"},
|
||||
)
|
||||
assert res_inactive.status_code in (401, 403)
|
||||
finally:
|
||||
@@ -77,11 +77,11 @@ def test_auth_me(client):
|
||||
bad_tok = client.get("/api/auth/me", headers={"Authorization": "Bearer invalid.token.here"})
|
||||
assert bad_tok.status_code == 401
|
||||
|
||||
headers = _auth_headers(client, "dept@poona.demo")
|
||||
headers = _auth_headers(client, "dept@xyz.demo")
|
||||
me = client.get("/api/auth/me", headers=headers)
|
||||
assert me.status_code == 200
|
||||
data = me.json()
|
||||
assert data["email"] == "dept@poona.demo"
|
||||
assert data["email"] == "dept@xyz.demo"
|
||||
assert data["role"] == "department_user"
|
||||
assert data["department_name"] == "Intensive Care Unit"
|
||||
|
||||
@@ -89,16 +89,16 @@ def test_auth_me(client):
|
||||
@pytest.mark.parametrize(
|
||||
"email",
|
||||
[
|
||||
"bio@poona.demo",
|
||||
"dept@poona.demo",
|
||||
"mgmt@poona.demo",
|
||||
"coord@poona.demo",
|
||||
"bio@xyz.demo",
|
||||
"dept@xyz.demo",
|
||||
"mgmt@xyz.demo",
|
||||
"coord@xyz.demo",
|
||||
],
|
||||
)
|
||||
def test_non_admin_forbidden_on_admin_endpoints(client, db, email):
|
||||
headers = _auth_headers(client, email)
|
||||
dept = db.query(Department).first()
|
||||
target_user = db.query(User).filter(User.email == "dept@poona.demo").first()
|
||||
target_user = db.query(User).filter(User.email == "dept@xyz.demo").first()
|
||||
|
||||
# Masters GET is allowed for authenticated users
|
||||
assert client.get("/api/departments", headers=headers).status_code == 200
|
||||
@@ -134,7 +134,7 @@ def test_non_admin_forbidden_on_admin_endpoints(client, db, email):
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "Hack",
|
||||
"email": "hack@poona.demo",
|
||||
"email": "hack@xyz.demo",
|
||||
"password": "Password1",
|
||||
"role": "biomedical",
|
||||
},
|
||||
@@ -172,7 +172,7 @@ def test_non_admin_forbidden_on_admin_endpoints(client, db, email):
|
||||
|
||||
|
||||
def test_admin_masters_and_users_crud(client):
|
||||
headers = _auth_headers(client, "admin@poona.demo")
|
||||
headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
# Department create, patch, soft-delete
|
||||
r = client.post(
|
||||
@@ -201,7 +201,7 @@ def test_admin_masters_and_users_crud(client):
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "Temp Staff",
|
||||
"email": "temp.staff@poona.demo",
|
||||
"email": "temp.staff@xyz.demo",
|
||||
"password": "InitPassword1",
|
||||
"role": "biomedical",
|
||||
},
|
||||
@@ -218,7 +218,7 @@ def test_admin_masters_and_users_crud(client):
|
||||
assert u_patch.status_code == 200
|
||||
login_new = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "temp.staff@poona.demo", "password": "NewPassword2"},
|
||||
json={"email": "temp.staff@xyz.demo", "password": "NewPassword2"},
|
||||
)
|
||||
assert login_new.status_code == 200
|
||||
|
||||
@@ -280,7 +280,7 @@ def test_permissions_matrix_all_roles():
|
||||
|
||||
|
||||
def test_settings_validation_and_demo_date(client, db):
|
||||
headers = _auth_headers(client, "admin@poona.demo")
|
||||
headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
res = client.get("/api/settings", headers=headers)
|
||||
assert res.status_code == 200
|
||||
|
||||
@@ -32,7 +32,7 @@ def _make_xlsx_bytes(sheet_name: str, headers: list[str], rows: list[list[object
|
||||
|
||||
|
||||
def test_contracts_bulk_import_lifecycle(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
asset = db.query(Asset).filter(Asset.asset_code.isnot(None)).first()
|
||||
vendor = db.query(Vendor).filter(Vendor.is_active.is_(True)).first()
|
||||
@@ -119,7 +119,7 @@ def test_contracts_bulk_import_lifecycle(client, db):
|
||||
|
||||
|
||||
def test_calibration_bulk_import_lifecycle(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
# Find asset without calibration plan
|
||||
existing_plan_ids = [p.asset_id for p in db.query(CalibrationPlan.asset_id).all()]
|
||||
@@ -179,7 +179,7 @@ def test_calibration_bulk_import_lifecycle(client, db):
|
||||
|
||||
|
||||
def test_insurance_bulk_import_lifecycle(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
asset = db.query(Asset).filter(Asset.asset_code.isnot(None)).first()
|
||||
vendor = db.query(Vendor).filter(Vendor.is_active.is_(True)).first()
|
||||
|
||||
@@ -85,11 +85,11 @@ def test_clip_downtime_to_month_across_boundary():
|
||||
|
||||
|
||||
def test_complaint_field_level_permissions(client, db):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
ot = db.query(Department).filter(Department.code == "OT").first()
|
||||
@@ -181,16 +181,16 @@ def test_complaint_field_level_permissions(client, db):
|
||||
|
||||
|
||||
def test_full_complaint_workflow_and_asset_status_sync(client, db):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
asset = db.query(Asset).filter(Asset.department_id == icu.id, Asset.status == "in_service").first()
|
||||
assert asset is not None
|
||||
|
||||
bio1 = db.query(User).filter(User.email == "bio@poona.demo").first()
|
||||
bio2 = db.query(User).filter(User.email == "vikram.shinde@poona.demo").first()
|
||||
bio1 = db.query(User).filter(User.email == "bio@xyz.demo").first()
|
||||
bio2 = db.query(User).filter(User.email == "vikram.shinde@xyz.demo").first()
|
||||
|
||||
# 1. Dept user raises critical complaint -> asset becomes under_repair
|
||||
create_res = client.post(
|
||||
@@ -339,8 +339,8 @@ def test_require_closure_remarks_and_wired_settings(client, db):
|
||||
from datetime import date
|
||||
from app.services.calculations import compute_sla_status
|
||||
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
asset = db.query(Asset).first()
|
||||
assert asset is not None
|
||||
|
||||
@@ -419,7 +419,7 @@ def test_require_closure_remarks_and_wired_settings(client, db):
|
||||
|
||||
|
||||
def test_close_without_restore_sets_restored_at_and_reopen_recloses(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
asset = db.query(Asset).first()
|
||||
assert asset is not None
|
||||
|
||||
@@ -479,7 +479,7 @@ def test_sla_breach_alert_emitted_and_suppressed_when_restored(client, db):
|
||||
from app.models import Notification
|
||||
from app.services.alerts import run_alert_check
|
||||
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
asset = db.query(Asset).first()
|
||||
assert asset is not None
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def _auth_headers(client, email: str) -> dict[str, str]:
|
||||
|
||||
|
||||
def test_pm_record_attachment_upload_and_download(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
pm_rec = db.query(PMRecord).first()
|
||||
assert pm_rec is not None
|
||||
|
||||
@@ -52,7 +52,7 @@ def test_pm_record_attachment_upload_and_download(client, db):
|
||||
|
||||
|
||||
def test_complaint_assigned_team_and_location_filter(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
asset = db.query(Asset).filter(Asset.location_id.isnot(None)).first()
|
||||
assert asset is not None
|
||||
|
||||
@@ -92,7 +92,7 @@ def test_complaint_assigned_team_and_location_filter(client, db):
|
||||
|
||||
|
||||
def test_demo_equipment_serial_no(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept = db.query(Department).first()
|
||||
vendor = db.query(Vendor).first()
|
||||
today = effective_today(db)
|
||||
@@ -126,8 +126,8 @@ def test_demo_equipment_serial_no(client, db):
|
||||
|
||||
|
||||
def test_department_visit_new_requirements_and_monthly_report(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
dept = db.query(Department).first()
|
||||
today = effective_today(db)
|
||||
|
||||
@@ -161,7 +161,7 @@ def test_department_visit_new_requirements_and_monthly_report(client, db):
|
||||
|
||||
|
||||
def test_asset_calibration_and_insurance_filters(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
# Filter calibration applicable
|
||||
res_cal_yes = client.get("/api/assets?requires_calibration=true", headers=bio_headers)
|
||||
@@ -182,7 +182,7 @@ def test_asset_calibration_and_insurance_filters(client, db):
|
||||
|
||||
|
||||
def test_bulk_import_templates_endpoints(client):
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
|
||||
# Contracts template
|
||||
r_c = client.get("/api/contracts/import-template", headers=coord_headers)
|
||||
|
||||
@@ -3,5 +3,5 @@ def test_health_check(client):
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "ok"
|
||||
assert data["service"] == "Poona Hospital AMS"
|
||||
assert data["service"] == "XYZ Hospital AMS"
|
||||
assert data["version"] == "0.1.0"
|
||||
|
||||
@@ -33,11 +33,11 @@ def test_alert_check_dedupe_and_seed_notifications(db):
|
||||
|
||||
|
||||
def test_demo_clock_alert_run_and_admin_only_permission(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
|
||||
# Non-admins get 403 on POST /api/alerts/run
|
||||
for h in (bio_headers, dept_headers, mgmt_headers, coord_headers):
|
||||
@@ -74,9 +74,9 @@ def test_demo_clock_alert_run_and_admin_only_permission(client, db):
|
||||
|
||||
|
||||
def test_per_user_read_state_and_department_scoping(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
admin_list_before = client.get("/api/notifications?limit=100", headers=admin_headers).json()
|
||||
bio_list_before = client.get("/api/notifications?limit=100", headers=bio_headers).json()
|
||||
@@ -118,8 +118,8 @@ def test_per_user_read_state_and_department_scoping(client, db):
|
||||
|
||||
|
||||
def test_dashboard_summary_role_scoping_and_charts(client, db):
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
icu_asset_count = db.query(Asset).filter(Asset.department_id == icu.id).count()
|
||||
|
||||
@@ -28,9 +28,9 @@ def _make_png_bytes() -> bytes:
|
||||
|
||||
|
||||
def test_contract_create_renew_supersede_history_and_scoping(client, db):
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
ot = db.query(Department).filter(Department.code == "OT").first()
|
||||
@@ -136,9 +136,9 @@ def test_contract_create_renew_supersede_history_and_scoping(client, db):
|
||||
|
||||
|
||||
def test_warranty_and_insurance_expiry_and_permissions(client, db):
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
icu_asset = db.query(Asset).filter(Asset.department_id == icu.id).first()
|
||||
@@ -228,9 +228,9 @@ def test_warranty_and_insurance_expiry_and_permissions(client, db):
|
||||
|
||||
|
||||
def test_demo_equipment_overdue_detection_and_return(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
icu_loc = db.query(Location).filter(Location.department_id == icu.id).first()
|
||||
@@ -301,10 +301,10 @@ def test_demo_equipment_overdue_detection_and_return(client, db):
|
||||
|
||||
|
||||
def test_department_visits_permissions_and_multi_linking(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
|
||||
icu = db.query(Department).filter(Department.code == "ICU").first()
|
||||
icu_assets = db.query(Asset).filter(Asset.department_id == icu.id).limit(2).all()
|
||||
|
||||
@@ -19,10 +19,10 @@ def _auth_headers(client, email: str) -> dict[str, str]:
|
||||
|
||||
|
||||
def test_global_search_grouped_and_department_scoped(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
dept_user = db.query(User).filter(User.email == "dept@poona.demo").first()
|
||||
dept_user = db.query(User).filter(User.email == "dept@xyz.demo").first()
|
||||
icu_dept = db.query(Department).filter(Department.id == dept_user.department_id).first()
|
||||
assert dept_user is not None and icu_dept is not None
|
||||
|
||||
@@ -69,13 +69,13 @@ def test_global_search_grouped_and_department_scoped(client, db):
|
||||
|
||||
|
||||
def test_audit_logs_rbac_and_filters(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
for email in ("bio@poona.demo", "mgmt@poona.demo", "dept@poona.demo", "coord@poona.demo"):
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
for email in ("bio@xyz.demo", "mgmt@xyz.demo", "dept@xyz.demo", "coord@xyz.demo"):
|
||||
headers = _auth_headers(client, email)
|
||||
assert client.get("/api/audit-logs", headers=headers).status_code == 403
|
||||
|
||||
# Ensure there is at least one distinct AuditLog entry via API/DB
|
||||
admin_user = db.query(User).filter(User.email == "admin@poona.demo").first()
|
||||
admin_user = db.query(User).filter(User.email == "admin@xyz.demo").first()
|
||||
assert admin_user is not None
|
||||
log_entry = AuditLog(
|
||||
entity_type="asset",
|
||||
@@ -110,14 +110,14 @@ def test_login_rate_limiter_429_and_reset(client):
|
||||
for i in range(MAX_LOGIN_ATTEMPTS):
|
||||
res = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "ratelimit@poona.demo", "password": "WrongPassword"},
|
||||
json={"email": "ratelimit@xyz.demo", "password": "WrongPassword"},
|
||||
)
|
||||
assert res.status_code == 401, f"Attempt {i + 1} unexpected status {res.status_code}"
|
||||
|
||||
# Attempt 16 triggers 429 RATE_LIMITED
|
||||
blocked = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "ratelimit@poona.demo", "password": "WrongPassword"},
|
||||
json={"email": "ratelimit@xyz.demo", "password": "WrongPassword"},
|
||||
)
|
||||
assert blocked.status_code == 429
|
||||
assert blocked.json()["code"] == "RATE_LIMITED"
|
||||
@@ -126,7 +126,7 @@ def test_login_rate_limiter_429_and_reset(client):
|
||||
reset_login_rate_limiter()
|
||||
ok = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "admin@poona.demo", "password": "Demo@123"},
|
||||
json={"email": "admin@xyz.demo", "password": "Demo@123"},
|
||||
)
|
||||
assert ok.status_code == 200
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ def test_add_months_clamping_and_db_note_n2(db):
|
||||
|
||||
|
||||
def test_outsourced_pm_lifecycle_complete_and_reschedule(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
|
||||
provider = db.query(Vendor).filter(Vendor.vendor_type == "service_provider").first()
|
||||
contract = db.query(Contract).filter(Contract.is_superseded.is_(False)).first()
|
||||
@@ -200,9 +200,9 @@ def test_outsourced_pm_lifecycle_complete_and_reschedule(client, db):
|
||||
|
||||
|
||||
def test_calibration_plan_approval_permissions_and_completion(client, db):
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
|
||||
a1 = _create_test_asset(client, bio_headers, db, "001", req_cal=False)
|
||||
a2 = _create_test_asset(client, bio_headers, db, "002", req_cal=False)
|
||||
@@ -328,8 +328,8 @@ def test_calibration_plan_approval_permissions_and_completion(client, db):
|
||||
|
||||
|
||||
def test_demo_clock_transitions_statuses_dynamically_on_read(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
asset_id = _create_test_asset(client, bio_headers, db, "CLK", req_cal=True)
|
||||
agency = db.query(Vendor).filter(Vendor.vendor_type == "calibration_agency").first()
|
||||
|
||||
@@ -36,8 +36,8 @@ def _auth_headers(client, email: str) -> dict[str, str]:
|
||||
|
||||
|
||||
def test_all_eight_reports_accessible_for_management_and_admin(client):
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
for headers in (mgmt_headers, admin_headers):
|
||||
for key in ALL_REPORT_KEYS:
|
||||
@@ -56,9 +56,9 @@ def test_all_eight_reports_accessible_for_management_and_admin(client):
|
||||
|
||||
|
||||
def test_daily_visit_rbac_and_department_user_scoping(client, db):
|
||||
dept_headers = _auth_headers(client, "dept@poona.demo")
|
||||
coord_headers = _auth_headers(client, "coord@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
dept_headers = _auth_headers(client, "dept@xyz.demo")
|
||||
coord_headers = _auth_headers(client, "coord@xyz.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
# daily-visit is forbidden for department_user and coordinator (JSON + export)
|
||||
for headers in (dept_headers, coord_headers):
|
||||
@@ -69,7 +69,7 @@ def test_daily_visit_rbac_and_department_user_scoping(client, db):
|
||||
assert client.get("/api/reports/daily-visit", headers=bio_headers).status_code == 200
|
||||
|
||||
# Department user attempting to pass another department_id is still scoped to own department
|
||||
dept_user = db.query(User).filter(User.email == "dept@poona.demo").first()
|
||||
dept_user = db.query(User).filter(User.email == "dept@xyz.demo").first()
|
||||
other_dept = db.query(Department).filter(Department.id != dept_user.department_id).first()
|
||||
assert dept_user is not None and dept_user.department_id is not None
|
||||
assert other_dept is not None
|
||||
@@ -93,8 +93,8 @@ def test_daily_visit_rbac_and_department_user_scoping(client, db):
|
||||
|
||||
|
||||
def test_monthly_maintenance_three_complaint_reconciliation(client, db):
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_user = db.query(User).filter(User.email == "admin@poona.demo").first()
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
admin_user = db.query(User).filter(User.email == "admin@xyz.demo").first()
|
||||
category = db.query(Category).first()
|
||||
location = db.query(Location).first()
|
||||
assert admin_user is not None and category is not None and location is not None
|
||||
@@ -198,7 +198,7 @@ def test_monthly_maintenance_three_complaint_reconciliation(client, db):
|
||||
|
||||
|
||||
def test_report_exports_xlsx_and_csv(client):
|
||||
mgmt_headers = _auth_headers(client, "mgmt@poona.demo")
|
||||
mgmt_headers = _auth_headers(client, "mgmt@xyz.demo")
|
||||
|
||||
# Excel export
|
||||
xlsx_res = client.get(
|
||||
@@ -211,7 +211,7 @@ def test_report_exports_xlsx_and_csv(client):
|
||||
|
||||
wb = openpyxl.load_workbook(BytesIO(xlsx_res.content))
|
||||
ws = wb.active
|
||||
assert "Poona Hospital" in str(ws["A1"].value)
|
||||
assert "XYZ Hospital" in str(ws["A1"].value)
|
||||
assert "Generated:" in str(ws["A2"].value)
|
||||
assert "Filters:" in str(ws["A2"].value)
|
||||
assert "Total Downtime Minutes: 525" in str(ws["A3"].value)
|
||||
@@ -233,7 +233,7 @@ def test_report_exports_xlsx_and_csv(client):
|
||||
decoded = csv_res.content.decode("utf-8-sig")
|
||||
parsed = list(csv.reader(StringIO(decoded)))
|
||||
assert len(parsed) >= 5
|
||||
assert "Poona Hospital" in parsed[0][0]
|
||||
assert "XYZ Hospital" in parsed[0][0]
|
||||
assert parsed[4][0] == "Complaint No"
|
||||
|
||||
# Unsupported export format rejected
|
||||
@@ -246,7 +246,7 @@ def test_report_exports_xlsx_and_csv(client):
|
||||
|
||||
def test_all_eight_reports_export_xlsx_and_csv(client):
|
||||
"""Verify that all 8 reports export cleanly as both XLSX and CSV without title/slash errors."""
|
||||
admin_headers = _auth_headers(client, "admin@poona.demo")
|
||||
admin_headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
for key in ALL_REPORT_KEYS:
|
||||
# Test XLSX export
|
||||
|
||||
@@ -14,7 +14,7 @@ def seeded_task1_db(db, tmp_path_factory):
|
||||
return upload_dir
|
||||
|
||||
|
||||
def _auth_headers(client, email: str = "admin@poona.demo") -> dict[str, str]:
|
||||
def _auth_headers(client, email: str = "admin@xyz.demo") -> dict[str, str]:
|
||||
res = client.post("/api/auth/login", json={"email": email, "password": "Demo@123"})
|
||||
assert res.status_code == 200, res.text
|
||||
return {"Authorization": f"Bearer {res.json()['access_token']}"}
|
||||
|
||||
@@ -12,7 +12,7 @@ def seeded_task2_db(db, tmp_path_factory):
|
||||
return upload_dir
|
||||
|
||||
|
||||
def _auth_headers(client, email: str = "admin@poona.demo") -> dict[str, str]:
|
||||
def _auth_headers(client, email: str = "admin@xyz.demo") -> dict[str, str]:
|
||||
res = client.post("/api/auth/login", json={"email": email, "password": "Demo@123"})
|
||||
assert res.status_code == 200, res.text
|
||||
return {"Authorization": f"Bearer {res.json()['access_token']}"}
|
||||
|
||||
@@ -12,7 +12,7 @@ def seeded_task4_db(db, tmp_path_factory):
|
||||
return upload_dir
|
||||
|
||||
|
||||
def _auth_headers(client, email: str = "admin@poona.demo") -> dict[str, str]:
|
||||
def _auth_headers(client, email: str = "admin@xyz.demo") -> dict[str, str]:
|
||||
res = client.post("/api/auth/login", json={"email": email, "password": "Demo@123"})
|
||||
assert res.status_code == 200, res.text
|
||||
return {"Authorization": f"Bearer {res.json()['access_token']}"}
|
||||
@@ -50,20 +50,20 @@ def test_validate_password_unit():
|
||||
assert "easily guessable" in str(exc5.value) or "at least 8" in str(exc5.value) or "at least one" in str(exc5.value)
|
||||
|
||||
# 6. Demo password MUST be allowed
|
||||
validate_password("demo@123", email="admin@poona.demo")
|
||||
validate_password("Demo@123", email="admin@poona.demo")
|
||||
validate_password("demo@123", email="admin@xyz.demo")
|
||||
validate_password("Demo@123", email="admin@xyz.demo")
|
||||
|
||||
# 7. Contains email local part (>= 4 chars)
|
||||
with pytest.raises(Exception) as exc7:
|
||||
validate_password("Secureadmin123", email="admin@poona.demo")
|
||||
validate_password("Secureadmin123", email="admin@xyz.demo")
|
||||
assert "username" in str(exc7.value).lower()
|
||||
|
||||
# Short local part (< 4 chars) does NOT trigger username check
|
||||
validate_password("Securebio123", email="bio@poona.demo")
|
||||
validate_password("Securebio123", email="bio@xyz.demo")
|
||||
|
||||
|
||||
def test_api_create_user_password_validation(client, db):
|
||||
headers = _auth_headers(client, "admin@poona.demo")
|
||||
headers = _auth_headers(client, "admin@xyz.demo")
|
||||
|
||||
# Rejected: no digit
|
||||
res_bad = client.post(
|
||||
@@ -71,7 +71,7 @@ def test_api_create_user_password_validation(client, db):
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "Test User",
|
||||
"email": "test_pw_rule@poona.demo",
|
||||
"email": "test_pw_rule@xyz.demo",
|
||||
"password": "NoDigitsPassword",
|
||||
"role": "biomedical",
|
||||
},
|
||||
@@ -85,7 +85,7 @@ def test_api_create_user_password_validation(client, db):
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "Test User 2",
|
||||
"email": "tester123@poona.demo",
|
||||
"email": "tester123@xyz.demo",
|
||||
"password": "tester123Password1",
|
||||
"role": "biomedical",
|
||||
},
|
||||
@@ -99,7 +99,7 @@ def test_api_create_user_password_validation(client, db):
|
||||
headers=headers,
|
||||
json={
|
||||
"name": "Test User 3",
|
||||
"email": "validuser@poona.demo",
|
||||
"email": "validuser@xyz.demo",
|
||||
"password": "ValidPassword123",
|
||||
"role": "biomedical",
|
||||
},
|
||||
@@ -127,7 +127,7 @@ def test_api_create_user_password_validation(client, db):
|
||||
|
||||
def test_api_change_password_validation(client, db):
|
||||
# Log in as bio user
|
||||
bio_headers = _auth_headers(client, "bio@poona.demo")
|
||||
bio_headers = _auth_headers(client, "bio@xyz.demo")
|
||||
|
||||
# Reject new == current
|
||||
res_same = client.post(
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_resolve_department_scope_rules():
|
||||
|
||||
def test_unassigned_department_user_sees_zero_records(client, db):
|
||||
# Create a department_user with department_id = None
|
||||
email = "unassigned_dept_user@poona.demo"
|
||||
email = "unassigned_dept_user@xyz.demo"
|
||||
user = db.query(User).filter(User.email == email).first()
|
||||
if not user:
|
||||
user = User(
|
||||
@@ -102,7 +102,7 @@ def test_assigned_department_user_scoping_ignores_query_param(client, db):
|
||||
assert len(depts) >= 2
|
||||
dept1, dept2 = depts[0], depts[1]
|
||||
|
||||
email = "dept1_scoped_user@poona.demo"
|
||||
email = "dept1_scoped_user@xyz.demo"
|
||||
user = db.query(User).filter(User.email == email).first()
|
||||
if not user:
|
||||
user = User(
|
||||
|
||||
@@ -12,7 +12,7 @@ def seeded_task7_db(db, tmp_path_factory):
|
||||
|
||||
def test_token_invalidation_on_change_password_and_admin_reset(client, db):
|
||||
# 1. Login as user and save the initial token
|
||||
user_email = "bio@poona.demo"
|
||||
user_email = "bio@xyz.demo"
|
||||
login_res = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": user_email, "password": "Demo@123"},
|
||||
@@ -59,7 +59,7 @@ def test_token_invalidation_on_change_password_and_admin_reset(client, db):
|
||||
# 5. Login as admin, reset that user's password
|
||||
admin_login = client.post(
|
||||
"/api/auth/login",
|
||||
json={"email": "admin@poona.demo", "password": "Demo@123"},
|
||||
json={"email": "admin@xyz.demo", "password": "Demo@123"},
|
||||
)
|
||||
assert admin_login.status_code == 200
|
||||
admin_token = admin_login.json()["access_token"]
|
||||
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
def test_package_target_creates_clean_delivery_zip(tmp_path):
|
||||
repo_root = Path(__file__).resolve().parent.parent.parent
|
||||
zip_path = tmp_path / "poona-ams-delivery.zip"
|
||||
zip_path = tmp_path / "xyz-ams-delivery.zip"
|
||||
|
||||
# Run git archive command (matching Makefile package target)
|
||||
cmd = ["git", "archive", "--format=zip", f"--output={zip_path}", "HEAD"]
|
||||
|
||||
Reference in New Issue
Block a user