Coverage for backend / app / routers / others.py: 69%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-17 21:34 +0000

1"""Router for miscellaneous endpoints like currencies and countries.""" 

2 

3from fastapi import APIRouter, Depends 

4from fastapi.responses import JSONResponse 

5 

6from app import models, database 

7from app.config import settings 

8from app.core.models import get_setting_value 

9from app.job_email_scraping.email_parsers import PLATFORM_SENDER_EMAILS 

10from app.resources import COUNTRIES, CURRENCIES 

11 

12other_router = APIRouter(prefix="/others", tags=["others"]) 

13 

14 

15@other_router.get("/currencies/", response_class=JSONResponse) 

16def get_currencies() -> list[dict]: 

17 """Get the list of currencies.""" 

18 

19 return CURRENCIES 

20 

21 

22@other_router.get("/countries/", response_class=JSONResponse) 

23def get_countries() -> list[dict]: 

24 """Get the list of countries.""" 

25 

26 return COUNTRIES 

27 

28 

29config_router = APIRouter(prefix="/config", tags=["config"]) 

30 

31 

32def get_demo_credentials(db) -> str: 

33 """Get the demo user for testing purposes.""" 

34 

35 user = db.query(models.User).filter(models.User.is_demo).first() 

36 if not user: 

37 raise AssertionError("No demo user found in database.") 

38 return user.email 

39 

40 

41@config_router.get("/") 

42def get_config( 

43 db=Depends(database.get_db), 

44) -> dict: 

45 """Get the application configuration.""" 

46 

47 return { 

48 "scraper_email": settings.scraper_email_username, 

49 "support_email": settings.support_email, 

50 "platform_sender_emails": {value: key for key, value in PLATFORM_SENDER_EMAILS.items()}, 

51 "min_password_length": settings.min_password_length, 

52 "app_demo_username": get_demo_credentials(db), 

53 "scrape_max_retry": settings.scrape_max_retry, 

54 } 

55 

56 

57@config_router.get("/status") 

58def get_status(db=Depends(database.get_db)) -> dict: 

59 """Get dynamic application status (polled by frontend).""" 

60 

61 return { 

62 "maintenance_scheduled_at": get_setting_value(db, "maintenance_scheduled_at", None), 

63 "test_mode": settings.test_mode, 

64 }