Coverage for tests/endpoints/tests_get_store.py: 100%
17 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-05 22:06 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-05 22:06 +0000
1import json
2from json import dumps as _dumps
3from unittest.mock import MagicMock, patch
4from tests.endpoints.endpoint_testing import TestEndpoints
7class TestGetStore(TestEndpoints):
8 @patch("canonicalwebteam.store_api.dashboard.Dashboard.get_store")
9 def test_get_store(self, mock_get_store):
10 def dumps_wrapper(*args, **kwargs):
11 return _dumps(
12 *args,
13 **(kwargs | {"default": lambda obj: json.dumps(test_store)})
14 )
16 json.dumps = MagicMock(wraps=dumps_wrapper)
18 test_store = {
19 "allowed-inclusion-source-stores": [],
20 "allowed-inclusion-target-stores": [],
21 "brand-id": "test-brand-id",
22 "id": "test-id",
23 "manual-review-policy": "avoid",
24 "name": "Test Store",
25 "parent": None,
26 "private": False,
27 "roles": [
28 {
29 "description": "Admin's manage the store users",
30 "label": "Admin",
31 "role": "admin",
32 }
33 ],
34 "snap-name-prefixes": [],
35 "store-whitelist": [],
36 }
38 mock_get_store.return_value = test_store
40 response = self.client.get("/api/store/test-store-id")
41 data = response.get_json()
43 self.assertEqual(response.status_code, 200)
44 self.assertTrue(data["success"])
45 self.assertEqual(
46 data["data"],
47 json.dumps(
48 {
49 "allowed-inclusion-source-stores": [],
50 "allowed-inclusion-target-stores": [],
51 "brand-id": "test-brand-id",
52 "id": "test-id",
53 "manual-review-policy": "avoid",
54 "name": "Test Store",
55 "parent": None,
56 "private": False,
57 "roles": [
58 {
59 "description": "Admin's manage the store users",
60 "label": "Admin",
61 "role": "admin",
62 }
63 ],
64 "snap-name-prefixes": [],
65 "store-whitelist": [],
66 }
67 ),
68 )