Coverage for tests/publisher/snaps/tests_listing.py: 100%
82 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-20 22:09 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-20 22:09 +0000
1import responses
2from tests.publisher.endpoint_testing import BaseTestCases
5class ListingPageNotAuth(BaseTestCases.EndpointLoggedOut):
6 def setUp(self):
7 snap_name = "test-snap"
8 endpoint_url = "/api/{}/listing".format(snap_name)
10 super().setUp(snap_name=snap_name, endpoint_url=endpoint_url)
13class GetListingPage(BaseTestCases.EndpointLoggedInErrorHandling):
14 def setUp(self):
15 snap_name = "test-snap"
17 api_url = "https://dashboard.snapcraft.io/dev/api/snaps/info/{}"
18 api_url = api_url.format(snap_name)
19 endpoint_url = "/api/{}/listing".format(snap_name)
21 super().setUp(
22 snap_name=snap_name,
23 endpoint_url=endpoint_url,
24 method_endpoint="GET",
25 api_url=api_url,
26 method_api="GET",
27 )
29 @responses.activate
30 def test_icons_listing_uses_publisher_route(self):
31 snap_name = "icons"
32 api_url = "https://dashboard.snapcraft.io/dev/api/snaps/info/{}"
33 api_url = api_url.format(snap_name)
34 payload = {
35 "snap_id": "id",
36 "snap_name": snap_name,
37 "links": {"website": []},
38 }
40 responses.add(responses.GET, api_url, json=payload, status=200)
42 response = self.client.get("/icons/listing")
44 self.assertEqual(response.status_code, 200)
45 self.assert_template_used("store/publisher.html")
47 @responses.activate
48 def test_page_not_found(self):
49 payload = {"error_list": []}
50 responses.add(responses.GET, self.api_url, json=payload, status=404)
52 response = self.client.get(self.endpoint_url)
54 self.check_call_by_api_url(responses.calls)
56 assert response.status_code == 404
57 self.assert_template_used("404.html")
59 @responses.activate
60 def test_account_logged_in(self):
61 snap_name = "test-snap"
63 payload = {
64 "snap_id": "id",
65 "snap_name": snap_name,
66 "title": "Snap title",
67 "summary": "This is a summary",
68 "description": "This is a description",
69 "media": [],
70 "publisher": {"display-name": "The publisher", "username": "toto"},
71 "private": True,
72 "channel_maps_list": [{"map": [{"info": "info"}]}],
73 "contact": "contact adress",
74 "website": "website_url",
75 "public_metrics_enabled": True,
76 "public_metrics_blacklist": False,
77 "license": "License",
78 "video_urls": [],
79 "categories": {"items": []},
80 "status": "published",
81 "update_metadata_on_release": True,
82 "links": {"website": ["https://example.com"]},
83 }
85 responses.add(responses.GET, self.api_url, json=payload, status=200)
86 responses.add(
87 responses.GET,
88 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
89 json=[],
90 status=200,
91 )
93 endpoint = "?".join([self.endpoint_url, "from=test"])
95 response = self.client.get(endpoint)
97 self.check_call_by_api_url(responses.calls)
99 assert response.status_code == 200
101 @responses.activate
102 def test_icon(self):
103 payload = {
104 "snap_id": "id",
105 "snap_name": self.snap_name,
106 "title": "Snap title",
107 "summary": "This is a summary",
108 "description": "This is a description",
109 "media": [{"url": "this is a url", "type": "icon"}],
110 "publisher": {"display-name": "The publisher", "username": "toto"},
111 "private": True,
112 "channel_maps_list": [{"map": [{"info": "info"}]}],
113 "contact": "contact adress",
114 "website": "website_url",
115 "public_metrics_enabled": True,
116 "public_metrics_blacklist": True,
117 "license": "license",
118 "video_urls": [],
119 "categories": {"items": []},
120 "status": "published",
121 "update_metadata_on_release": True,
122 "links": {"website": ["https://example.com"]},
123 }
125 responses.add(responses.GET, self.api_url, json=payload, status=200)
126 responses.add(
127 responses.GET,
128 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
129 json=[],
130 status=200,
131 )
133 response = self.client.get(self.endpoint_url)
135 self.check_call_by_api_url(responses.calls)
137 assert response.status_code == 200
139 @responses.activate
140 def test_screenshots(self):
141 payload = {
142 "snap_id": "id",
143 "snap_name": self.snap_name,
144 "title": "Snap title",
145 "summary": "This is a summary",
146 "description": "This is a description",
147 "media": [{"url": "this is a url", "type": "screenshot"}],
148 "publisher": {"display-name": "The publisher", "username": "toto"},
149 "private": True,
150 "channel_maps_list": [{"map": [{"info": "info"}]}],
151 "contact": "contact adress",
152 "website": "website_url",
153 "public_metrics_enabled": True,
154 "public_metrics_blacklist": True,
155 "license": "license",
156 "video_urls": [],
157 "categories": {"items": []},
158 "status": "published",
159 "update_metadata_on_release": True,
160 "links": {"website": ["https://example.com"]},
161 }
163 responses.add(responses.GET, self.api_url, json=payload, status=200)
164 responses.add(
165 responses.GET,
166 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
167 json=[],
168 status=200,
169 )
171 response = self.client.get(self.endpoint_url)
173 self.check_call_by_api_url(responses.calls)
175 assert response.status_code == 200
177 @responses.activate
178 def test_banner_images(self):
179 payload = {
180 "snap_id": "id",
181 "snap_name": self.snap_name,
182 "title": "Snap title",
183 "summary": "This is a summary",
184 "description": "This is a description",
185 "media": [
186 {"url": "/banner_1234.png", "type": "banner"},
187 {"url": "/test.jpg", "type": "screenshot"},
188 {"url": "/banner-icon_4321.jpg", "type": "screenshot"},
189 {"url": "/banner-test.png", "type": "screenshot"},
190 {"url": "/banner-icon", "type": "screenshot"},
191 ],
192 "publisher": {"display-name": "The publisher", "username": "toto"},
193 "private": True,
194 "channel_maps_list": [{"map": [{"info": "info"}]}],
195 "contact": "contact adress",
196 "website": "website_url",
197 "public_metrics_enabled": True,
198 "public_metrics_blacklist": True,
199 "license": "license",
200 "video_urls": [],
201 "categories": {"items": []},
202 "status": "published",
203 "update_metadata_on_release": True,
204 "links": {"website": ["https://example.com"]},
205 }
207 responses.add(responses.GET, self.api_url, json=payload, status=200)
208 responses.add(
209 responses.GET,
210 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
211 json=[],
212 status=200,
213 )
215 response = self.client.get(self.endpoint_url)
217 self.check_call_by_api_url(responses.calls)
219 assert response.status_code == 200
221 @responses.activate
222 def test_videos(self):
223 payload = {
224 "snap_id": "id",
225 "snap_name": self.snap_name,
226 "title": "Snap title",
227 "summary": "This is a summary",
228 "description": "This is a description",
229 "media": [],
230 "publisher": {"display-name": "The publisher", "username": "toto"},
231 "private": True,
232 "channel_maps_list": [{"map": [{"info": "info"}]}],
233 "contact": "contact adress",
234 "website": "website_url",
235 "public_metrics_enabled": True,
236 "public_metrics_blacklist": True,
237 "license": "license",
238 "video_urls": ["https://youtube.com/watch?v=1234"],
239 "categories": {"items": []},
240 "status": "published",
241 "update_metadata_on_release": True,
242 "links": {"website": ["https://example.com"]},
243 }
245 responses.add(responses.GET, self.api_url, json=payload, status=200)
246 responses.add(
247 responses.GET,
248 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
249 json=[],
250 status=200,
251 )
253 response = self.client.get(self.endpoint_url)
255 self.check_call_by_api_url(responses.calls)
257 assert response.status_code == 200
259 @responses.activate
260 def test_failed_categories_api(self):
261 payload = {
262 "snap_id": "id",
263 "snap_name": self.snap_name,
264 "title": "Snap title",
265 "summary": "This is a summary",
266 "description": "This is a description",
267 "media": [],
268 "publisher": {"display-name": "The publisher", "username": "toto"},
269 "private": True,
270 "channel_maps_list": [{"map": [{"info": "info"}]}],
271 "contact": "contact adress",
272 "website": "website_url",
273 "public_metrics_enabled": True,
274 "public_metrics_blacklist": True,
275 "license": "license",
276 "video_urls": ["https://youtube.com/watch?v=1234"],
277 "categories": {"items": []},
278 "status": "published",
279 "update_metadata_on_release": True,
280 "links": {"website": ["https://example.com"]},
281 }
283 responses.add(responses.GET, self.api_url, json=payload, status=200)
284 responses.add(
285 responses.GET,
286 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
287 json=[],
288 status=500,
289 )
291 response = self.client.get(self.endpoint_url)
293 self.check_call_by_api_url(responses.calls)
295 assert response.status_code == 200