Coverage for tests/store/tests_publisher.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 urllib.parse import urlencode
3from flask_testing import TestCase
4from webapp.app import create_app
7class GetPublisherPageTest(TestCase):
8 def setUp(self):
9 self.publisher = "jetbrains"
10 self.api_url = "".join(
11 [
12 "https://api.snapcraft.io/api/v1/",
13 "snaps/search",
14 "?",
15 urlencode(
16 {
17 "q": "publisher:28zEonXNoBLvIB7xneRbltOsp0Nf7DwS",
18 "size": "500",
19 "page": "1",
20 "scope": "wide",
21 "confinement": "strict,classic",
22 "fields": ",".join(
23 [
24 "package_name",
25 "title",
26 "summary",
27 "architecture",
28 "media",
29 "developer_name",
30 "developer_id",
31 "developer_validation",
32 "origin",
33 "apps",
34 "sections",
35 ]
36 ),
37 "arch": "wide",
38 }
39 ),
40 ]
41 )
43 self.api_url
45 self.endpoint_url = "/publisher/" + self.publisher
47 def create_app(self):
48 app = create_app(testing=True)
49 app.secret_key = "secret_key"
50 app.config["WTF_CSRF_METHODS"] = []
52 return app
54 def test_community_publisher(self):
55 response = self.client.get("/publisher/lukewh")
56 self.assertEqual(response.status_code, 200)
57 self.assert_template_used("store/community-publisher-details.html")
59 def test_existant_publisher(self):
60 response = self.client.get("/publisher/jetbrains")
61 self.assertEqual(response.status_code, 200)
62 self.assert_template_used("store/publisher-details.html")
64 def test_non_existant_publisher(self):
65 response = self.client.get("/publisher/toto")
66 self.assertEqual(response.status_code, 200)
67 self.assert_template_used("store/community-publisher-details.html")
69 @responses.activate
70 def test_api_error(self):
71 responses.add(responses.GET, self.api_url, json={}, status=504)
73 response = self.client.get(self.endpoint_url)
75 self.assertEqual(response.status_code, 200)
76 self.assert_template_used("store/publisher-details.html")
78 @responses.activate
79 def test_no_snaps_from_api(self):
80 payload = {"_embedded": {"clickindex:package": []}}
82 responses.add(responses.GET, self.api_url, json=payload, status=200)
84 response = self.client.get(self.endpoint_url)
86 self.assertEqual(response.status_code, 200)
87 self.assert_template_used("store/publisher-details.html")