Coverage for tests/publisher/snaps/tests_listing.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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_page_not_found(self):
31 payload = {"error_list": []}
32 responses.add(responses.GET, self.api_url, json=payload, status=404)
34 response = self.client.get(self.endpoint_url)
36 self.check_call_by_api_url(responses.calls)
38 assert response.status_code == 404
39 self.assert_template_used("404.html")
41 @responses.activate
42 def test_account_logged_in(self):
43 snap_name = "test-snap"
45 payload = {
46 "snap_id": "id",
47 "snap_name": snap_name,
48 "title": "Snap title",
49 "summary": "This is a summary",
50 "description": "This is a description",
51 "media": [],
52 "publisher": {"display-name": "The publisher", "username": "toto"},
53 "private": True,
54 "channel_maps_list": [{"map": [{"info": "info"}]}],
55 "contact": "contact adress",
56 "website": "website_url",
57 "public_metrics_enabled": True,
58 "public_metrics_blacklist": False,
59 "license": "License",
60 "video_urls": [],
61 "categories": {"items": []},
62 "status": "published",
63 "update_metadata_on_release": True,
64 "links": {"website": ["https://example.com"]},
65 }
67 responses.add(responses.GET, self.api_url, json=payload, status=200)
68 responses.add(
69 responses.GET,
70 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
71 json=[],
72 status=200,
73 )
75 endpoint = "?".join([self.endpoint_url, "from=test"])
77 response = self.client.get(endpoint)
79 self.check_call_by_api_url(responses.calls)
81 assert response.status_code == 200
83 @responses.activate
84 def test_icon(self):
85 payload = {
86 "snap_id": "id",
87 "snap_name": self.snap_name,
88 "title": "Snap title",
89 "summary": "This is a summary",
90 "description": "This is a description",
91 "media": [{"url": "this is a url", "type": "icon"}],
92 "publisher": {"display-name": "The publisher", "username": "toto"},
93 "private": True,
94 "channel_maps_list": [{"map": [{"info": "info"}]}],
95 "contact": "contact adress",
96 "website": "website_url",
97 "public_metrics_enabled": True,
98 "public_metrics_blacklist": True,
99 "license": "license",
100 "video_urls": [],
101 "categories": {"items": []},
102 "status": "published",
103 "update_metadata_on_release": True,
104 "links": {"website": ["https://example.com"]},
105 }
107 responses.add(responses.GET, self.api_url, json=payload, status=200)
108 responses.add(
109 responses.GET,
110 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
111 json=[],
112 status=200,
113 )
115 response = self.client.get(self.endpoint_url)
117 self.check_call_by_api_url(responses.calls)
119 assert response.status_code == 200
121 @responses.activate
122 def test_screenshots(self):
123 payload = {
124 "snap_id": "id",
125 "snap_name": self.snap_name,
126 "title": "Snap title",
127 "summary": "This is a summary",
128 "description": "This is a description",
129 "media": [{"url": "this is a url", "type": "screenshot"}],
130 "publisher": {"display-name": "The publisher", "username": "toto"},
131 "private": True,
132 "channel_maps_list": [{"map": [{"info": "info"}]}],
133 "contact": "contact adress",
134 "website": "website_url",
135 "public_metrics_enabled": True,
136 "public_metrics_blacklist": True,
137 "license": "license",
138 "video_urls": [],
139 "categories": {"items": []},
140 "status": "published",
141 "update_metadata_on_release": True,
142 "links": {"website": ["https://example.com"]},
143 }
145 responses.add(responses.GET, self.api_url, json=payload, status=200)
146 responses.add(
147 responses.GET,
148 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
149 json=[],
150 status=200,
151 )
153 response = self.client.get(self.endpoint_url)
155 self.check_call_by_api_url(responses.calls)
157 assert response.status_code == 200
159 @responses.activate
160 def test_banner_images(self):
161 payload = {
162 "snap_id": "id",
163 "snap_name": self.snap_name,
164 "title": "Snap title",
165 "summary": "This is a summary",
166 "description": "This is a description",
167 "media": [
168 {"url": "/banner_1234.png", "type": "banner"},
169 {"url": "/test.jpg", "type": "screenshot"},
170 {"url": "/banner-icon_4321.jpg", "type": "screenshot"},
171 {"url": "/banner-test.png", "type": "screenshot"},
172 {"url": "/banner-icon", "type": "screenshot"},
173 ],
174 "publisher": {"display-name": "The publisher", "username": "toto"},
175 "private": True,
176 "channel_maps_list": [{"map": [{"info": "info"}]}],
177 "contact": "contact adress",
178 "website": "website_url",
179 "public_metrics_enabled": True,
180 "public_metrics_blacklist": True,
181 "license": "license",
182 "video_urls": [],
183 "categories": {"items": []},
184 "status": "published",
185 "update_metadata_on_release": True,
186 "links": {"website": ["https://example.com"]},
187 }
189 responses.add(responses.GET, self.api_url, json=payload, status=200)
190 responses.add(
191 responses.GET,
192 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
193 json=[],
194 status=200,
195 )
197 response = self.client.get(self.endpoint_url)
199 self.check_call_by_api_url(responses.calls)
201 assert response.status_code == 200
203 @responses.activate
204 def test_videos(self):
205 payload = {
206 "snap_id": "id",
207 "snap_name": self.snap_name,
208 "title": "Snap title",
209 "summary": "This is a summary",
210 "description": "This is a description",
211 "media": [],
212 "publisher": {"display-name": "The publisher", "username": "toto"},
213 "private": True,
214 "channel_maps_list": [{"map": [{"info": "info"}]}],
215 "contact": "contact adress",
216 "website": "website_url",
217 "public_metrics_enabled": True,
218 "public_metrics_blacklist": True,
219 "license": "license",
220 "video_urls": ["https://youtube.com/watch?v=1234"],
221 "categories": {"items": []},
222 "status": "published",
223 "update_metadata_on_release": True,
224 "links": {"website": ["https://example.com"]},
225 }
227 responses.add(responses.GET, self.api_url, json=payload, status=200)
228 responses.add(
229 responses.GET,
230 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
231 json=[],
232 status=200,
233 )
235 response = self.client.get(self.endpoint_url)
237 self.check_call_by_api_url(responses.calls)
239 assert response.status_code == 200
241 @responses.activate
242 def test_failed_categories_api(self):
243 payload = {
244 "snap_id": "id",
245 "snap_name": self.snap_name,
246 "title": "Snap title",
247 "summary": "This is a summary",
248 "description": "This is a description",
249 "media": [],
250 "publisher": {"display-name": "The publisher", "username": "toto"},
251 "private": True,
252 "channel_maps_list": [{"map": [{"info": "info"}]}],
253 "contact": "contact adress",
254 "website": "website_url",
255 "public_metrics_enabled": True,
256 "public_metrics_blacklist": True,
257 "license": "license",
258 "video_urls": ["https://youtube.com/watch?v=1234"],
259 "categories": {"items": []},
260 "status": "published",
261 "update_metadata_on_release": True,
262 "links": {"website": ["https://example.com"]},
263 }
265 responses.add(responses.GET, self.api_url, json=payload, status=200)
266 responses.add(
267 responses.GET,
268 "https://api.snapcraft.io/v2/snaps/categories?type=shared",
269 json=[],
270 status=500,
271 )
273 response = self.client.get(self.endpoint_url)
275 self.check_call_by_api_url(responses.calls)
277 assert response.status_code == 200