44from webapp .app import create_app
55
66
7- EMPTY_EXTRA_DETAILS_PAYLOAD = {"aliases" : None , "package_name" : "vault" }
8-
9-
107class GetDetailsPageTest (TestCase ):
118 def setUp (self ):
129 self .snap_name = "toto"
@@ -43,15 +40,6 @@ def setUp(self):
4340 ]
4441 )
4542 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- )
5543
5644 def create_app (self ):
5745 app = create_app (testing = True )
@@ -60,16 +48,6 @@ def create_app(self):
6048
6149 return app
6250
63- def assert_not_in_context (self , name ):
64- try :
65- self .get_context_variable (name )
66- except Exception :
67- # flask-testing throws exception if context doesn't have "name"
68- # that's what we expect so we just return and let the test pass
69- return
70- # If we reach this point it means the variable IS in context
71- self .fail (f"Context variable exists: { name } " )
72-
7351 @responses .activate
7452 def test_api_404 (self ):
7553 payload = {"error-list" : [{"code" : "resource-not-found" }]}
@@ -87,77 +65,6 @@ def test_api_404(self):
8765
8866 assert response .status_code == 404
8967
90- @responses .activate
91- def test_extra_details_404 (self ):
92- payload = {
93- "snap-id" : "id" ,
94- "name" : "toto" ,
95- "default-track" : None ,
96- "snap" : {
97- "title" : "Snap Title" ,
98- "summary" : "This is a summary" ,
99- "description" : "this is a description" ,
100- "media" : [],
101- "license" : "license" ,
102- "publisher" : {
103- "display-name" : "Toto" ,
104- "username" : "toto" ,
105- "validation" : True ,
106- },
107- "categories" : [{"name" : "test" }],
108- "trending" : False ,
109- "unlisted" : False ,
110- "links" : {},
111- },
112- "channel-map" : [
113- {
114- "channel" : {
115- "architecture" : "amd64" ,
116- "name" : "stable" ,
117- "risk" : "stable" ,
118- "track" : "latest" ,
119- "released-at" : "2018-09-18T14:45:28.064633+00:00" ,
120- },
121- "created-at" : "2018-09-18T14:45:28.064633+00:00" ,
122- "version" : "1.0" ,
123- "confinement" : "conf" ,
124- "download" : {"size" : 100000 },
125- }
126- ],
127- }
128- extra_details_payload = {
129- "error_list" : [
130- {
131- "code" : "resource-not-found" ,
132- "message" : "No snap named 'toto' found in series '16'." ,
133- }
134- ],
135- "errors" : ["No snap named 'toto' found in series '16'." ],
136- "result" : "error" ,
137- }
138-
139- responses .add (
140- responses .Response (
141- method = "GET" , url = self .api_url , json = payload , status = 200
142- )
143- )
144- responses .add (
145- responses .Response (
146- method = "GET" ,
147- url = self .api_url_details ,
148- json = extra_details_payload ,
149- status = 404 ,
150- )
151- )
152-
153- response = self .client .get (self .endpoint_url )
154-
155- assert len (responses .calls ) == 2
156- assert responses .calls [0 ].request .url == self .api_url
157- assert responses .calls [1 ].request .url == self .api_url_details
158-
159- assert response .status_code == 404
160-
16168 @responses .activate
16269 def test_api_500 (self ):
16370 payload = {"error-list" : []}
@@ -218,14 +125,6 @@ def test_no_channel_map(self):
218125 method = "GET" , url = self .api_url , json = payload , status = 200
219126 )
220127 )
221- responses .add (
222- responses .Response (
223- method = "GET" ,
224- url = self .api_url_details ,
225- json = EMPTY_EXTRA_DETAILS_PAYLOAD ,
226- status = 200 ,
227- )
228- )
229128
230129 response = self .client .get (self .endpoint_url )
231130
@@ -275,14 +174,6 @@ def test_user_connected(self):
275174 method = "GET" , url = self .api_url , json = payload , status = 200
276175 )
277176 )
278- responses .add (
279- responses .Response (
280- method = "GET" ,
281- url = self .api_url_details ,
282- json = EMPTY_EXTRA_DETAILS_PAYLOAD ,
283- status = 200 ,
284- )
285- )
286177
287178 metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
288179 responses .add (
@@ -348,14 +239,6 @@ def test_user_not_connected(self):
348239 method = "GET" , url = self .api_url , json = payload , status = 200
349240 )
350241 )
351- responses .add (
352- responses .Response (
353- method = "GET" ,
354- url = self .api_url_details ,
355- json = EMPTY_EXTRA_DETAILS_PAYLOAD ,
356- status = 200 ,
357- )
358- )
359242
360243 metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
361244 responses .add (
@@ -413,14 +296,6 @@ def test_user_connected_on_not_own_snap(self):
413296 method = "GET" , url = self .api_url , json = payload , status = 200
414297 )
415298 )
416- responses .add (
417- responses .Response (
418- method = "GET" ,
419- url = self .api_url_details ,
420- json = EMPTY_EXTRA_DETAILS_PAYLOAD ,
421- status = 200 ,
422- )
423- )
424299
425300 metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
426301 responses .add (
@@ -436,91 +311,3 @@ def test_user_connected_on_not_own_snap(self):
436311
437312 assert response .status_code == 200
438313 self .assert_context ("is_users_snap" , False )
439-
440- @responses .activate
441- def test_extra_details (self ):
442- payload = {
443- "snap-id" : "toto_id" ,
444- "name" : "toto" ,
445- "default-track" : None ,
446- "snap" : {
447- "title" : "Snap Title" ,
448- "summary" : "This is a summary" ,
449- "description" : "this is a description" ,
450- "media" : [],
451- "license" : "license" ,
452- "publisher" : {
453- "display-name" : "Toto" ,
454- "username" : "toto" ,
455- "validation" : True ,
456- },
457- "categories" : [{"name" : "test" }],
458- "trending" : False ,
459- "unlisted" : False ,
460- "links" : {},
461- },
462- "channel-map" : [
463- {
464- "channel" : {
465- "architecture" : "amd64" ,
466- "name" : "stable" ,
467- "risk" : "stable" ,
468- "track" : "latest" ,
469- "released-at" : "2018-09-18T14:45:28.064633+00:00" ,
470- },
471- "created-at" : "2018-09-18T14:45:28.064633+00:00" ,
472- "version" : "1.0" ,
473- "confinement" : "conf" ,
474- "download" : {"size" : 100000 },
475- }
476- ],
477- }
478- payload_extra_details = {
479- "aliases" : [
480- {"name" : "nu" , "target" : "nu" },
481- {
482- "name" : "nu_plugin_stress_internals" ,
483- "target" : "nu-plugin-stress-internals" ,
484- },
485- {"name" : "nu_plugin_gstat" , "target" : "nu-plugin-gstat" },
486- {"name" : "nu_plugin_formats" , "target" : "nu-plugin-formats" },
487- {"name" : "nu_plugin_polars" , "target" : "nu-plugin-polars" },
488- ],
489- "package_name" : "toto" ,
490- }
491-
492- responses .add (
493- responses .Response (
494- method = "GET" , url = self .api_url , json = payload , status = 200
495- )
496- )
497- responses .add (
498- responses .Response (
499- method = "GET" ,
500- url = self .api_url_details ,
501- json = payload_extra_details ,
502- status = 200 ,
503- )
504- )
505- metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
506- responses .add (
507- responses .Response (
508- method = "POST" , url = metrics_url , json = {}, status = 200
509- )
510- )
511-
512- response = self .client .get (self .endpoint_url )
513- assert response .status_code == 200
514- self .assert_context (
515- "aliases" ,
516- [
517- ["toto.nu" , "nu" ],
518- [
519- "toto.nu-plugin-stress-internals" ,
520- "nu_plugin_stress_internals" ,
521- ],
522- ["toto.nu-plugin-gstat" , "nu_plugin_gstat" ],
523- ["toto.nu-plugin-formats" , "nu_plugin_formats" ],
524- ["toto.nu-plugin-polars" , "nu_plugin_polars" ],
525- ],
526- )
0 commit comments