Changeset be25db1 for src/mapservice
- Timestamp:
- Apr 22, 2019, 5:39:46 PM (8 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 041e464
- Parents:
- 5e4cb73
- Location:
- src/mapservice
- Files:
-
- 1 added
- 19 edited
-
codegen/code_generator (modified) (1 diff)
-
codegen/templates/__init__test.mustache (modified) (1 diff)
-
codegen/templates/controller_test.mustache (modified) (2 diffs)
-
codegen/templates/requirements.mustache (modified) (1 diff)
-
openapi.yaml (modified) (12 diffs)
-
src-gen/openapi_server/controllers/waters_controller.py (modified) (2 diffs)
-
src-gen/openapi_server/models/__init__.py (modified) (1 diff)
-
src-gen/openapi_server/models/water.py (modified) (1 diff)
-
src-gen/openapi_server/models/water_creation.py (modified) (1 diff)
-
src-gen/openapi_server/openapi/openapi.yaml (modified) (12 diffs)
-
src-gen/openapi_server/static/js/GnuBoat.Webserver.js (modified) (1 diff)
-
src-gen/openapi_server/test/__init__.py (modified) (1 diff)
-
src-gen/openapi_server/test/test_default_controller.py (modified) (2 diffs)
-
src-gen/openapi_server/test/test_waters_controller.py (modified) (3 diffs)
-
src-gen/requirements.txt (modified) (1 diff)
-
src/server_impl/controllers/UsersController.py (modified) (4 diffs)
-
src/server_impl/controllers/WatersController.py (modified) (1 diff)
-
src/server_impl/database/Model.py (modified) (3 diffs)
-
src/server_impl/tests/test_users.py (modified) (3 diffs)
-
src/server_impl/tests/test_waters.py (added)
Legend:
- Unmodified
- Added
- Removed
-
src/mapservice/codegen/code_generator
r5e4cb73 rbe25db1 9 9 fi 10 10 11 echo "Copying static files"12 cp -a ../../src/templates ./13 cp -a ../../src/static ./14 mkdir -p static/css/15 mkdir -p static/js/16 mkdir -p static/resources/17 cp -a ../../../common/css/* static/css/18 cp -a ../../../common/js/* static/js/19 cp -a ../../../common/resources/* static/resources/20 cp -a ../../../../icon/gnuboat-256-256-transparent.png static/resources/11 #echo "Copying static files" 12 #cp -a ../../src/templates ./ 13 #cp -a ../../src/static ./ 14 #mkdir -p static/css/ 15 #mkdir -p static/js/ 16 #mkdir -p static/resources/ 17 #cp -a ../../common/css/* static/css/ 18 #cp -a ../../common/js/* static/js/ 19 #cp -a ../../common/resources/* static/resources/ 20 #cp -a ../../common/icon/gnuboat-256-256-transparent.png static/resources/ 21 21 22 echo "Generating backend and client API code" 22 23 cd ../../ 24 # backend 23 25 codegen/openapi-generator-cli generate -i openapi.yaml -g python-flask -t codegen/templates/ -o src-gen 26 # client 27 #codegen/openapi-generator-cli generate -i openapi.yaml -g javascript -o src-gen/openapi_server/static/ 28 #rm -R src-gen/openapi_server/static/.openapi* 29 24 30 25 31 cd src-gen/ 32 tox > /tmp/openapi_tox.log 26 33 python3 -m openapi_server -
src/mapservice/codegen/templates/__init__test.mustache
r5e4cb73 rbe25db1 2 2 3 3 import connexion 4 from flask_cors import CORS 4 5 from flask_testing import TestCase 5 6 6 7 from {{packageName}}.encoder import JSONEncoder 7 8 9 from {{packageName}}.server_impl.database.Model import db, db_test_setup 8 10 9 11 class BaseTestCase(TestCase): 12 def create_app(self): 13 logging.getLogger('connexion.operation').setLevel('ERROR') 14 app = connexion.App(__name__, specification_dir='../openapi/') 15 application = app.app 16 CORS(application) 17 application.json_encoder = JSONEncoder 18 app.add_api('openapi.yaml') 10 19 11 def create_app(self): 12 logging.getLogger('connexion.operation').setLevel('ERROR') 13 app = connexion.App(__name__, specification_dir='../openapi/') 14 app.app.json_encoder = JSONEncoder 15 app.add_api('openapi.yaml') 16 return app.app 20 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig') 21 db.init_app(application) 22 application.app_context().push() 23 24 return application 25 26 def setUp(self): 27 db.drop_all() 28 db_test_setup() 29 30 def tearDown(self): 31 db.session.remove() 32 db.drop_all() -
src/mapservice/codegen/templates/controller_test.mustache
r5e4cb73 rbe25db1 28 28 {{/bodyParam}} 29 29 {{#queryParams}} 30 {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', {{{example}}}){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}}30 {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', '{{{example}}}'){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}} 31 31 {{/queryParams}} 32 32 headers = { {{#vendorExtensions.x-prefered-produce}} 33 33 'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}} 34 34 'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-consume}}{{#headerParams}} 35 '{{paramName}}': {{{example}}},{{/headerParams}}{{#authMethods}}36 {{#isOAuth}}'Authorization': 'Bearer special-key',{{/isOAuth}}{{#isApiKey}}' {{name}}': 'special-key',{{/isApiKey}}{{#isBasicBasic}}'Authorization': 'BasicZm9vOmJhcg==',{{/isBasicBasic}}{{#isBasicBearer}}'Authorization': 'Bearer special-key',{{/isBasicBearer}}{{/authMethods}}35 '{{paramName}}': '{{{example}}}',{{/headerParams}}{{#authMethods}} 36 {{#isOAuth}}'Authorization': 'Bearer special-key',{{/isOAuth}}{{#isApiKey}}'X-API-KEY': 'test_key',{{/isApiKey}}{{#isBasicBasic}}'Authorization': 'BasicZm9vOmJhcg==',{{/isBasicBasic}}{{#isBasicBearer}}'Authorization': 'Bearer special-key',{{/isBasicBearer}}{{/authMethods}} 37 37 } 38 38 {{#formParams}} … … 40 40 {{/formParams}} 41 41 response = self.client.open( 42 '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}= {{{example}}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}},42 '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}='{{{example}}}'{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}}, 43 43 method='{{httpMethod}}', 44 44 headers=headers{{#bodyParam}}, -
src/mapservice/codegen/templates/requirements.mustache
r5e4cb73 rbe25db1 6 6 {{/supportPython2}} 7 7 setuptools >= 21.0.0 8 flask-sqlalchemy 9 flask-cors -
src/mapservice/openapi.yaml
r5e4cb73 rbe25db1 23 23 default: v1 24 24 paths: 25 '/user': 26 get: 27 description: Returns information for a user 28 tags: 29 - users 30 summary: Returns info of a user 31 operationId: usersGet 32 security: 33 - basicAuth: [] 34 - apiKeyAuth: [] 35 responses: 36 '200': 37 description: OK 38 content: 39 application/json: 40 schema: 41 $ref: '#/components/schemas/User' 42 examples: 43 User: 44 $ref: '#/components/examples/User' 45 '400': 46 $ref: '#/components/responses/BadRequest' 47 '401': 48 $ref: '#/components/responses/Unauthorized' 49 post: 50 description: Registers a new user 51 tags: 52 - users 53 summary: Registers a new user 54 operationId: usersRegister 55 requestBody: 56 content: 57 application/json: 58 schema: 59 $ref: '#/components/schemas/UserCreation' 60 examples: 61 Water: 62 $ref: '#/components/examples/UserCreation' 63 responses: 64 '201': 65 description: Userr created 66 content: 67 application/json: 68 schema: 69 $ref: '#/components/schemas/User' 70 examples: 71 Water: 72 $ref: '#/components/examples/User' 73 '400': 74 $ref: '#/components/responses/BadRequest' 75 options: 76 description: Used by CORS preflight 77 tags: 78 - users 79 responses: 80 '200': 81 description: CORS prefilght requests should return 200 as status code 82 content: 83 application/json: {} 84 '/user/apikey_create': 85 get: 86 description: Generates and returns a new API key for current user 87 tags: 88 - users 89 summary: Returns a new API key 90 operationId: usersApiKeyCreate 91 security: 92 - basicAuth: [] 93 - apiKeyAuth: [] 94 responses: 95 '200': 96 description: OK 97 content: 98 application/json: 99 schema: 100 $ref: '#/components/schemas/apiKeys' 101 example: 'NewApiKey4711' 102 '400': 103 $ref: '#/components/responses/BadRequest' 104 '401': 105 $ref: '#/components/responses/Unauthorized' 106 '/user/{api_key}': 107 delete: 108 description: Deletes given API key and returns remaining API keys of the user 109 tags: 110 - users 111 summary: Deletes API key 112 operationId: usersApiKeyDelete 113 security: 114 - basicAuth: [] 115 - apiKeyAuth: [] 116 parameters: 117 - name: api_key 118 in: path 119 description: API key 120 required: true 121 schema: 122 $ref: '#/components/schemas/apiKey' 123 example: 'DelApiKey4711' 124 responses: 125 '200': 126 description: OK 127 content: 128 application/json: 129 schema: 130 $ref: '#/components/schemas/apiKeys' 131 example: 'ApiKey4711' 132 '400': 133 $ref: '#/components/responses/BadRequest' 134 '401': 135 $ref: '#/components/responses/Unauthorized' 136 '/user/activate/{activation_code}': 137 get: 138 description: Activates a user account 139 tags: 140 - users 141 summary: Activates a user account 142 operationId: usersActivate 143 parameters: 144 - name: activation_code 145 in: path 146 description: Activation code 147 required: true 148 schema: 149 $ref: '#/components/schemas/activationCode' 150 example: 'dac9630aec642a428cd73f4be0a03569' 151 responses: 152 '302': 153 description: OK or not OK 154 headers: 155 Location: 156 schema: 157 type: string 158 description: URL to the website, showing the result of the activation 25 159 /waters: 26 160 get: … … 32 166 parameters: 33 167 - name: name 34 in: header168 in: query 35 169 schema: 36 170 $ref: '#/components/schemas/item_name' 171 example: 'Missi' 37 172 - name: manager 38 in: header173 in: query 39 174 schema: 40 175 $ref: '#/components/schemas/username' 176 example: 'jane' 41 177 - $ref: '#/components/parameters/orderBy' 42 178 - $ref: '#/components/parameters/offset' … … 57 193 - waters 58 194 summary: Add a new water 195 operationId: watersCreate 59 196 security: 60 197 - basicAuth: [] 61 198 - apiKeyAuth: [] 62 199 requestBody: 63 description: item id of water is going to be ignored64 200 content: 65 201 application/json: … … 124 260 title: Username 125 261 type: string 262 apiKey: 263 title: API Key 264 type: string 265 apiKeys: 266 title: Array of API keys 267 type: array 268 items: 269 $ref: '#/components/schemas/apiKey' 270 activationCode: 271 title: Activation code for a User 272 type: string 126 273 item_id: 127 274 title: Item ID … … 131 278 title: Item Name 132 279 type: string 133 osm _type:280 osmType: 134 281 maxLength: 1 135 282 minLength: 1 136 283 type: string 284 User: 285 title: User 286 type: object 287 properties: 288 username: 289 $ref: '#/components/schemas/username' 290 email: 291 type: string 292 firstName: 293 type: string 294 lastName: 295 type: string 296 activated: 297 type: boolean 298 apiKeys: 299 $ref: '#/components/schemas/apiKeys' 300 UserCreation: 301 title: User 302 type: object 303 properties: 304 username: 305 $ref: '#/components/schemas/username' 306 email: 307 type: string 308 firstName: 309 type: string 310 lastName: 311 type: string 312 password: 313 type: string 314 required: 315 - username 316 - email 317 - firstName 318 - lastName 319 - password 137 320 Water: 138 321 title: Water 139 322 type: object 140 323 properties: 141 water _id:324 waterId: 142 325 $ref: '#/components/schemas/item_id' 143 326 name: … … 145 328 manager: 146 329 $ref: '#/components/schemas/username' 147 osm _id:330 osmId: 148 331 $ref: '#/components/schemas/item_id' 149 osm _type:150 $ref: '#/components/schemas/osm _type'332 osmType: 333 $ref: '#/components/schemas/osmType' 151 334 osm_class: 152 $ref: '#/components/schemas/osm _type'335 $ref: '#/components/schemas/osmType' 153 336 required: 154 - water _id337 - waterId 155 338 - name 156 339 WaterCreation: … … 160 343 name: 161 344 $ref: '#/components/schemas/item_name' 162 osm _id:345 osmId: 163 346 $ref: '#/components/schemas/item_id' 164 osm _type:165 $ref: '#/components/schemas/osm _type'347 osmType: 348 $ref: '#/components/schemas/osmType' 166 349 required: 167 350 - name … … 202 385 type: string 203 386 default: name 387 example: 'name' 204 388 order: 205 389 name: order … … 208 392 schema: 209 393 $ref: '#/components/schemas/order' 394 example: '' 210 395 offset: 211 396 name: offset … … 231 416 example: 10 232 417 examples: 418 User: 419 value: 420 username: jane 421 email: jane@example.org 422 firstName: Jane 423 lastName: Doe 424 activated: true 425 apiKeys: 426 - ApiKey4701 427 UserCreation: 428 value: 429 username: richard 430 email: richard@examle.org 431 firstName: Richard 432 lastName: Roe 433 password: sdfl.1238_ASDkeil? 233 434 Water: 234 435 value: 235 water _id: 1436 waterId: 1 236 437 name: Mississippi 237 osm _id: 1756854238 osm _type: R438 osmId: 1756854 439 osmType: R 239 440 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1' 240 441 summary: A water example object … … 242 443 value: 243 444 name: Mississippi 244 osm _id: 1756854245 osm _type: R445 osmId: 1756854 446 osmType: R 246 447 summary: A water example object for creation of a water 247 448 waters: 248 449 value: 249 - water _id: 1450 - waterId: 1 250 451 name: Mississippi 251 osm _id: 1756854252 osm _type: R452 osmId: 1756854 453 osmType: R 253 454 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1' 254 - water _id: 2455 - waterId: 2 255 456 name: Bodensee 256 457 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/2' … … 293 494 A water is a river (like Mississippi, lake (Lake Ontario), or a sea (North 294 495 Sea) 496 - name: users 497 description: >- 498 All actions used to manage users and api keys -
src/mapservice/src-gen/openapi_server/controllers/waters_controller.py
r5e4cb73 rbe25db1 23 23 from openapi_server.server_impl.controllers import WatersController 24 24 25 def waters_create(water_creation=None): # noqa: E501 26 """Add a new water 27 28 Adds a new water to the database # noqa: E501 29 30 :param water_creation: 31 :type water_creation: dict | bytes 32 33 :rtype: Water 34 """ 35 if connexion.request.is_json: 36 water_creation = WaterCreation.from_dict(connexion.request.get_json()) # noqa: E501 37 return WatersController.waters_create(water_creation=water_creation) 38 39 from openapi_server.server_impl.controllers import WatersController 40 25 41 def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None): # noqa: E501 26 42 """Find waters by id … … 42 58 """ 43 59 return WatersController.waters_get(name=name, manager=manager, order_by=order_by, offset=offset, limit=limit) 44 45 from openapi_server.server_impl.controllers import WatersController46 47 def waters_post(water_creation=None): # noqa: E50148 """Add a new water49 50 Adds a new water to the database # noqa: E50151 52 :param water_creation: item id of water is going to be ignored53 :type water_creation: dict | bytes54 55 :rtype: Water56 """57 if connexion.request.is_json:58 water_creation = WaterCreation.from_dict(connexion.request.get_json()) # noqa: E50159 return WatersController.waters_post(water_creation=water_creation) -
src/mapservice/src-gen/openapi_server/models/__init__.py
r5e4cb73 rbe25db1 6 6 from openapi_server.models.http_error import HttpError 7 7 from openapi_server.models.order import Order 8 from openapi_server.models.user import User 9 from openapi_server.models.user_creation import UserCreation 8 10 from openapi_server.models.water import Water 9 11 from openapi_server.models.water_creation import WaterCreation -
src/mapservice/src-gen/openapi_server/models/water.py
r5e4cb73 rbe25db1 42 42 43 43 self.attribute_map = { 44 'water_id': 'water _id',44 'water_id': 'waterId', 45 45 'name': 'name', 46 46 'manager': 'manager', 47 'osm_id': 'osm _id',48 'osm_type': 'osm _type',47 'osm_id': 'osmId', 48 'osm_type': 'osmType', 49 49 'osm_class': 'osm_class' 50 50 } -
src/mapservice/src-gen/openapi_server/models/water_creation.py
r5e4cb73 rbe25db1 34 34 self.attribute_map = { 35 35 'name': 'name', 36 'osm_id': 'osm _id',37 'osm_type': 'osm _type'36 'osm_id': 'osmId', 37 'osm_type': 'osmType' 38 38 } 39 39 -
src/mapservice/src-gen/openapi_server/openapi/openapi.yaml
r5e4cb73 rbe25db1 25 25 - description: A water is a river (like Mississippi, lake (Lake Ontario), or a sea (North Sea) 26 26 name: waters 27 - description: All actions used to manage users and api keys 28 name: users 27 29 paths: 30 /user: 31 get: 32 description: Returns information for a user 33 operationId: users_get 34 responses: 35 200: 36 content: 37 application/json: 38 examples: 39 User: 40 $ref: '#/components/examples/User' 41 schema: 42 $ref: '#/components/schemas/User' 43 description: OK 44 400: 45 content: 46 application/json: 47 examples: 48 HttpError: 49 $ref: '#/components/examples/HttpError' 50 schema: 51 $ref: '#/components/schemas/HttpError' 52 description: Bad Request (400) 53 401: 54 content: 55 application/json: 56 examples: 57 HttpError: 58 $ref: '#/components/examples/HttpError' 59 schema: 60 $ref: '#/components/schemas/HttpError' 61 description: Unauthorized (401) acces to resource 62 security: 63 - basicAuth: [] 64 - apiKeyAuth: [] 65 summary: Returns info of a user 66 tags: 67 - users 68 x-openapi-router-controller: openapi_server.controllers.users_controller 69 options: 70 description: Used by CORS preflight 71 operationId: user_options 72 responses: 73 200: 74 content: 75 application/json: {} 76 description: CORS prefilght requests should return 200 as status code 77 tags: 78 - users 79 x-openapi-router-controller: openapi_server.controllers.users_controller 80 post: 81 description: Registers a new user 82 operationId: users_register 83 requestBody: 84 content: 85 application/json: 86 examples: 87 Water: 88 $ref: '#/components/examples/UserCreation' 89 schema: 90 $ref: '#/components/schemas/UserCreation' 91 responses: 92 201: 93 content: 94 application/json: 95 examples: 96 Water: 97 $ref: '#/components/examples/User' 98 schema: 99 $ref: '#/components/schemas/User' 100 description: Userr created 101 400: 102 content: 103 application/json: 104 examples: 105 HttpError: 106 $ref: '#/components/examples/HttpError' 107 schema: 108 $ref: '#/components/schemas/HttpError' 109 description: Bad Request (400) 110 summary: Registers a new user 111 tags: 112 - users 113 x-openapi-router-controller: openapi_server.controllers.users_controller 114 /user/apikey_create: 115 get: 116 description: Generates and returns a new API key for current user 117 operationId: users_api_key_create 118 responses: 119 200: 120 content: 121 application/json: 122 example: NewApiKey4711 123 schema: 124 $ref: '#/components/schemas/apiKeys' 125 description: OK 126 400: 127 content: 128 application/json: 129 examples: 130 HttpError: 131 $ref: '#/components/examples/HttpError' 132 schema: 133 $ref: '#/components/schemas/HttpError' 134 description: Bad Request (400) 135 401: 136 content: 137 application/json: 138 examples: 139 HttpError: 140 $ref: '#/components/examples/HttpError' 141 schema: 142 $ref: '#/components/schemas/HttpError' 143 description: Unauthorized (401) acces to resource 144 security: 145 - basicAuth: [] 146 - apiKeyAuth: [] 147 summary: Returns a new API key 148 tags: 149 - users 150 x-openapi-router-controller: openapi_server.controllers.users_controller 151 /user/{api_key}: 152 delete: 153 description: Deletes given API key and returns remaining API keys of the user 154 operationId: users_api_key_delete 155 parameters: 156 - description: API key 157 example: DelApiKey4711 158 explode: false 159 in: path 160 name: api_key 161 required: true 162 schema: 163 $ref: '#/components/schemas/apiKey' 164 style: simple 165 responses: 166 200: 167 content: 168 application/json: 169 example: ApiKey4711 170 schema: 171 $ref: '#/components/schemas/apiKeys' 172 description: OK 173 400: 174 content: 175 application/json: 176 examples: 177 HttpError: 178 $ref: '#/components/examples/HttpError' 179 schema: 180 $ref: '#/components/schemas/HttpError' 181 description: Bad Request (400) 182 401: 183 content: 184 application/json: 185 examples: 186 HttpError: 187 $ref: '#/components/examples/HttpError' 188 schema: 189 $ref: '#/components/schemas/HttpError' 190 description: Unauthorized (401) acces to resource 191 security: 192 - basicAuth: [] 193 - apiKeyAuth: [] 194 summary: Deletes API key 195 tags: 196 - users 197 x-openapi-router-controller: openapi_server.controllers.users_controller 198 /user/activate/{activation_code}: 199 get: 200 description: Activates a user account 201 operationId: users_activate 202 parameters: 203 - description: Activation code 204 example: dac9630aec642a428cd73f4be0a03569 205 explode: false 206 in: path 207 name: activation_code 208 required: true 209 schema: 210 $ref: '#/components/schemas/activationCode' 211 style: simple 212 responses: 213 302: 214 description: OK or not OK 215 headers: 216 Location: 217 description: URL to the website, showing the result of the activation 218 explode: false 219 schema: 220 type: string 221 style: simple 222 summary: Activates a user account 223 tags: 224 - users 225 x-openapi-router-controller: openapi_server.controllers.users_controller 28 226 /waters: 29 227 get: … … 31 229 operationId: waters_get 32 230 parameters: 33 - explode: false 34 in: header 231 - example: Missi 232 explode: true 233 in: query 35 234 name: name 36 235 required: false 37 236 schema: 38 237 $ref: '#/components/schemas/item_name' 39 style: simple 40 - explode: false 41 in: header 238 style: form 239 - example: jane 240 explode: true 241 in: query 42 242 name: manager 43 243 required: false 44 244 schema: 45 245 $ref: '#/components/schemas/username' 46 style: simple246 style: form 47 247 - description: 'Order by field: name' 48 248 explode: true … … 52 252 schema: 53 253 default: name 254 example: name 54 255 type: string 55 256 style: form … … 92 293 post: 93 294 description: Adds a new water to the database 94 operationId: waters_ post295 operationId: waters_create 95 296 requestBody: 96 297 content: … … 101 302 schema: 102 303 $ref: '#/components/schemas/WaterCreation' 103 description: item id of water is going to be ignored104 304 responses: 105 305 201: … … 175 375 components: 176 376 examples: 377 User: 378 value: 379 username: jane 380 email: jane@example.org 381 firstName: Jane 382 lastName: Doe 383 activated: true 384 apiKeys: 385 - ApiKey4701 386 UserCreation: 387 value: 388 username: richard 389 email: richard@examle.org 390 firstName: Richard 391 lastName: Roe 392 password: sdfl.1238_ASDkeil? 177 393 Water: 178 394 summary: A water example object 179 395 value: 180 water _id: 1396 waterId: 1 181 397 name: Mississippi 182 osm _id: 1756854183 osm _type: R398 osmId: 1756854 399 osmType: R 184 400 link: http://gnuboat.engsas.com/mapservice/v1/waters/1 185 401 WaterCreation: … … 187 403 value: 188 404 name: Mississippi 189 osm _id: 1756854190 osm _type: R405 osmId: 1756854 406 osmType: R 191 407 waters: 192 408 summary: A sample list with waters 193 409 value: 194 - water _id: 1410 - waterId: 1 195 411 name: Mississippi 196 osm _id: 1756854197 osm _type: R412 osmId: 1756854 413 osmType: R 198 414 link: http://gnuboat.engsas.com/mapservice/v1/waters/1 199 - water _id: 2415 - waterId: 2 200 416 name: Bodensee 201 417 link: http://gnuboat.engsas.com/mapservice/v1/waters/2 … … 213 429 schema: 214 430 default: name 431 example: name 215 432 type: string 216 433 style: form … … 280 497 title: Username 281 498 type: string 499 apiKey: 500 title: API Key 501 type: string 502 apiKeys: 503 items: 504 $ref: '#/components/schemas/apiKey' 505 title: Array of API keys 506 type: array 507 activationCode: 508 title: Activation code for a User 509 type: string 282 510 item_id: 283 511 format: int32 … … 287 515 title: Item Name 288 516 type: string 289 osm _type:517 osmType: 290 518 maxLength: 1 291 519 minLength: 1 292 520 type: string 521 User: 522 example: 523 firstName: firstName 524 lastName: lastName 525 apiKeys: 526 - null 527 - null 528 email: email 529 username: username 530 activated: true 531 properties: 532 username: 533 title: Username 534 type: string 535 email: 536 type: string 537 firstName: 538 type: string 539 lastName: 540 type: string 541 activated: 542 type: boolean 543 apiKeys: 544 items: 545 $ref: '#/components/schemas/apiKey' 546 title: Array of API keys 547 type: array 548 title: User 549 type: object 550 UserCreation: 551 example: 552 firstName: firstName 553 lastName: lastName 554 password: password 555 email: email 556 username: username 557 properties: 558 username: 559 title: Username 560 type: string 561 email: 562 type: string 563 firstName: 564 type: string 565 lastName: 566 type: string 567 password: 568 type: string 569 required: 570 - email 571 - firstName 572 - lastName 573 - password 574 - username 575 title: User 576 type: object 293 577 Water: 294 578 example: 295 osm_id: 6296 osm_type: osm_type297 579 manager: manager 580 osmId: 6 298 581 name: name 299 water_id: 0582 osmType: osmType 300 583 osm_class: osm_class 584 waterId: 0 301 585 properties: 302 water _id:586 waterId: 303 587 format: int32 304 588 title: Item ID … … 310 594 title: Username 311 595 type: string 312 osm _id:596 osmId: 313 597 format: int32 314 598 title: Item ID 315 599 type: integer 316 osm _type:600 osmType: 317 601 maxLength: 1 318 602 minLength: 1 … … 324 608 required: 325 609 - name 326 - water _id610 - waterId 327 611 title: Water 328 612 type: object 329 613 WaterCreation: 330 614 example: 331 osm_id: 0 332 osm_type: osm_type 615 osmId: 0 333 616 name: name 617 osmType: osmType 334 618 properties: 335 619 name: 336 620 title: Item Name 337 621 type: string 338 osm _id:622 osmId: 339 623 format: int32 340 624 title: Item ID 341 625 type: integer 342 osm _type:626 osmType: 343 627 maxLength: 1 344 628 minLength: 1 -
src/mapservice/src-gen/openapi_server/static/js/GnuBoat.Webserver.js
r5e4cb73 rbe25db1 111 111 // getting my waters 112 112 $.ajax({ 113 headers: {114 // manager: Cookies.get('username')115 manager: "bla"116 },117 113 dataType: "json", 118 url: GnuBoat.Webserver.private.serverBaseUrl +'waters ',114 url: GnuBoat.Webserver.private.serverBaseUrl +'waters?manager='+ encodeURIComponent(Cookies.get('username')), 119 115 }).done(function(data) { 120 116 GnuBoat.Webserver.private.loggedin = true; -
src/mapservice/src-gen/openapi_server/test/__init__.py
r5e4cb73 rbe25db1 2 2 3 3 import connexion 4 from flask_cors import CORS 4 5 from flask_testing import TestCase 5 6 6 7 from openapi_server.encoder import JSONEncoder 7 8 9 from openapi_server.server_impl.database.Model import db, db_test_setup 8 10 9 11 class BaseTestCase(TestCase): 12 def create_app(self): 13 logging.getLogger('connexion.operation').setLevel('ERROR') 14 app = connexion.App(__name__, specification_dir='../openapi/') 15 application = app.app 16 CORS(application) 17 application.json_encoder = JSONEncoder 18 app.add_api('openapi.yaml') 10 19 11 def create_app(self): 12 logging.getLogger('connexion.operation').setLevel('ERROR') 13 app = connexion.App(__name__, specification_dir='../openapi/') 14 app.app.json_encoder = JSONEncoder 15 app.add_api('openapi.yaml') 16 return app.app 20 application.config.from_object('openapi_server.server_impl.Config.TestingConfig') 21 db.init_app(application) 22 application.app_context().push() 23 24 return application 25 26 def setUp(self): 27 db.drop_all() 28 db_test_setup() 29 30 def tearDown(self): 31 db.session.remove() 32 db.drop_all() -
src/mapservice/src-gen/openapi_server/test/test_default_controller.py
r5e4cb73 rbe25db1 7 7 from six import BytesIO 8 8 9 from openapi_server.models.water import Water # noqa: E50110 9 from openapi_server.test import BaseTestCase 11 10 … … 14 13 """DefaultController integration test stubs""" 15 14 16 def test_ water_get_by_id(self):17 """Test case for water_get_by_id15 def test_user_options(self): 16 """Test case for user_options 18 17 19 Represents a water18 20 19 """ 21 20 headers = { 22 21 } 23 22 response = self.client.open( 24 '/mapservice/v1/ waters/{id}'.format(id=56),25 method=' GET',23 '/mapservice/v1/user', 24 method='OPTIONS', 26 25 headers=headers) 27 26 self.assert200(response, -
src/mapservice/src-gen/openapi_server/test/test_waters_controller.py
r5e4cb73 rbe25db1 2 2 3 3 from __future__ import absolute_import 4 import unittest 4 5 5 6 from flask import json 6 7 from six import BytesIO 7 8 8 from openapi_server.models.order import Order # noqa: E501 9 from openapi_server.models.http_error import HttpError # noqa: E501 10 from openapi_server.models.water import Water # noqa: E501 11 from openapi_server.models.water_creation import WaterCreation # noqa: E501 9 12 from openapi_server.test import BaseTestCase 10 13 … … 13 16 """WatersController integration test stubs""" 14 17 18 def test_water_get_by_id(self): 19 """Test case for water_get_by_id 20 21 Represents a water 22 """ 23 headers = { 24 } 25 response = self.client.open( 26 '/mapservice/v1/waters/{id}'.format(id='56'), 27 method='GET', 28 headers=headers) 29 self.assert200(response, 30 'Response body is : ' + response.data.decode('utf-8')) 31 32 def test_waters_create(self): 33 """Test case for waters_create 34 35 Add a new water 36 """ 37 water_creation = WaterCreation() 38 headers = { 39 'X-API-KEY': 'test_key', 40 41 } 42 response = self.client.open( 43 '/mapservice/v1/waters', 44 method='POST', 45 headers=headers, 46 data=json.dumps(water_creation), 47 content_type='application/json') 48 self.assert200(response, 49 'Response body is : ' + response.data.decode('utf-8')) 50 15 51 def test_waters_get(self): 16 52 """Test case for waters_get 17 53 18 Waters_GET54 Find waters by id 19 55 """ 20 query_string = [('order_by', 'order_by_example'), 21 ('order', Order()), 22 ('offset', 0), 23 ('limit', 10)] 56 query_string = [('name', 'Missi'), 57 ('manager', 'jane'), 58 ('order_by', 'name'), 59 ('offset', '0'), 60 ('limit', '10')] 61 headers = { 62 } 24 63 response = self.client.open( 25 64 '/mapservice/v1/waters', 26 65 method='GET', 66 headers=headers, 27 67 query_string=query_string) 28 68 self.assert200(response, … … 31 71 32 72 if __name__ == '__main__': 33 import unittest34 73 unittest.main() -
src/mapservice/src-gen/requirements.txt
r5e4cb73 rbe25db1 3 3 python_dateutil == 2.6.0 4 4 setuptools >= 21.0.0 5 flask-sqlalchemy 6 flask-cors -
src/mapservice/src/server_impl/controllers/UsersController.py
r5e4cb73 rbe25db1 20 20 import hashlib 21 21 22 from ..database.Model import User, ApiKey 22 from ..database.Model import User, ApiKey, db 23 23 from ..HttpErrors import BadRequest, Unauthorized, NotFound 24 24 … … 50 50 api_key = hashlib.md5("{}{}".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S"), user.salt).encode()).hexdigest() 51 51 user.apikeys.append(ApiKey(user=user, key=api_key)) 52 53 return api_key 52 db.session.commit() 53 54 result = [] 55 for apiKey in user.apikeys: 56 result.append(apiKey.key) 57 return result 54 58 55 59 def users_api_key_delete(api_key): … … 58 62 return Unauthorized 59 63 60 if not ApiKey.query.filter_by( user=user,key=api_key).delete():64 if not ApiKey.query.filter_by(key=api_key).delete(): 61 65 return BadRequest 66 db.session.commit() 62 67 63 68 result = [] … … 78 83 79 84 # add api keys of the user to the result dict 80 81 85 result['apiKeys'] = [] 82 86 for apiKey in user.apikeys: -
src/mapservice/src/server_impl/controllers/WatersController.py
r5e4cb73 rbe25db1 18 18 19 19 from ..database.Model import User, Water 20 from ..HttpErrors import BadRequest, Unauthorized, NotFound 20 21 21 22 def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None): 22 23 query = None 24 23 25 if manager is not None: 24 26 manager = User.query.filter_by(username=manager).all() 25 27 if len(manager) != 1: 26 return NoContent, 404 28 return NotFound 29 manager = manager[0] 27 30 28 31 query = None 29 32 if manager is not None: 30 if len(manager) == 1and name is not None:31 query = Water.query.filter_by( name = name, manager = manager[0])32 elif len(manager) == 1:33 query = Water.query.filter_by(manager = manager [0])33 if manager and name is not None: 34 query = Water.query.filter_by(manager = manager).filter(Water.name.like('%{}%'.format(name))) 35 elif manager: 36 query = Water.query.filter_by(manager = manager) 34 37 elif name is not None: 35 query = Water.query.filter _by(name = name)38 query = Water.query.filter(Water.name.like('%{}%'.format(name))) 36 39 37 40 if query is None: 38 query = Water.query.filter_by(name = '*') 41 print("5") 42 query = Water.query 39 43 40 44 result = [] 41 for water in query :45 for water in query.offset(offset).limit(limit): 42 46 result.append(water.to_dict()) 43 47 return result -
src/mapservice/src/server_impl/database/Model.py
r5e4cb73 rbe25db1 57 57 return result 58 58 59 def password_set(self, password): 60 self.salt = hashlib.md5('{}{}'.format(self.username, datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest() 61 self.password = hashlib.md5('{}{}'.format(password, self.salt).encode()).hexdigest() 59 def factory(username, password, email): 60 salt = hashlib.md5('{}{}'.format(username, datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest() 61 password = hashlib.md5('{}{}'.format(password, salt).encode()).hexdigest() 62 activation_code = hashlib.md5('{}'.format(datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest() 63 return User(username=username, password=password, email=email, salt=salt, activated=False, activation_code=activation_code) 62 64 63 65 def password_verify(self, password): … … 85 87 86 88 def to_dict(obj): 87 result = { 'water _id': obj.id, 'name': obj.name }89 result = { 'waterId': obj.id, 'name': obj.name } 88 90 if obj.manager: 89 91 result['manager'] = obj.manager.username 90 92 if obj.osm_id: 91 result['osm _id'] = obj.osm_id93 result['osmId'] = obj.osm_id 92 94 if obj.osm_type: 93 result['osm _type'] = obj.osm_type95 result['osmType'] = obj.osm_type 94 96 if obj.osm_class: 95 result['osm _class'] = obj.osm_class97 result['osmClass'] = obj.osm_class 96 98 return result 97 99 … … 118 120 with db.session.no_autoflush: 119 121 if len(User.query.filter_by(username='john').all()) < 1: 120 test_user_john = User (username='john', email='john@example.org', activated=False, activation_code='dac9630aec642a428cd73f4be0a03569')121 test_user_john. password_set('testpass2')122 test_user_john = User.factory('john', 'testpass2', 'john@example.org') 123 test_user_john.activation_code = 'dac9630aec642a428cd73f4be0a03569' 122 124 db.session.add(test_user_john) 123 125 124 test_user_jane = User(username='jane', email='jane@example.org', activated=True) 125 test_user_jane.password_set('testpass') 126 test_user_jane = User.factory('jane', 'testpass', 'jane@example.org') 127 test_user_jane.activated = True 128 test_user_jane.first_name = 'Jane' 126 129 test_key_del = ApiKey(user=test_user_jane, key='DelApiKey4711') 127 130 db.session.add(test_key_del) -
src/mapservice/src/server_impl/tests/test_users.py
r5e4cb73 rbe25db1 21 21 from openapi_server.test import BaseTestCase 22 22 23 class Test DefaultController(BaseTestCase):23 class TestUsers(BaseTestCase): 24 24 def test_users_get(self): 25 25 headers = {} … … 36 36 assert response.status_code == 200 37 37 data = json.loads(response.data) 38 self.check_key("user_id", 2, data)39 38 self.check_key("username", "jane", data) 40 self.check_key("first _name", "", data)41 self.check_key("last _name", "", data)39 self.check_key("firstName", "Jane", data) 40 self.check_key("lastName", "", data) 42 41 self.check_key("email", "jane@example.org", data) 43 42 self.check_key("activated", True, data) 44 43 45 assert "api_keys" in data 46 assert data["api_keys"][0] == "test_key" 47 assert data["api_keys"][1] == "ApiKey4712" 44 assert "apiKeys" in data 45 assert data["apiKeys"][0] == "DelApiKey4711" 46 assert data["apiKeys"][1] == "test_key" 47 assert data["apiKeys"][2] == "ApiKey4712" 48 48 49 49 assert "password" not in data … … 55 55 56 56 def check_key(self, key, value, data): 57 assert key in data58 assert data[key] == value57 if not key in data: raise AssertionError(print("{} not in data {}".format(key, data))) 58 if data[key] != value: raise AssertionError(print("{} = {}".format(value, data[key]))) 59 59 60 60 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.
