Changeset 9f0f35e for buildhelpers
- Timestamp:
- May 19, 2020, 8:59:28 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 24617e1
- Parents:
- d5199c9
- Location:
- buildhelpers
- Files:
-
- 4 edited
-
codegen/templates/__init__test.mustache (modified) (1 diff)
-
codegen/templates/controller.mustache (modified) (2 diffs)
-
codegen/templates/controller_test.mustache (modified) (1 diff)
-
configure (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
buildhelpers/codegen/templates/__init__test.mustache
rd5199c9 r9f0f35e 1 from flask_testing import TestCase2 3 from {{packageName}}_impl.tests import (4 create_app as orig_create_app,5 setUp as orig_setUp,6 tearDown as orig_tearDown7 )8 9 class BaseTestCase(TestCase):10 def create_app(self):11 return orig_create_app(self)12 13 def setUp(self):14 orig_setUp(self)15 16 def tearDown(self):17 orig_tearDown(self)18 19 def check_key(self, key, value, data):20 assert key in data, "{} not in data {}".format(key, data)21 assert data[key] == value, "{} = {}".format(value, data[key]) -
buildhelpers/codegen/templates/controller.mustache
rd5199c9 r9f0f35e 5 5 {{/imports}} 6 6 from {{packageName}} import util 7 from {{packageName}}_impl.controllers import {{classFilename}} 7 8 {{#operations}} 8 9 {{#operation}} 9 10 from {{packageName}}_impl.controllers import {{classname}}11 10 12 11 def {{operationId}}({{#allParams}}{{paramName}}{{^required}}=None{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): # noqa: E501 … … 109 108 {{/isMapContainer}} 110 109 {{/allParams}} 111 return {{class name}}.{{operationId}}({{#allParams}}{{paramName}}{{^required}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})110 return {{classFilename}}.{{operationId}}({{#allParams}}{{paramName}}{{^required}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) 112 111 {{/operation}} 113 112 {{/operations}} -
buildhelpers/codegen/templates/controller_test.mustache
rd5199c9 r9f0f35e 1 1 # coding: utf-8 2 2 3 from __future__ import absolute_import 4 import unittest 5 6 from flask import json 7 from six import BytesIO 3 import pytest 4 import json 8 5 9 6 {{#imports}}{{import}} # noqa: E501 10 7 {{/imports}} 11 from . import BaseTestCase12 8 9 # {{classFilename}} integration test stubs 10 {{#operations}} 11 {{#operation}} 12 {{#vendorExtensions.x-skip-test}} 13 @pytest.mark.skip(reason="{{reason}}") 14 {{/vendorExtensions.x-skip-test}} 15 {{#vendorExtensions.x-xfail-test}} 16 @pytest.mark.xfail(reason=('Reason: ' 17 '{{reason}}')) # noqa: E501 18 {{/vendorExtensions.x-xfail-test}} 19 def test_{{operationId}}({{#vendorExtensions.x-mapservice-required}}mapservice, {{/vendorExtensions.x-mapservice-required}}client): 20 """Test case for {{{operationId}}} 21 {{{summary}}} 22 """ 23 {{#bodyParam}} 24 {{paramName}} = {{{example}}} 25 {{/bodyParam}} 26 {{#queryParams}} 27 {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', '{{{example}}}'){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}} 28 {{/queryParams}} 29 headers = { {{#vendorExtensions.x-prefered-produce}} 30 'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}} 31 'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-consume}}{{#headerParams}} 32 '{{paramName}}': '{{{example}}}',{{/headerParams}}{{#authMethods}} 33 {{#isBasicBasic}}'Authorization': 'Basic YXV0b3Rlc3RzOmF1dG90ZXN0cw==',{{/isBasicBasic}} 34 {{/authMethods}} 35 } 36 {{#formParams}} 37 {{#-first}}data = dict({{/-first}}{{^-first}} {{/-first}}{{paramName}}={{{example}}}{{#hasMore}},{{/hasMore}}{{#-last}}){{/-last}} 38 {{/formParams}} 13 39 14 class {{#operations}}Test{{classname}}(BaseTestCase): 15 """{{classname}} integration test stubs""" 16 17 {{#operation}} 18 {{#vendorExtensions.x-skip-test}} 19 @unittest.skip("{{reason}}") 20 {{/vendorExtensions.x-skip-test}} 21 def test_{{operationId}}(self): 22 """Test case for {{{operationId}}} 23 {{{summary}}} 24 """ 25 {{#bodyParam}} 26 {{paramName}} = {{{example}}} 27 {{/bodyParam}} 28 {{#queryParams}} 29 {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', '{{{example}}}'){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}} 30 {{/queryParams}} 31 headers = { {{#vendorExtensions.x-prefered-produce}} 32 'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}} 33 'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-consume}}{{#headerParams}} 34 '{{paramName}}': '{{{example}}}',{{/headerParams}}{{#authMethods}} 35 {{#isBasicBasic}}'Authorization': 'Basic YXV0b3Rlc3RzOmF1dG90ZXN0cw==',{{/isBasicBasic}} 36 {{/authMethods}} 37 } 38 {{#formParams}} 39 {{#-first}}data = dict({{/-first}}{{^-first}} {{/-first}}{{paramName}}={{{example}}}{{#hasMore}},{{/hasMore}}{{#-last}}){{/-last}} 40 {{/formParams}} 41 response = self.client.open( 42 '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}='{{{example}}}'{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}}, 43 method='{{httpMethod}}', 44 headers=headers{{#bodyParam}}, 45 data=json.dumps({{paramName}}){{^consumes}}, 46 content_type='application/json'{{/consumes}}{{/bodyParam}}{{#formParams}}{{#-first}}, 47 data=data{{/-first}}{{/formParams}}{{#consumes}}{{#-first}}, 48 content_type='{{{mediaType}}}'{{/-first}}{{/consumes}}{{#queryParams}}{{#-first}}, 49 query_string=query_string{{/-first}}{{/queryParams}}) 50 self.assert200(response, 51 'Response body is : ' + response.data.decode('utf-8')) 52 53 {{/operation}} 40 {{#responses}} 41 {{#-first}} 42 response = client.open( 43 '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}='{{{example}}}'{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}}, 44 method='{{httpMethod}}', 45 headers=headers{{#bodyParam}}, 46 data=json.dumps({{paramName}}){{^consumes}}, 47 content_type='application/json'{{/consumes}}{{/bodyParam}}{{#formParams}}{{#-first}}, 48 data=data{{/-first}}{{/formParams}}{{#consumes}}{{#-first}}, 49 content_type='{{{mediaType}}}'{{/-first}}{{/consumes}}{{#queryParams}}{{#-first}}, 50 query_string=query_string{{/-first}}{{/queryParams}}) 51 try: 52 response_data = response.data.decode('utf-8') 53 except Exception as e: 54 response_data = 'Failed to decode body with {}'.format(repr(e)) 55 assert response.status_code == {{code}}, \ 56 'Response body is : {}'.format(response_data) 57 {{/-first}} 58 {{^-first}} 59 # Skipping responses with status code {{code}} 60 {{/-first}} 61 {{/responses}} 62 63 64 {{/operation}} 54 65 {{/operations}} 55 56 if __name__ == '__main__':57 unittest.main() -
buildhelpers/configure
rd5199c9 r9f0f35e 11 11 CURRENT_DIR = Path(os.path.dirname(__file__)) 12 12 SRC = CURRENT_DIR.joinpath('../src/gnuboat') 13 SRC_GEN = CURRENT_DIR.joinpath('../src /gnuboat/')13 SRC_GEN = CURRENT_DIR.joinpath('../src') 14 14 APIS_DIR = CURRENT_DIR.joinpath('../apis') 15 15 version_file = open(CURRENT_DIR.joinpath('../VERSION').resolve(), 'r') … … 51 51 Package('mapservice', 'python-flask', CURRENT_DIR.joinpath('codegen/templates'), None), 52 52 Package('deviceservice', 'python-flask', CURRENT_DIR.joinpath('codegen/templates'), None), 53 Package('mapservice', 'python', None, 'mapservice_client'), 53 Package('mapservice', 'python', None, 'gnuboat/mapservice_client'), 54 Package('mapservice', 'typescript-angular', None, 'mapservice-webclient/src-gen/gnuboat-mapservice'), 54 55 ] 55 56 56 def generate_stub(package, generator, template_folder, target ):57 def generate_stub(package, generator, template_folder, target_dir): 57 58 target_tmp = SRC_GEN.joinpath('{}_tmp'.format(package)) 58 59 service_specification_file = APIS_DIR.joinpath('{}.yaml'.format(package)).resolve() 59 60 server_port = 8080 60 61 62 target = target_dir.stem 61 63 package_name_gen = 'gnuboat.{}'.format(target) 62 64 target_tmp = SRC_GEN.joinpath('{}_tmp'.format(package)) 63 target_dir = SRC_GEN.joinpath(target )65 target_dir = SRC_GEN.joinpath(target_dir) 64 66 service_specification_file = APIS_DIR.joinpath('{}.yaml'.format(package)).resolve() 65 67 server_port = 8080 … … 104 106 return 105 107 106 shutil.move(target_tmp.joinpath('gnuboat/{}'.format(target)).resolve(), target_dir.resolve()) 107 shutil.rmtree(target_tmp.resolve()) 108 if 'python' in generator: 109 shutil.move(target_tmp.joinpath('gnuboat/{}'.format(target)).resolve(), target_dir.resolve()) 110 shutil.rmtree(target_tmp.resolve()) 111 # running yapf 112 print(' Formatting the generated code accoring to style file') 113 subprocess.run(['yapf', '--style', 'python-style.yapf', '-r', '-i', 114 target_dir.resolve()]) 115 if 'python-flask' == generator: 116 # copy conftest in place 117 shutil.copy(target_dir.joinpath( 118 '../{}_impl/tests/conftest.py'.format(package)).resolve(), 119 target_dir.joinpath('test').resolve() 120 ) 121 else: 122 shutil.move(target_tmp, target_dir.resolve()) 108 123 109 # running yapf110 print(' Formatting the generated code accoring to style file')111 subprocess.run(['yapf', '--style', 'python-style.yapf', '-r', '-i',112 target_dir.resolve()])113 124 114 125 print('Generating the {} services:'.format(len(PACKAGES))) 115 126 for package in PACKAGES: 116 127 print(' {}'.format(package.package)) 117 118 128 for package in PACKAGES: 119 129 package_name_gen = 'gnuboat.{}'.format(package) 120 130 if package.target is None: 121 package.target = package.package 131 package.target = Path('gnuboat').joinpath(package.package) 132 else: 133 package.target = Path(package.target) 122 134 generate_stub(package.package, package.generator, package.template_folder, package.target) 123 135
Note:
See TracChangeset
for help on using the changeset viewer.
