vantage6-algorithm-store 4.15.1__tar.gz → 5.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. vantage6_algorithm_store-5.0.0/.gitignore +37 -0
  2. vantage6_algorithm_store-5.0.0/Makefile +22 -0
  3. vantage6_algorithm_store-5.0.0/PKG-INFO +53 -0
  4. vantage6_algorithm_store-5.0.0/README.md +25 -0
  5. vantage6_algorithm_store-5.0.0/dev_store.sh +37 -0
  6. vantage6_algorithm_store-5.0.0/pyproject.toml +48 -0
  7. vantage6_algorithm_store-5.0.0/server.sh +35 -0
  8. vantage6_algorithm_store-5.0.0/tests_store/base/unittest_base.py +149 -0
  9. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/resources/test_algorithm.py +194 -233
  10. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/resources/test_policy.py +35 -90
  11. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/resources/test_review.py +208 -238
  12. vantage6_algorithm_store-5.0.0/tests_store/resources/test_role.py +131 -0
  13. vantage6_algorithm_store-5.0.0/tests_store/resources/test_rule.py +40 -0
  14. vantage6_algorithm_store-5.0.0/tests_store/resources/test_user.py +183 -0
  15. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/resources/test_version.py +1 -2
  16. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/test___init__.py +23 -30
  17. vantage6_algorithm_store-5.0.0/tests_store/test_argument_schema.py +66 -0
  18. vantage6_algorithm_store-5.0.0/tests_store/test_link_algorithms.py +141 -0
  19. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/__init__.py +319 -0
  20. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/_data/unittest_config.yaml +8 -0
  21. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/_data/unittest_fixtures.yaml +0 -0
  22. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/algorithm_create.py +195 -0
  23. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/db.py +5 -5
  24. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/default_roles.py +8 -26
  25. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/globals.py +3 -4
  26. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/init_db.py +43 -0
  27. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/link_algorithms.py +285 -0
  28. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/__init__.py +8 -9
  29. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/algorithm.py +14 -12
  30. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/argument.py +5 -4
  31. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/base.py +6 -25
  32. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/common/enums.py +10 -46
  33. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/common/ui_visualization_schemas.py +2 -2
  34. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/database.py +5 -1
  35. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/function.py +5 -4
  36. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/permission.py +1 -1
  37. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/policy.py +23 -76
  38. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/review.py +3 -1
  39. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/role.py +12 -6
  40. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/role_rule_association.py +2 -2
  41. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/rule.py +16 -17
  42. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/ui_visualization.py +1 -1
  43. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/user.py +35 -57
  44. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/permission.py +18 -11
  45. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/resource/__init__.py +235 -0
  46. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/algorithm.py +95 -201
  47. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/policy.py +20 -27
  48. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/review.py +102 -82
  49. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/role.py +14 -117
  50. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/rule.py +23 -35
  51. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/schema/input_schema.py +87 -123
  52. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/schema/output_schema.py +8 -23
  53. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/user.py +41 -115
  54. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/resource/version.py +5 -3
  55. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/static/robots.txt +5 -0
  56. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/algorithm_review_finalized.html +206 -0
  57. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/algorithm_review_finalized.txt +9 -0
  58. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/new_algorithm.html +212 -0
  59. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/new_algorithm.txt +11 -0
  60. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/new_review.html +212 -0
  61. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/new_review.txt +11 -0
  62. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/review_no_longer_required.html +208 -0
  63. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/templates/mail/review_no_longer_required.txt +9 -0
  64. vantage6_algorithm_store-5.0.0/vantage6/algorithm/store/wsgi.py +18 -0
  65. vantage6_algorithm_store-4.15.1/PKG-INFO +0 -237
  66. vantage6_algorithm_store-4.15.1/setup.cfg +0 -4
  67. vantage6_algorithm_store-4.15.1/setup.py +0 -55
  68. vantage6_algorithm_store-4.15.1/tests_store/base/unittest_base.py +0 -117
  69. vantage6_algorithm_store-4.15.1/tests_store/resources/test_role.py +0 -190
  70. vantage6_algorithm_store-4.15.1/tests_store/resources/test_rule.py +0 -57
  71. vantage6_algorithm_store-4.15.1/tests_store/resources/test_user.py +0 -245
  72. vantage6_algorithm_store-4.15.1/tests_store/resources/test_v6server.py +0 -206
  73. vantage6_algorithm_store-4.15.1/tests_store/test_permission.py +0 -77
  74. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/__build__ +0 -1
  75. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/__init__.py +0 -519
  76. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/_version.py +0 -23
  77. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/model/vantage6_server.py +0 -80
  78. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/resource/__init__.py +0 -360
  79. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/resource/vantage6_server.py +0 -365
  80. vantage6_algorithm_store-4.15.1/vantage6/algorithm/store/wsgi.py +0 -17
  81. vantage6_algorithm_store-4.15.1/vantage6_algorithm_store.egg-info/PKG-INFO +0 -237
  82. vantage6_algorithm_store-4.15.1/vantage6_algorithm_store.egg-info/SOURCES.txt +0 -57
  83. vantage6_algorithm_store-4.15.1/vantage6_algorithm_store.egg-info/dependency_links.txt +0 -1
  84. vantage6_algorithm_store-4.15.1/vantage6_algorithm_store.egg-info/requires.txt +0 -17
  85. vantage6_algorithm_store-4.15.1/vantage6_algorithm_store.egg-info/top_level.txt +0 -2
  86. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/__init__.py +0 -0
  87. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/base/__init__.py +0 -0
  88. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/tests_store/resources/__init__.py +0 -0
  89. {vantage6_algorithm_store-4.15.1 → vantage6_algorithm_store-5.0.0}/vantage6/algorithm/store/model/allowed_argument_value.py +0 -0
