Coverage for src\zapy\api\v1\api_server.py: 100%

1 import sys

2 import platform

3 import os

4

5 from pydantic import BaseModel

6 from fastapi import APIRouter, Request

7

8 from datetime import datetime

9

10 from zapy.__init__ import __version__

11

12

13 api_server_v1 = APIRouter(tags=["v1"])

14

15

16 class InfoModel(BaseModel):

17 key: str

18 application: str

19 version: str

20 current_time: datetime

21 start_time: datetime

22 running_time: int

23 virtualEnv: bool

24 sys_prefix: str

25 python_version: str

26 documentation: str

27 directory: str

28

29

30@api_server_v1.get("/info")

31 async def server_info(request: Request) -> InfoModel:

32 application_start_time: datetime = request.app.state.application_start_time

33 return InfoModel(

34 key="zapy",

35 application="Zapy",

36 version=__version__,

37 current_time=datetime.now().isoformat(),

38 start_time=application_start_time.isoformat(),

39 running_time=(datetime.now() - application_start_time).seconds,

40 virtualEnv=sys.prefix != sys.base_prefix,

41 sys_prefix=sys.prefix,

42 python_version=platform.python_version(),

43 documentation="https://docs.zapy.dev",

44 directory=os.path.abspath(os.curdir),

45 )