Coverage for an_website/ping/ping.py: 100.000%

11 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-10 18:56 +0000

1# This program is free software: you can redistribute it and/or modify 

2# it under the terms of the GNU Affero General Public License as 

3# published by the Free Software Foundation, either version 3 of the 

4# License, or (at your option) any later version. 

5# 

6# This program is distributed in the hope that it will be useful, 

7# but WITHOUT ANY WARRANTY; without even the implied warranty of 

8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

9# GNU Affero General Public License for more details. 

10# 

11# You should have received a copy of the GNU Affero General Public License 

12# along with this program. If not, see <https://www.gnu.org/licenses/>. 

13 

14"""The ping API of the website.""" 

15 

16from typing import ClassVar 

17 

18from ..utils.request_handler import APIRequestHandler 

19from ..utils.utils import ModuleInfo 

20 

21 

22def get_module_info() -> ModuleInfo: 

23 """Create and return the ModuleInfo for this module.""" 

24 return ModuleInfo( 

25 handlers=((r"/api/ping", PingPong),), 

26 name="Ping Pong", 

27 description="🏓", 

28 path="/api/ping", 

29 hidden=True, 

30 ) 

31 

32 

33class PingPong(APIRequestHandler): 

34 """The request handler for the ping API.""" 

35 

36 POSSIBLE_CONTENT_TYPES: ClassVar[tuple[str, ...]] = ( 

37 "text/plain", 

38 *APIRequestHandler.POSSIBLE_CONTENT_TYPES, 

39 ) 

40 

41 async def get(self, *, head: bool = False) -> None: 

42 """Handle GET requests to the ping API.""" 

43 # pylint: disable=unused-argument 

44 if self.content_type == "text/plain": 

45 await self.finish("🏓") 

46 else: 

47 await self.finish({"success": True})