@@ -60,6 +60,16 @@ def create_app(self):
6060
6161 return app
6262
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+
6373 @responses .activate
6474 def test_api_404 (self ):
6575 payload = {"error-list" : [{"code" : "resource-not-found" }]}
@@ -77,6 +87,86 @@ def test_api_404(self):
7787
7888 assert response .status_code == 404
7989
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+ metrics_url = "https://api.snapcraft.io/api/v1/snaps/metrics"
153+ responses .add (
154+ responses .Response (
155+ method = "POST" , url = metrics_url , json = {}, status = 200
156+ )
157+ )
158+
159+ response = self .client .get (self .endpoint_url )
160+
161+ assert len (responses .calls ) == 3
162+ assert responses .calls [0 ].request .url == self .api_url
163+ assert responses .calls [1 ].request .url == self .api_url_details
164+ assert responses .calls [2 ].request .url == metrics_url
165+
166+ self .assert200 (response )
167+ self .assert_not_in_context ("aliases" )
168+ self .assert_context ("snap-id" , "id" )
169+
80170 @responses .activate
81171 def test_api_500 (self ):
82172 payload = {"error-list" : []}
0 commit comments