-
Notifications
You must be signed in to change notification settings - Fork 6
[clientpython] feat(pyoaev): add multi-tenancy (#205) #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e3ed3f
[client-python] feat(pyoaev): add multi-tenancy (#205)
Megafredo 81073c2
[client-python] Add tests multi-tenant
Megafredo 3ec2d22
[client-python] Adding and Updating multi-tenant tests
Megafredo 1ed3ba4
[client-python] Updating test
Megafredo 601ebff
[client-python] Up linter
Megafredo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/bdd/constraints/multi_tenant_api_routing_constraint.feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Feature: URL normalization in OpenAEV client | ||
|
|
||
| Scenario Outline: URL normalization combines base_url and path correctly | ||
| Given an OpenAEV client with base_url "<base_url>" | ||
| When I build the URL for "<path>" | ||
| Then the resulting URL should be "<expected>" | ||
|
|
||
| Examples: | ||
| | base_url | path | expected | | ||
| | base_url | path | base_url/api/path | | ||
| | base_url/ | /path | base_url/api/path | | ||
| | base_url// | //path | base_url/api/path | |
30 changes: 30 additions & 0 deletions
30
test/bdd/constraints/multi_tenant_validation_uuid_constraint.feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| Feature: Tenant ID handling in OpenAEV configuration | ||
|
|
||
| Scenario: tenant_id is not provided | ||
| Given a configuration without tenant_id | ||
| When the configuration is loaded | ||
| Then tenant_id should be None | ||
|
|
||
|
|
||
| Scenario: tenant_id is explicitly set to None | ||
| Given a configuration with tenant_id set to None | ||
| When the configuration is loaded | ||
| Then tenant_id should be None | ||
|
|
||
|
|
||
| Scenario Outline: tenant_id is invalid and should raise a validation error | ||
| Given a configuration with tenant_id "<tenant_id>" invalid | ||
| When the configuration is loaded | ||
| Then a validation error should be raised | ||
|
|
||
| Examples: | ||
| | tenant_id | | ||
| | ChangeMe | | ||
| | "" | | ||
| | 550-e29-41d-a71-446 | | ||
|
|
||
|
|
||
| Scenario: tenant_id is a valid UUID | ||
| Given a configuration with tenant_id "2cffad3a-0001-4078-b0e2-ef74274022c3" | ||
| When the configuration is loaded | ||
| Then tenant_id should be a valid UUID |
63 changes: 63 additions & 0 deletions
63
test/bdd/constraints/test_multi_tenant_api_routing_constraint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """URL normalization in OpenAEV client feature tests.""" | ||
|
|
||
| import pytest | ||
| from pytest_bdd import given, parsers, scenario, then, when | ||
|
|
||
| from pyoaev import OpenAEV | ||
|
|
||
| # -------------------------------------------------- | ||
| # SCENARIOS | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @scenario( | ||
| "multi_tenant_api_routing_constraint.feature", | ||
| "URL normalization combines base_url and path correctly", | ||
| ) | ||
| def test_url_normalization(): | ||
| pass | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # FIXTURE CONTEXT | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def context(): | ||
| return {} | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # GIVEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @given(parsers.parse('an OpenAEV client with base_url "{base_url}"')) | ||
| def client(context, base_url): | ||
| context["client"] = OpenAEV( | ||
| url=base_url, | ||
| token="token", | ||
| tenant_id=None, | ||
| ) | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # WHEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @when(parsers.parse('I build the URL for "{path}"')) | ||
| def build_url(context, path): | ||
| client = context["client"] | ||
| context["result"] = client._build_url(path) | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # THEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @then(parsers.parse('the resulting URL should be "{expected}"')) | ||
| def check_url(context, expected): | ||
| assert context["result"] == expected |
132 changes: 132 additions & 0 deletions
132
test/bdd/constraints/test_multi_tenant_validation_uuid_constraint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| """Tenant ID handling in OpenAEV configuration feature tests.""" | ||
|
|
||
| from uuid import UUID | ||
|
|
||
| from pydantic import ValidationError | ||
| from pytest_bdd import given, parsers, scenario, then, when | ||
|
|
||
| from pyoaev.configuration.settings_loader import ConfigLoaderOAEV | ||
|
|
||
| # -------------------------------------------------- | ||
| # SCENARIOS | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @scenario( | ||
| "multi_tenant_validation_uuid_constraint.feature", | ||
| "tenant_id is a valid UUID", | ||
| ) | ||
| def test_tenant_id_is_a_valid_uuid(): | ||
| pass | ||
|
|
||
|
|
||
| @scenario( | ||
| "multi_tenant_validation_uuid_constraint.feature", | ||
| "tenant_id is explicitly set to None", | ||
| ) | ||
| def test_tenant_id_is_explicitly_set_to_none(): | ||
| pass | ||
|
|
||
|
|
||
| @scenario( | ||
| "multi_tenant_validation_uuid_constraint.feature", | ||
| "tenant_id is invalid and should raise a validation error", | ||
| ) | ||
| def test_tenant_id_is_invalid_and_should_raise_a_validation_error(): | ||
| pass | ||
|
|
||
|
|
||
| @scenario( | ||
| "multi_tenant_validation_uuid_constraint.feature", | ||
| "tenant_id is not provided", | ||
| ) | ||
| def test_tenant_id_is_not_provided(): | ||
| pass | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # GIVEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @given( | ||
| "a configuration without tenant_id", | ||
| target_fixture="config", | ||
| ) | ||
| def config_without(): | ||
| return { | ||
| "url": "https://example.com", | ||
| "token": "token", | ||
| } | ||
|
|
||
|
|
||
| @given( | ||
| "a configuration with tenant_id set to None", | ||
| target_fixture="config", | ||
| ) | ||
| def config_none(): | ||
| return { | ||
| "url": "https://example.com", | ||
| "token": "token", | ||
| "tenant_id": None, | ||
| } | ||
|
|
||
|
|
||
| @given( | ||
| parsers.parse('a configuration with tenant_id "{tenant_id}" invalid'), | ||
| target_fixture="config", | ||
| ) | ||
| def config_with_tenant_invalid(tenant_id): | ||
| return { | ||
| "url": "https://example.com", | ||
| "token": "token", | ||
| "tenant_id": tenant_id, | ||
| } | ||
|
|
||
|
|
||
| @given( | ||
| 'a configuration with tenant_id "2cffad3a-0001-4078-b0e2-ef74274022c3"', | ||
| target_fixture="config", | ||
| ) | ||
| def config_with_tenant_valid(): | ||
| return { | ||
| "url": "https://example.com", | ||
| "token": "token", | ||
| "tenant_id": "2cffad3a-0001-4078-b0e2-ef74274022c3", | ||
| } | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # WHEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @when( | ||
| "the configuration is loaded", | ||
| target_fixture="result", | ||
| ) | ||
| def load_config(config): | ||
| try: | ||
| return ConfigLoaderOAEV(**config) | ||
| except ValidationError as err: | ||
| return err | ||
|
|
||
|
|
||
| # -------------------------------------------------- | ||
| # THEN | ||
| # -------------------------------------------------- | ||
|
|
||
|
|
||
| @then("tenant_id should be None") | ||
| def assert_none(result): | ||
| assert result.tenant_id is None | ||
|
|
||
|
|
||
| @then("tenant_id should be a valid UUID") | ||
| def assert_uuid(result): | ||
| assert isinstance(result.tenant_id, UUID) | ||
|
|
||
|
|
||
| @then("a validation error should be raised") | ||
| def assert_validation_error(result): | ||
| assert isinstance(result, ValidationError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Feature: Multi-tenant API routing in OpenAEV client | ||
|
|
||
| Scenario: Full URL bypasses tenant routing | ||
| Given an OpenAEV client with any tenant configuration | ||
| When I build the URL for "https://external.service/api/path" | ||
| Then the resulting URL should be "https://external.service/api/path" | ||
|
|
||
|
|
||
| Scenario Outline: Relative path routing depends on tenant configuration | ||
| Given an OpenAEV client with tenant_id "<tenant_id>" | ||
| When I build the URL for "/path" | ||
| Then the resulting URL should be "<output>" | ||
|
|
||
| Examples: | ||
| | tenant_id | output | | ||
| | None | base_url/api/path | | ||
| | 2cffad3a-0001-4078-b0e2-ef74274022c3 | base_url/api/tenants/2cffad3a-0001-4078-b0e2-ef74274022c3/path | |
12 changes: 12 additions & 0 deletions
12
test/bdd/features/multi_tenant_base_daemon_propagation.feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Feature: Tenant propagation in BaseDaemon API client initialization | ||
|
|
||
| Scenario Outline: BaseDaemon propagates tenant_id correctly from configuration | ||
| Given a daemon configuration with "<tenant_case>" | ||
| When the BaseDaemon is initialized | ||
| Then the API client should be created with tenant_id "<expected_tenant_id>" | ||
|
|
||
| Examples: | ||
| | tenant_case | expected_tenant_id | | ||
| | missing_key | None | | ||
| | explicit_none | None | | ||
| | valid_uuid | 2cffad3a-0001-4078-b0e2-ef74274022c3 | |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a constraint 'tenant_id is not a valid uuid4' ?