Coverage for waveqc/routes.py: 0%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-15 08:47 +0000

1import json 

2 

3from pyramid.config import Configurator 

4from pyramid.static import ManifestCacheBuster as _ManifestCacheBuster 

5 

6from .config import settings 

7 

8 

9class ManifestCacheBuster(_ManifestCacheBuster): 

10 def parse_manifest(self, content: bytes) -> dict[str, str]: 

11 # we remove unwanted slashs at the beggining of 

12 # each cache-busted version of the path 

13 manifest = json.loads(content.decode("utf-8")) 

14 return {key: value[1:] for key, value in manifest.items()} 

15 

16 

17def includeme(config: Configurator) -> None: 

18 config.add_route("homepage", "/") 

19 config.add_route("healthcheck", "/healthcheck/") 

20 config.add_route("station_detail", "/stations/{id}/") 

21 config.add_route("channel_detail", "/channels/") 

22 config.add_route("channel_full_detail", "/channels/full/") 

23 config.add_route("network_list", "/networks/") 

24 config.add_route("network_detail", "/networks/{code}/") 

25 config.add_route("network_full_detail", "/networks/{code}/full/") 

26 config.add_route("network_summary", "/networks/{code}/summary/") 

27 config.add_route("operator_list", "/operators/") 

28 config.add_route("operator_detail", "/operators/{id}/") 

29 config.add_route("operator_full_detail", "/operators/{id}/full/") 

30 config.add_static_view(name="static", path="waveqc:static") 

31 config.add_cache_buster( 

32 "waveqc:static", 

33 ManifestCacheBuster( 

34 "waveqc:static/parcel-manifest.json", reload=settings.DEBUG 

35 ), 

36 )