Skip to content

Commit ec2202b

Browse files
committed
WD-17150 - add tests
1 parent 90f2759 commit ec2202b

2 files changed

Lines changed: 138 additions & 2 deletions

File tree

tests/store/tests_details.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from webapp.app import create_app
55

66

7+
EMPTY_EXTRA_DETAILS_PAYLOAD = {"aliases": None, "package_name": "vault"}
8+
9+
710
class GetDetailsPageTest(TestCase):
811
def setUp(self):
912
self.snap_name = "toto"
@@ -40,6 +43,15 @@ def setUp(self):
4043
]
4144
)
4245
self.endpoint_url = "/" + self.snap_name
46+
self.api_url_details = "".join(
47+
[
48+
"https://api.snapcraft.io/api/v1/",
49+
"snaps/details/",
50+
self.snap_name,
51+
"?",
52+
urlencode({"fields": ",".join(["aliases"])}),
53+
]
54+
)
4355

4456
def create_app(self):
4557
app = create_app(testing=True)
@@ -125,6 +137,14 @@ def test_no_channel_map(self):
125137
method="GET", url=self.api_url, json=payload, status=200
126138
)
127139
)
140+
responses.add(
141+
responses.Response(
142+
method="GET",
143+
url=self.api_url_details,
144+
json=EMPTY_EXTRA_DETAILS_PAYLOAD,
145+
status=200,
146+
)
147+
)
128148

129149
response = self.client.get(self.endpoint_url)
130150

@@ -174,6 +194,14 @@ def test_user_connected(self):
174194
method="GET", url=self.api_url, json=payload, status=200
175195
)
176196
)
197+
responses.add(
198+
responses.Response(
199+
method="GET",
200+
url=self.api_url_details,
201+
json=EMPTY_EXTRA_DETAILS_PAYLOAD,
202+
status=200,
203+
)
204+
)
177205

178206
metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
179207
responses.add(
@@ -239,6 +267,14 @@ def test_user_not_connected(self):
239267
method="GET", url=self.api_url, json=payload, status=200
240268
)
241269
)
270+
responses.add(
271+
responses.Response(
272+
method="GET",
273+
url=self.api_url_details,
274+
json=EMPTY_EXTRA_DETAILS_PAYLOAD,
275+
status=200,
276+
)
277+
)
242278

243279
metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
244280
responses.add(
@@ -296,6 +332,14 @@ def test_user_connected_on_not_own_snap(self):
296332
method="GET", url=self.api_url, json=payload, status=200
297333
)
298334
)
335+
responses.add(
336+
responses.Response(
337+
method="GET",
338+
url=self.api_url_details,
339+
json=EMPTY_EXTRA_DETAILS_PAYLOAD,
340+
status=200,
341+
)
342+
)
299343

300344
metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
301345
responses.add(
@@ -311,3 +355,91 @@ def test_user_connected_on_not_own_snap(self):
311355

312356
assert response.status_code == 200
313357
self.assert_context("is_users_snap", False)
358+
359+
@responses.activate
360+
def test_extra_details(self):
361+
payload = {
362+
"snap-id": "toto_id",
363+
"name": "toto",
364+
"default-track": None,
365+
"snap": {
366+
"title": "Snap Title",
367+
"summary": "This is a summary",
368+
"description": "this is a description",
369+
"media": [],
370+
"license": "license",
371+
"publisher": {
372+
"display-name": "Toto",
373+
"username": "toto",
374+
"validation": True,
375+
},
376+
"categories": [{"name": "test"}],
377+
"trending": False,
378+
"unlisted": False,
379+
"links": {},
380+
},
381+
"channel-map": [
382+
{
383+
"channel": {
384+
"architecture": "amd64",
385+
"name": "stable",
386+
"risk": "stable",
387+
"track": "latest",
388+
"released-at": "2018-09-18T14:45:28.064633+00:00",
389+
},
390+
"created-at": "2018-09-18T14:45:28.064633+00:00",
391+
"version": "1.0",
392+
"confinement": "conf",
393+
"download": {"size": 100000},
394+
}
395+
],
396+
}
397+
payload_extra_details = {
398+
"aliases": [
399+
{"name": "nu", "target": "nu"},
400+
{
401+
"name": "nu_plugin_stress_internals",
402+
"target": "nu-plugin-stress-internals",
403+
},
404+
{"name": "nu_plugin_gstat", "target": "nu-plugin-gstat"},
405+
{"name": "nu_plugin_formats", "target": "nu-plugin-formats"},
406+
{"name": "nu_plugin_polars", "target": "nu-plugin-polars"},
407+
],
408+
"package_name": "toto",
409+
}
410+
411+
responses.add(
412+
responses.Response(
413+
method="GET", url=self.api_url, json=payload, status=200
414+
)
415+
)
416+
responses.add(
417+
responses.Response(
418+
method="GET",
419+
url=self.api_url_details,
420+
json=payload_extra_details,
421+
status=200,
422+
)
423+
)
424+
metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
425+
responses.add(
426+
responses.Response(
427+
method="POST", url=metrics_url, json={}, status=200
428+
)
429+
)
430+
431+
response = self.client.get(self.endpoint_url)
432+
assert response.status_code == 200
433+
self.assert_context(
434+
"aliases",
435+
[
436+
["toto.nu", "nu"],
437+
[
438+
"toto.nu-plugin-stress-internals",
439+
"nu_plugin_stress_internals",
440+
],
441+
["toto.nu-plugin-gstat", "nu_plugin_gstat"],
442+
["toto.nu-plugin-formats", "nu_plugin_formats"],
443+
["toto.nu-plugin-polars", "nu_plugin_polars"],
444+
],
445+
)

webapp/store/snap_details_views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,15 @@ def snap_details(snap_name):
213213

214214
context = _get_context_snap_details(snap_name)
215215
extra_details = device_gateway.get_snap_details(
216-
snap_name, fields=FIELDS_EXTRA_DETAILS)
216+
snap_name, fields=FIELDS_EXTRA_DETAILS
217+
)
217218

218219
if extra_details["aliases"]:
219220
context["aliases"] = [
220-
[f"{extra_details['package_name']}.{alias_obj['target']}", alias_obj['name']]
221+
[
222+
f"{extra_details['package_name']}.{alias_obj['target']}",
223+
alias_obj["name"],
224+
]
221225
for alias_obj in extra_details["aliases"]
222226
]
223227

0 commit comments

Comments
 (0)