mirrored from https://chromium.googlesource.com/infra/luci/luci-py
-
Notifications
You must be signed in to change notification settings - Fork 36
/
endpoints_smoke_test.py
executable file
·71 lines (56 loc) · 2.14 KB
/
endpoints_smoke_test.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env vpython
# Copyright 2014 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
"""Smoke test for Cloud Endpoints support in auth component.
It launches app via dev_appserver and queries a bunch of cloud endpoints
methods.
"""
import os
import shutil
import sys
import tempfile
import unittest
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_APP_DIR = os.path.join(THIS_DIR, 'test_endpoints_app')
from tool_support import gae_sdk_utils
from tool_support import local_app
class CloudEndpointsSmokeTest(unittest.TestCase):
def setUp(self):
super(CloudEndpointsSmokeTest, self).setUp()
self.root = tempfile.mkdtemp(prefix='endpoints_smoke_test')
self.app = local_app.LocalApplication(TEST_APP_DIR, 9700, False, self.root)
self.app.start()
self.app.ensure_serving()
def tearDown(self):
try:
self.app.stop()
shutil.rmtree(self.root)
if self.has_failed():
self.app.dump_log()
finally:
super(CloudEndpointsSmokeTest, self).tearDown()
def has_failed(self):
# pylint: disable=E1101
return not self._resultForDoCleanups.wasSuccessful()
def test_smoke(self):
self.check_who_anonymous()
self.check_who_authenticated()
self.check_forbidden()
def check_who_anonymous(self):
response = self.app.client.json_request('/_ah/api/testing_service/v1/who')
self.assertEqual(200, response.http_code)
self.assertEqual('anonymous:anonymous', response.body.get('identity'))
self.assertIn(response.body.get('ip'), ('127.0.0.1', '0:0:0:0:0:0:0:1'))
def check_who_authenticated(self):
# TODO(vadimsh): Testing this requires interacting with real OAuth2 service
# to get OAuth2 token. It's doable, but the service account secrets had to
# be hardcoded into the source code. I'm not sure it's a good idea.
pass
def check_forbidden(self):
response = self.app.client.json_request(
'/_ah/api/testing_service/v1/forbidden')
self.assertEqual(403, response.http_code)
if __name__ == '__main__':
gae_sdk_utils.setup_gae_env()
unittest.main()