@@ -0,0 +1,37 @@
1
+
2
+ # documentation
3
+ docs/_build
4
+ docs/api-docs/_autosummary
5
+
6
+ # Python
7
+ .ipynb_checkpoints
8
+ **/__pycache__
9
+ **/.coverage
10
+
11
+ # IDE's
12
+ .idea/
13
+ *.sublime-project
14
+ *.sublime-workspace
15
+ .vscode/
16
+
17
+ # build files
18
+ **/build/
19
+ **/dist/
20
+ *.egg-info
21
+ *.code-workspace
22
+
23
+ # UI build files
24
+ **/node_modules/
25
+
26
+ # Ignore DevSpace cache and log folder
27
+ .devspace/
28
+ dev/.data/
29
+ dev/.tasks/
30
+ dev/.db/
31
+ dev/.log/
32
+
33
+ # Helm
34
+ charts/**/*.tgz
35
+
36
+ # MacOS
37
+ .DS_Store
@@ -0,0 +1,22 @@
1
+ # `make` is expected to be called from the directory that contains
2
+ # this Makefile
3
+
4
+ TAG ?= latest
5
+
6
+ rebuild: clean build-dist
7
+
8
+ build-dist:
9
+ # Build the PyPI package
10
+ uv build
11
+
12
+ publish:
13
+ # Uploading to pypi.org
14
+ twine upload --repository pypi dist/*
15
+
16
+ test:
17
+ coverage run --source=vantage6 --omit="utest.py" ./utest.py
18
+
19
+ clean:
20
+ # Cleaning ...
21
+ -rm -r build
22
+ -rm dist/*
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: vantage6-algorithm-store
3
+ Version: 5.0.0
4
+ Summary: Vantage6 algorithm store
5
+ Author: Vantage6 Team
6
+ Maintainer-email: Frank Martin <f.martin@iknl.nl>, Bart van Beusekom <b.vanbeusekom@iknl.nl>
7
+ License: MIT
8
+ Requires-Python: >=3.13
9
+ Requires-Dist: flask-jwt-extended==4.7.1
10
+ Requires-Dist: flask-principal==0.4.0
11
+ Requires-Dist: flask-restful==0.3.10
12
+ Requires-Dist: flask==3.1.3
13
+ Requires-Dist: gevent==25.4.2
14
+ Requires-Dist: httpx==0.28.1
15
+ Requires-Dist: jsonschema==4.21.1
16
+ Requires-Dist: marshmallow==3.26.2
17
+ Requires-Dist: python-keycloak==5.5.0
18
+ Requires-Dist: requests==2.33.1
19
+ Requires-Dist: schema==0.7.5
20
+ Requires-Dist: sqlalchemy==2.0.37
21
+ Requires-Dist: vantage6-common==5.0.0
22
+ Requires-Dist: vantage6==5.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: black; extra == 'dev'
25
+ Requires-Dist: coverage==7.10.2; extra == 'dev'
26
+ Requires-Dist: pre-commit; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ <h1 align="center">
30
+ <br>
31
+ <a href="https://vantage6.ai"><img src="https://github.com/IKNL/guidelines/blob/master/resources/logos/vantage6.png?raw=true" alt="vantage6" width="350"></a>
32
+ </h1>
33
+
34
+ <h3 align=center> A Privacy Enhancing Technology (PET) Operations platform</h3>
35
+
36
+ ---
37
+
38
+ # Vantage6 Algorithm Store
39
+
40
+ This package contains the vantage6 algorithm store application.
41
+
42
+ ## Documentation
43
+
44
+ For complete documentation, installation instructions, and usage examples, please see
45
+ the **[main Vantage6 README](https://github.com/vantage6/vantage6/blob/main/README.md)**
46
+ .
47
+
48
+ ## About Vantage6
49
+
50
+ Vantage6 is a Privacy Enhancing Technology (PET) Operations platform that enables
51
+ federated learning and multi-party computation. For more information, visit
52
+ [vantage6.ai](https://vantage6.ai) or view our
53
+ [documentation](https://docs.vantage6.ai).
@@ -0,0 +1,25 @@
1
+ <h1 align="center">
2
+ <br>
3
+ <a href="https://vantage6.ai"><img src="https://github.com/IKNL/guidelines/blob/master/resources/logos/vantage6.png?raw=true" alt="vantage6" width="350"></a>
4
+ </h1>
5
+
6
+ <h3 align=center> A Privacy Enhancing Technology (PET) Operations platform</h3>
7
+
8
+ ---
9
+
10
+ # Vantage6 Algorithm Store
11
+
12
+ This package contains the vantage6 algorithm store application.
13
+
14
+ ## Documentation
15
+
16
+ For complete documentation, installation instructions, and usage examples, please see
17
+ the **[main Vantage6 README](https://github.com/vantage6/vantage6/blob/main/README.md)**
18
+ .
19
+
20
+ ## About Vantage6
21
+
22
+ Vantage6 is a Privacy Enhancing Technology (PET) Operations platform that enables
23
+ federated learning and multi-party computation. For more information, visit
24
+ [vantage6.ai](https://vantage6.ai) or view our
25
+ [documentation](https://docs.vantage6.ai).
@@ -0,0 +1,37 @@
1
+ #!/bin/sh
2
+
3
+ echo "*********************************************************************************"
4
+ echo "********************* VANTAGE6 STORE DEVELOPMENT MODE ***************************"
5
+ echo "*********************************************************************************"
6
+
7
+ # check if environment variable is set
8
+ if [ -z "$VANTAGE6_STORE_CONFIG_LOCATION" ]; then
9
+ echo "VANTAGE6_STORE_CONFIG_LOCATION is not set"
10
+ echo " using default location /mnt/config.yaml"
11
+ VANTAGE6_STORE_CONFIG_LOCATION="/mnt/config.yaml"
12
+ fi
13
+
14
+
15
+ # Run from repo root so module imports don't shadow stdlib modules.
16
+ cd /vantage6
17
+
18
+ python -m vantage6.algorithm.store.init_db "${VANTAGE6_STORE_CONFIG_LOCATION}"
19
+ status=$?
20
+ if [ "$status" -ne 0 ]; then
21
+ echo "ERROR: failed to initialize algorithm store database" >&2
22
+ exit "$status"
23
+ fi
24
+
25
+ exec uwsgi \
26
+ --py-autoreload 1 \
27
+ --reload-mercy 1 \
28
+ --gevent 100 \
29
+ --http-websockets \
30
+ --http :7602 \
31
+ --master \
32
+ --callable app \
33
+ --disable-logging \
34
+ --wsgi-file /vantage6/vantage6-algorithm-store/vantage6/algorithm/store/wsgi.py \
35
+ --pyargv "${VANTAGE6_STORE_CONFIG_LOCATION}"
36
+
37
+ echo "exit dev_store.sh"
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "vantage6-algorithm-store"
7
+ version = "5.0.0"
8
+ description = "Vantage6 algorithm store"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "Vantage6 Team"}
13
+ ]
14
+ maintainers = [
15
+ {name = "Frank Martin", email = "f.martin@iknl.nl"},
16
+ {name = "Bart van Beusekom", email = "b.vanbeusekom@iknl.nl"}
17
+ ]
18
+ requires-python = ">=3.13"
19
+ dependencies = [
20
+ "flask==3.1.3",
21
+ "Flask-JWT-Extended==4.7.1",
22
+ "Flask-Principal==0.4.0",
23
+ "Flask-RESTful==0.3.10",
24
+ "gevent==25.4.2",
25
+ # TODO remove httpx once 1.0.0 is released - atm this is added to prevent 1.0.dev3 is installed
26
+ "httpx==0.28.1",
27
+ "jsonschema==4.21.1",
28
+ "marshmallow==3.26.2",
29
+ "python-keycloak==5.5.0",
30
+ "requests==2.33.1",
31
+ "schema==0.7.5",
32
+ "sqlalchemy==2.0.37",
33
+ "vantage6-common==5.0.0",
34
+ "vantage6==5.0.0",
35
+ ]
36
+
37
+ [project.optional-dependencies]
38
+ dev = [
39
+ "coverage==7.10.2",
40
+ "black",
41
+ "pre-commit",
42
+ ]
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["vantage6"]
46
+
47
+ [tool.hatch.build.targets.wheel.sources]
48
+ "vantage6" = "vantage6"
@@ -0,0 +1,35 @@
1
+ #!/bin/sh
2
+
3
+ echo "[server.sh start]"
4
+
5
+ HTTP_PORT="${V6_PROXY_PORT:-80}"
6
+ GEVENT="${UWSGI_GEVENT:-100}"
7
+
8
+ # check if environment variable is set
9
+ if [ -z "$VANTAGE6_CONFIG_LOCATION" ]; then
10
+ echo "VANTAGE6_CONFIG_LOCATION is not set"
11
+ echo " using default location /mnt/config.yaml"
12
+ VANTAGE6_CONFIG_LOCATION="/mnt/config.yaml"
13
+ fi
14
+
15
+
16
+ # initialize the database
17
+ python -m vantage6.algorithm.store.init_db "${VANTAGE6_CONFIG_LOCATION}"
18
+ status=$?
19
+ if [ "$status" -ne 0 ]; then
20
+ echo "ERROR: failed to initialize algorithm store database" >&2
21
+ exit "$status"
22
+ fi
23
+
24
+ # start the algorithm store
25
+ exec uwsgi \
26
+ --http ":${HTTP_PORT}" \
27
+ --gevent "${GEVENT}" \
28
+ --http-websockets \
29
+ --master \
30
+ --callable app \
31
+ --disable-logging \
32
+ --wsgi-file /vantage6/vantage6-algorithm-store/vantage6/algorithm/store/wsgi.py \
33
+ --pyargv "${VANTAGE6_CONFIG_LOCATION}"
34
+
35
+ echo "[server.sh exit]"
@@ -0,0 +1,149 @@
1
+ import os
2
+ import unittest
3
+ from http import HTTPStatus
4
+ from unittest.mock import Mock, patch
5
+
6
+ from cryptography.hazmat.backends import default_backend
7
+ from cryptography.hazmat.primitives import serialization
8
+ from cryptography.hazmat.primitives.asymmetric import rsa
9
+
10
+ from vantage6.common.globals import InstanceType
11
+
12
+ from vantage6.backend.common import test_context
13
+
14
+ from vantage6.algorithm.store import AlgorithmStoreApp
15
+ from vantage6.algorithm.store.default_roles import get_default_roles
16
+ from vantage6.algorithm.store.globals import PACKAGE_FOLDER
17
+ from vantage6.algorithm.store.model.base import Database, DatabaseSessionManager
18
+ from vantage6.algorithm.store.model.policy import Policy
19
+ from vantage6.algorithm.store.model.review import Review
20
+ from vantage6.algorithm.store.model.role import Role
21
+ from vantage6.algorithm.store.model.rule import Rule
22
+ from vantage6.algorithm.store.model.user import User
23
+
24
+ # Generate a mock RSA key pair for testing
25
+ MOCK_PRIVATE_KEY = rsa.generate_private_key(
26
+ public_exponent=65537, key_size=2048, backend=default_backend()
27
+ )
28
+ MOCK_PUBLIC_KEY = MOCK_PRIVATE_KEY.public_key()
29
+ MOCK_PRIVATE_KEY_PEM = MOCK_PRIVATE_KEY.private_bytes(
30
+ encoding=serialization.Encoding.PEM,
31
+ format=serialization.PrivateFormat.PKCS8,
32
+ encryption_algorithm=serialization.NoEncryption(),
33
+ )
34
+ MOCK_PUBLIC_KEY_PEM = MOCK_PUBLIC_KEY.public_bytes(
35
+ encoding=serialization.Encoding.PEM,
36
+ format=serialization.PublicFormat.SubjectPublicKeyInfo,
37
+ )
38
+
39
+
40
+ class TestResources(unittest.TestCase):
41
+ @classmethod
42
+ def setUpClass(cls):
43
+ """Called immediately before running a test method."""
44
+
45
+ Database().connect("sqlite://", allow_drop_all=True)
46
+
47
+ ctx = test_context.TestContext.from_external_config_file(
48
+ PACKAGE_FOLDER, InstanceType.ALGORITHM_STORE
49
+ )
50
+
51
+ # set required environment variables *before* creating the app
52
+ os.environ["KEYCLOAK_URL"] = "dummy-keycloak-url"
53
+ os.environ["KEYCLOAK_REALM"] = "dummy-keycloak-realm"
54
+ os.environ["KEYCLOAK_ADMIN_USERNAME"] = "dummy-keycloak-admin-username"
55
+ os.environ["KEYCLOAK_ADMIN_PASSWORD"] = "dummy-keycloak-admin-password"
56
+ os.environ["KEYCLOAK_ADMIN_CLIENT"] = "dummy-keycloak-admin-client"
57
+ os.environ["KEYCLOAK_ADMIN_CLIENT_SECRET"] = (
58
+ "dummy-keycloak-admin-client-secret"
59
+ )
60
+
61
+ # Mock the Keycloak public key fetch
62
+ with patch(
63
+ "vantage6.algorithm.store.AlgorithmStoreApp._get_keycloak_public_key"
64
+ ) as mock_get_key:
65
+ mock_get_key.return_value = MOCK_PUBLIC_KEY_PEM.decode()
66
+ # create store instance. Patch the start_background_task method
67
+ # to prevent the store from starting a ping/pong thread that will
68
+ # prevent the tests from starting
69
+ backend_service = AlgorithmStoreApp(ctx)
70
+ # Configure JWT for container tokens
71
+ backend_service.app.config["JWT_PRIVATE_KEY"] = MOCK_PRIVATE_KEY_PEM
72
+ backend_service.app.config["JWT_PUBLIC_KEY"] = MOCK_PUBLIC_KEY_PEM
73
+
74
+ cls.backend = backend_service
75
+ cls.backend.app.testing = True
76
+ cls.app = cls.backend.app.test_client()
77
+
78
+ @classmethod
79
+ def tearDownClass(cls):
80
+ Database().clear_data()
81
+ Database().close()
82
+
83
+ @classmethod
84
+ def setUp(cls):
85
+ # set session.session
86
+ DatabaseSessionManager.get_session()
87
+
88
+ @classmethod
89
+ def tearDown(cls):
90
+ # delete resources from database
91
+ policies_to_delete = Policy.get()
92
+ for p in policies_to_delete:
93
+ p.delete()
94
+ users_to_delete = User.get()
95
+ for u in users_to_delete:
96
+ u.delete()
97
+ roles_to_delete = Role.get()
98
+ for r in roles_to_delete:
99
+ r.delete()
100
+ reviews_to_delete = Review.get()
101
+ for r in reviews_to_delete:
102
+ r.delete()
103
+
104
+ # unset session.session
105
+ DatabaseSessionManager.clear_session()
106
+
107
+ def register_user(
108
+ self,
109
+ username: str = "test_user",
110
+ user_roles: list[Role] = None,
111
+ user_rules: list[Rule] = None,
112
+ organization_id: int = 1,
113
+ authenticate_mock: Mock = None,
114
+ auth: bool = True,
115
+ ) -> User:
116
+ user = User(username=username, organization_id=organization_id)
117
+ if user_roles and len(user_roles) > 0:
118
+ user.roles = user_roles
119
+ if user_rules and len(user_rules) > 0:
120
+ user.rules = user_rules
121
+ user.save()
122
+ if authenticate_mock:
123
+ self._mock_auth(user, authenticate_mock, auth)
124
+ return user
125
+
126
+ def _mock_auth(self, user: User, authenticate_mock: Mock, auth: bool):
127
+ authenticate_mock.return_value = (
128
+ (user, HTTPStatus.OK)
129
+ if auth
130
+ else ({"msg": "Unauthorized"}, HTTPStatus.UNAUTHORIZED)
131
+ )
132
+
133
+ def create_role(self, rules: list[Rule], name: str = "test_role") -> Role:
134
+ role = Role(name=name, rules=rules)
135
+ role.save()
136
+ return role
137
+
138
+ def assign_role_to_user(self, user: User, role: Role):
139
+ user.roles.append(role)
140
+ user.save()
141
+
142
+ def create_default_roles(self) -> list[Role]:
143
+ for role in get_default_roles():
144
+ new_role = Role(
145
+ name=role["name"],
146
+ description=role["description"],
147
+ rules=role["rules"],
148
+ )
149
+ new_role.save()