Coverage for tests / store / tests_publisher.py: 100%
45 statements
« prev ^ index » next coverage.py v7.13.1, created at 2025-12-29 22:06 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2025-12-29 22:06 +0000
1import responses
2from urllib.parse import urlencode
3from flask_testing import TestCase
4from webapp.app import create_app
6JETBRAINS_FIND_RESPONSE = {
7 "results": [
8 {
9 "name": "pycharm-community",
10 "snap": {
11 "media": [
12 {
13 "height": 400,
14 "type": "icon",
15 "url": (
16 "https://dashboard.snapcraft.io/site_media/"
17 "appmedia/2024/06/Avatar-7.png"
18 ),
19 "width": 400,
20 },
21 {
22 "height": 2095,
23 "type": "screenshot",
24 "url": (
25 "https://dashboard.snapcraft.io/site_media/"
26 "appmedia/2017/12/pycharm_com_general.png"
27 ),
28 "width": 3713,
29 },
30 ],
31 "publisher": {
32 "display-name": "jetbrains",
33 "id": "28zEonXNoBLvIB7xneRbltOsp0Nf7DwS",
34 "username": "jetbrains",
35 "validation": "verified",
36 },
37 "summary": "PyCharm Community Edition",
38 "title": "pycharm-community",
39 },
40 "snap-id": "Qo9GiW9eyzgN1tXmWpQ9gdstdFsj4K7E",
41 },
42 ]
43}
45LUKEWH_FIND_RESPONSE = {
46 "results": [
47 {
48 "name": "deluge-lukewh",
49 "snap": {
50 "media": [
51 {
52 "height": 300,
53 "type": "icon",
54 "url": (
55 "https://dashboard.snapcraft.io/site_media/"
56 "appmedia/2020/04/the-new-deluge-icon-300x300.png"
57 ),
58 "width": 300,
59 },
60 {
61 "height": 720,
62 "type": "banner",
63 "url": (
64 "https://dashboard.snapcraft.io/site_media/"
65 "appmedia/2020/05/deluge-banner1.png"
66 ),
67 "width": 2160,
68 },
69 ],
70 "publisher": {
71 "display-name": "LukeWH",
72 "id": "GMrEEEdGN4gN9BhRHjRRDCoJuUkyJJnm",
73 "username": "lukewh",
74 "validation": "unproven",
75 },
76 "summary": (
77 "Deluge is a fully-featured cross-platform "
78 "BitTorrent client"
79 ),
80 "title": "Deluge",
81 },
82 "snap-id": "5dm2RBhIIGdr8sAnA9WJZWco2MQgbni7",
83 },
84 ]
85}
88class GetPublisherPageTest(TestCase):
89 def setUp(self):
90 self.api_url_publisher_items = "".join(
91 [
92 "https://api.snapcraft.io/api/v1/",
93 "snaps/search",
94 "?",
95 urlencode(
96 {
97 "q": "publisher:28zEonXNoBLvIB7xneRbltOsp0Nf7DwS",
98 "size": "500",
99 "page": "1",
100 "scope": "wide",
101 "confinement": "strict,classic",
102 "fields": ",".join(
103 [
104 "package_name",
105 "title",
106 "summary",
107 "architecture",
108 "media",
109 "developer_name",
110 "developer_id",
111 "developer_validation",
112 "origin",
113 "apps",
114 "sections",
115 ]
116 ),
117 "arch": "wide",
118 }
119 ),
120 ]
121 )
122 self.api_url_find = lambda publisher: "".join(
123 [
124 "https://api.snapcraft.io/v2/",
125 "snaps/find",
126 "?",
127 urlencode(
128 {
129 "publisher": publisher,
130 "fields": ",".join(
131 [
132 "title",
133 "summary",
134 "media",
135 "publisher",
136 ]
137 ),
138 }
139 ),
140 ]
141 )
143 def create_app(self):
144 app = create_app(testing=True)
145 app.secret_key = "secret_key"
146 app.config["WTF_CSRF_METHODS"] = []
148 return app
150 @responses.activate
151 def test_community_publisher(self):
152 responses.add(
153 responses.GET,
154 self.api_url_find("lukewh"),
155 json=LUKEWH_FIND_RESPONSE,
156 status=200,
157 )
158 response = self.client.get("/publisher/lukewh")
159 self.assertEqual(response.status_code, 200)
160 self.assert_template_used("store/community-publisher-details.html")
162 @responses.activate
163 def test_existant_publisher(self):
164 responses.add(
165 responses.GET,
166 self.api_url_find("jetbrains"),
167 json=JETBRAINS_FIND_RESPONSE,
168 status=200,
169 )
170 response = self.client.get("/publisher/jetbrains")
171 self.assertEqual(response.status_code, 200)
172 self.assert_template_used("store/publisher-details.html")
174 @responses.activate
175 def test_non_existant_publisher(self):
176 responses.add(
177 responses.GET,
178 self.api_url_find("toto"),
179 json={"results": []},
180 status=200,
181 )
182 response = self.client.get("/publisher/toto")
183 self.assertEqual(response.status_code, 200)
184 self.assert_template_used("store/community-publisher-details.html")
186 @responses.activate
187 def test_api_error(self):
188 responses.add(
189 responses.GET, self.api_url_find("jetbrains"), json={}, status=504
190 )
191 response = self.client.get("/publisher/jetbrains")
192 self.assertEqual(response.status_code, 200)
193 self.assert_template_used("store/publisher-details.html")
195 @responses.activate
196 def test_no_snaps_from_api(self):
197 responses.add(
198 responses.GET,
199 self.api_url_find("jetbrains"),
200 json={"results": []},
201 status=200,
202 )
203 response = self.client.get("/publisher/jetbrains")
204 self.assertEqual(response.status_code, 200)
205 self.assert_template_used("store/publisher-details.html")