diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-04-04 17:00:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-04 17:00:31 +0200 |
| commit | 38769373c7e89783d33849283586bfa0b62e8251 (patch) | |
| tree | 4fda128ee6b30018c1aa14c584cc53ade80e67f7 /opendc-web/opendc-web-api/tests/api/test_projects.py | |
| parent | 6021aa4278bebb34bf5603ead4b5daeabcdc4c19 (diff) | |
| parent | 527ae2230f5c2dd22f496f45d5d8e3bd4acdb854 (diff) | |
merge: Migrate to Quarkus-based web API
This pull request changes the web API to a Quarkus-based version. Currently, the OpenDC web API is written in Python (using Flask). Although Python is a powerful language to develop web services, having another language next to Kotlin/Java and JavaScript introduces some challenges.
For instance, the web API and UI lack integration with our Gradle-based build pipeline and require additional steps from the developer to start working with. Furthermore, deploying OpenDC requires having Python installed in addition to the JVM.
By converting the web API into a Quarkus application, we can enjoy further integration with our Gradle-based build pipeline and simplify the development/deployment process of OpenDC, by requiring only the JVM and Node to work with OpenDC.
## Implementation Notes :hammer_and_pick:
* Move build dependencies into version catalog
* Design unified communication protocol
* Add Quarkus API implementation
* Add new web client implementation
* Update runner to use new web client
* Fix compatibility with React.js UI
* Remove Python build steps from CI pipeline
* Update Docker deployment for new web API
* Remove obsolete database configuration
## External Dependencies :four_leaf_clover:
* Quarkus
## Breaking API Changes :warning:
* The new web API only supports SQL-based databases for storing user-data, as opposed to MongoDB currently. We intend to use H2 for development and Postgres for production.
Diffstat (limited to 'opendc-web/opendc-web-api/tests/api/test_projects.py')
| -rw-r--r-- | opendc-web/opendc-web-api/tests/api/test_projects.py | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/opendc-web/opendc-web-api/tests/api/test_projects.py b/opendc-web/opendc-web-api/tests/api/test_projects.py deleted file mode 100644 index 1cfe4c52..00000000 --- a/opendc-web/opendc-web-api/tests/api/test_projects.py +++ /dev/null @@ -1,197 +0,0 @@ -# Copyright (c) 2021 AtLarge Research -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -from opendc.exts import db - -test_id = 24 * '1' - - -def test_get_user_projects(client, mocker): - mocker.patch.object(db, 'fetch_all', return_value={'_id': test_id, 'authorizations': [{'userId': 'test', - 'level': 'OWN'}]}) - res = client.get('/projects/') - assert '200' in res.status - - -def test_get_user_topologies(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [{ - 'userId': 'test', - 'level': 'EDIT' - }] - }) - mocker.patch.object(db, 'fetch_all', return_value=[{'_id': test_id}]) - res = client.get(f'/projects/{test_id}/topologies') - assert '200' in res.status - - -def test_get_user_portfolios(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [{ - 'userId': 'test', - 'level': 'EDIT' - }] - }) - mocker.patch.object(db, 'fetch_all', return_value=[{'_id': test_id}]) - res = client.get(f'/projects/{test_id}/portfolios') - assert '200' in res.status - - -def test_add_project_missing_parameter(client): - assert '400' in client.post('/projects/').status - - -def test_add_project(client, mocker): - mocker.patch.object(db, 'fetch_one', return_value={'_id': test_id, 'authorizations': []}) - mocker.patch.object(db, - 'insert', - return_value={ - '_id': test_id, - 'datetimeCreated': '000', - 'datetimeLastEdited': '000', - 'topologyIds': [] - }) - mocker.patch.object(db, 'update', return_value={}) - res = client.post('/projects/', json={'project': {'name': 'test project'}}) - assert 'datetimeCreated' in res.json['data'] - assert 'datetimeLastEdited' in res.json['data'] - assert 'topologyIds' in res.json['data'] - assert '200' in res.status - - -def test_get_project_non_existing(client, mocker): - mocker.patch.object(db, 'fetch_one', return_value=None) - assert '404' in client.get(f'/projects/{test_id}').status - - -def test_get_project_no_authorizations(client, mocker): - mocker.patch.object(db, 'fetch_one', return_value={'authorizations': []}) - res = client.get(f'/projects/{test_id}') - assert '403' in res.status - - -def test_get_project_not_authorized(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [] - }) - res = client.get(f'/projects/{test_id}') - assert '403' in res.status - - -def test_get_project(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [{ - 'userId': 'test', - 'level': 'EDIT' - }] - }) - res = client.get(f'/projects/{test_id}') - assert '200' in res.status - - -def test_update_project_missing_parameter(client): - assert '400' in client.put(f'/projects/{test_id}').status - - -def test_update_project_non_existing(client, mocker): - mocker.patch.object(db, 'fetch_one', return_value=None) - assert '404' in client.put(f'/projects/{test_id}', json={'project': {'name': 'S'}}).status - - -def test_update_project_not_authorized(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [{ - 'userId': 'test', - 'level': 'VIEW' - }] - }) - mocker.patch.object(db, 'update', return_value={}) - assert '403' in client.put(f'/projects/{test_id}', json={'project': {'name': 'S'}}).status - - -def test_update_project(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'authorizations': [{ - 'userId': 'test', - 'level': 'OWN' - }] - }) - mocker.patch.object(db, 'update', return_value={}) - - res = client.put(f'/projects/{test_id}', json={'project': {'name': 'S'}}) - assert '200' in res.status - - -def test_delete_project_non_existing(client, mocker): - mocker.patch.object(db, 'fetch_one', return_value=None) - assert '404' in client.delete(f'/projects/{test_id}').status - - -def test_delete_project_different_user(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'googleId': 'other_test', - 'authorizations': [{ - 'userId': 'test', - 'level': 'VIEW' - }], - 'topologyIds': [] - }) - mocker.patch.object(db, 'delete_one', return_value=None) - assert '403' in client.delete(f'/projects/{test_id}').status - - -def test_delete_project(client, mocker): - mocker.patch.object(db, - 'fetch_one', - return_value={ - '_id': test_id, - 'googleId': 'test', - 'authorizations': [{ - 'userId': 'test', - 'level': 'OWN' - }], - 'topologyIds': [], - 'portfolioIds': [], - }) - mocker.patch.object(db, 'update', return_value=None) - mocker.patch.object(db, 'delete_one', return_value={'googleId': 'test'}) - res = client.delete(f'/projects/{test_id}') - assert '200' in res.status |
