Coverage for tests/publisher/snaps/tests_post_close_channel.py: 100%
79 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-28 22:05 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-28 22:05 +0000
1import responses
2from tests.publisher.endpoint_testing import BaseTestCases
5class PostCloseChannelPageNotAuth(BaseTestCases.EndpointLoggedOut):
6 def setUp(self):
7 snap_name = "test-snap"
8 endpoint_url = "/{}/releases/close-channel".format(snap_name)
10 super().setUp(
11 snap_name=snap_name,
12 endpoint_url=endpoint_url,
13 method_endpoint="POST",
14 )
17class PostDataCloseChannelGetSnapIdPage(BaseTestCases.EndpointLoggedIn):
18 def setUp(self):
19 snap_name = "test-snap"
20 endpoint_url = "/{}/releases/close-channel".format(snap_name)
21 json = {"info": "json"}
23 api_url = "https://dashboard.snapcraft.io/dev/api/snaps/info/{}"
24 api_url = api_url.format(snap_name)
26 super().setUp(
27 snap_name=snap_name,
28 api_url=api_url,
29 endpoint_url=endpoint_url,
30 method_api="GET",
31 method_endpoint="POST",
32 json=json,
33 )
35 @responses.activate
36 def test_page_not_found(self):
37 payload = {"error_list": []}
38 responses.add(responses.GET, self.api_url, json=payload, status=404)
40 response = self.client.post(self.endpoint_url, json=self.json)
41 self.check_call_by_api_url(responses.calls)
43 assert response.status_code == 404
44 self.assert_template_used("404.html")
46 @responses.activate
47 def test_error_4xx(self):
48 payload = {"error_list": []}
49 responses.add(responses.GET, self.api_url, json=payload, status=400)
51 response = self.client.post(self.endpoint_url, json=self.json)
52 self.check_call_by_api_url(responses.calls)
54 assert response.status_code == 400
55 assert response.get_json() == []
58class PostDataCloseChannelPage(BaseTestCases.EndpointLoggedIn):
59 def setUp(self):
60 snap_name = "test-snap"
61 snap_id = "test_id"
62 endpoint_url = "/{}/releases/close-channel".format(snap_name)
63 api_url = (
64 "https://dashboard.snapcraft.io/dev/api/"
65 "snaps/{}/close".format(snap_id)
66 )
67 json = {"info": "json"}
69 api_info_url = "https://dashboard.snapcraft.io/dev/api/snaps/info/{}"
70 api_info_url = api_info_url.format(snap_name)
71 responses.add(
72 method=responses.GET,
73 url=api_info_url,
74 json={"snap_id": snap_id},
75 status=200,
76 )
78 super().setUp(
79 snap_name=snap_name,
80 api_url=api_url,
81 endpoint_url=endpoint_url,
82 method_api="POST",
83 method_endpoint="POST",
84 json=json,
85 )
87 @responses.activate
88 def test_page_not_found(self):
89 payload = {"error_list": []}
90 responses.add(responses.POST, self.api_url, json=payload, status=404)
92 response = self.client.post(self.endpoint_url, json=self.json)
93 self.check_call_by_api_url(responses.calls)
95 assert response.status_code == 404
96 self.assert_template_used("404.html")
98 def test_post_no_data(self):
99 response = self.client.post(self.endpoint_url, json={})
101 assert response.status_code == 400
102 assert response.get_json() == {}
104 @responses.activate
105 def test_post_data(self):
106 payload = {}
108 responses.add(responses.POST, self.api_url, json=payload, status=200)
110 response = self.client.post(self.endpoint_url, json=self.json)
111 self.check_call_by_api_url(responses.calls)
113 result = {"success": True}
114 assert response.json == result
116 @responses.activate
117 def test_return_error(self):
118 payload = {"error_list": [{"code": "code", "name": ["message"]}]}
120 responses.add(responses.POST, self.api_url, json=payload, status=400)
122 response = self.client.post(self.endpoint_url, json=self.json)
123 self.check_call_by_api_url(responses.calls)
125 expected_response = {
126 "errors": [{"code": "code", "name": ["message"]}],
127 "success": False,
128 }
129 assert response.json == expected_response
131 @responses.activate
132 def test_error_4xx(self):
133 payload = {"error_list": []}
134 responses.add(responses.POST, self.api_url, json=payload, status=400)
136 response = self.client.post(self.endpoint_url, json=self.json)
137 self.check_call_by_api_url(responses.calls)
139 expected_response = {"errors": [], "success": False}
140 assert response.status_code == 400
141 assert response.get_json() == expected_response