Coverage for webapp/packages/store_packages.py: 61%

28 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-27 22:07 +0000

1from webapp.decorators import login_required 

2from flask import ( 

3 Blueprint, 

4 jsonify, 

5 request, 

6 session, 

7 make_response, 

8) 

9 

10from webapp.packages.logic import ( 

11 get_packages, 

12 get_package, 

13) 

14from webapp.config import SEARCH_FIELDS as FIELDS 

15from webapp.observability.utils import trace_function 

16from webapp.store_api import publisher_gateway 

17 

18 

19store_packages = Blueprint( 

20 "package", 

21 __name__, 

22) 

23 

24 

25@trace_function 

26@store_packages.route("/store.json") 

27def get_store_packages(): 

28 args = dict(request.args) 

29 libraries = bool(args.pop("fields", "")) 

30 res = make_response( 

31 get_packages( 

32 libraries, 

33 FIELDS, 

34 12, 

35 args, 

36 ) 

37 ) 

38 return res 

39 

40 

41@trace_function 

42@store_packages.route("/<any(charms, bundles):package_type>") 

43@login_required 

44def package(package_type): 

45 """ 

46 Retrieves and returns package information based on the current app 

47 and package type. 

48 

49 :returns: Response: The HTTP response containing the JSON data of the 

50 packages. 

51 """ 

52 

53 publisher_packages = publisher_gateway.get_account_packages( 

54 session["account-auth"], "charm", include_collaborations=True 

55 ) 

56 page_type = request.path[1:-1] 

57 

58 response = jsonify( 

59 { 

60 "published_packages": [ 

61 package 

62 for package in publisher_packages 

63 if package["status"] == "published" 

64 and package["type"] == page_type 

65 ], 

66 "registered_packages": [ 

67 package 

68 for package in publisher_packages 

69 if package["status"] == "registered" 

70 and package["type"] == page_type 

71 ], 

72 "page_type": page_type, 

73 } 

74 ) 

75 return response 

76 

77 

78@trace_function 

79@store_packages.route("/<package_name>/card.json") 

80def get_store_package(package_name): 

81 has_libraries = bool(request.args.get("fields", "")) 

82 

83 res = make_response( 

84 get_package( 

85 package_name, 

86 FIELDS, 

87 has_libraries, 

88 ) 

89 ) 

90 return res