forked from canonical/snapcraft.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint_testing.py
More file actions
48 lines (40 loc) · 1.49 KB
/
endpoint_testing.py
File metadata and controls
48 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from unittest import TestCase
from unittest.mock import patch
from webapp.app import create_app
from webapp.authentication import get_publishergw_authorization_header
from cache.cache_utility import redis_cache
class TestEndpoints(TestCase):
def _log_in(self, client):
test_macaroon = "test_macaroon"
with client.session_transaction() as s:
s["publisher"] = {
"account_id": "test_account_id",
"image": None,
"nickname": "XYZ",
"fullname": "ABC XYZ",
"email": "testing@testing.com",
"stores": [],
}
s["macaroons"] = "test_macaroon"
s["developer_token"] = test_macaroon
s["exchanged_developer_token"] = True
return get_publishergw_authorization_header(test_macaroon)
def setUp(self):
# Clear cache before each test
if redis_cache.redis_available:
try:
redis_cache.client.flushdb()
except Exception:
pass
else:
redis_cache.fallback.clear()
self.app = create_app(testing=True)
self.client = self.app.test_client()
self._log_in(self.client)
class TestModelServiceEndpoints(TestEndpoints):
def setUp(self):
self.api_key = "qwertyuioplkjhgfdsazxcvbnmkiopuytrewqasdfghjklmnbv"
self.mock_get_store = patch(
"webapp.endpoints.views.dashboard.get_store"
).start()
super().setUp()