Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/google-endpoints/apitools/gen/client_generation_test.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #
2 # Copyright 2015 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """Test gen_client against all the APIs we use regularly."""
17
18 import logging
19 import os
20 import subprocess
21 import tempfile
22
23 import unittest2
24
25 from apitools.gen import test_utils
26
27
28 _API_LIST = [
29 'drive.v2',
30 'bigquery.v2',
31 'compute.v1',
32 'storage.v1',
33 ]
34
35
36 class ClientGenerationTest(unittest2.TestCase):
37
38 def setUp(self):
39 super(ClientGenerationTest, self).setUp()
40 self.gen_client_binary = 'gen_client'
41
42 @test_utils.RunOnlyOnPython27
43 def testGeneration(self):
44 for api in _API_LIST:
45 with test_utils.TempDir(change_to=True):
46 args = [
47 self.gen_client_binary,
48 '--client_id=12345',
49 '--client_secret=67890',
50 '--discovery_url=%s' % api,
51 '--outdir=generated',
52 '--overwrite',
53 'client',
54 ]
55 logging.info('Testing API %s with command line: %s',
56 api, ' '.join(args))
57 retcode = subprocess.call(args)
58 if retcode == 128:
59 logging.error('Failed to fetch discovery doc, continuing.')
60 continue
61 self.assertEqual(0, retcode)
62
63 with tempfile.NamedTemporaryFile() as out:
64 with tempfile.NamedTemporaryFile() as err:
65 cmdline_args = [
66 os.path.join(
67 'generated', api.replace('.', '_') + '.py'),
68 'help',
69 ]
70 retcode = subprocess.call(
71 cmdline_args, stdout=out, stderr=err)
72 with open(err.name, 'rb') as f:
73 err_output = f.read()
74 # appcommands returns 1 on help
75 self.assertEqual(1, retcode)
76 if 'Traceback (most recent call last):' in err_output:
77 err = '\n======\n%s======\n' % err_output
78 self.fail(
79 'Error raised in generated client:' + err)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/apitools/gen/__init__.py ('k') | third_party/google-endpoints/apitools/gen/command_registry.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698