Coverage for webapp/packages/store_packages.py: 61%
28 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
1from webapp.decorators import login_required
2from flask import (
3 Blueprint,
4 jsonify,
5 request,
6 session,
7 make_response,
8)
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
19store_packages = Blueprint(
20 "package",
21 __name__,
22)
25@trace_function
26@store_packages.route("/store.json")
27def get_store_packages():
28 args = dict(request.args)
29 extra_fields = [f for f in args.pop("extra_fields", "").split(",") if f]
30 res = jsonify(
31 get_packages(
32 FIELDS + extra_fields,
33 args,
34 12,
35 )
36 )
37 return res
40@trace_function
41@store_packages.route("/<any(charms, bundles):package_type>")
42@login_required
43def package(package_type):
44 """
45 Retrieves and returns package information based on the current app
46 and package type.
48 :returns: Response: The HTTP response containing the JSON data of the
49 packages.
50 """
52 publisher_packages = publisher_gateway.get_account_packages(
53 session["account-auth"], "charm", include_collaborations=True
54 )
55 page_type = request.path[1:-1]
57 response = jsonify(
58 {
59 "published_packages": [
60 package
61 for package in publisher_packages
62 if package["status"] == "published"
63 and package["type"] == page_type
64 ],
65 "registered_packages": [
66 package
67 for package in publisher_packages
68 if package["status"] == "registered"
69 and package["type"] == page_type
70 ],
71 "page_type": page_type,
72 }
73 )
74 return response
77@trace_function
78@store_packages.route("/<package_name>/card.json")
79def get_store_package(package_name):
80 has_libraries = bool(request.args.get("fields", ""))
82 res = make_response(
83 get_package(
84 package_name,
85 FIELDS,
86 has_libraries,
87 )
88 )
89 return res