|
| 1 | +"""Tenant ID handling in OpenAEV configuration feature tests.""" |
| 2 | + |
| 3 | +from uuid import UUID |
| 4 | + |
| 5 | +import pytest |
| 6 | +from pydantic import ValidationError |
| 7 | +from pytest_bdd import given, parsers, scenario, then, when |
| 8 | + |
| 9 | +from pyoaev.configuration.settings_loader import ConfigLoaderOAEV |
| 10 | + |
| 11 | +# -------------------------------------------------- |
| 12 | +# SCENARIOS |
| 13 | +# -------------------------------------------------- |
| 14 | + |
| 15 | + |
| 16 | +@scenario( |
| 17 | + "multi_tenant_validation_uuid_constraint.feature", |
| 18 | + "tenant_id is a valid UUID", |
| 19 | +) |
| 20 | +def test_tenant_id_is_a_valid_uuid(): |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +@scenario( |
| 25 | + "multi_tenant_validation_uuid_constraint.feature", |
| 26 | + "tenant_id is explicitly set to None", |
| 27 | +) |
| 28 | +def test_tenant_id_is_explicitly_set_to_none(): |
| 29 | + pass |
| 30 | + |
| 31 | + |
| 32 | +@scenario( |
| 33 | + "multi_tenant_validation_uuid_constraint.feature", |
| 34 | + "tenant_id is invalid and should raise a validation error", |
| 35 | +) |
| 36 | +def test_tenant_id_is_invalid_and_should_raise_a_validation_error(): |
| 37 | + pass |
| 38 | + |
| 39 | + |
| 40 | +@scenario( |
| 41 | + "multi_tenant_validation_uuid_constraint.feature", |
| 42 | + "tenant_id is not provided", |
| 43 | +) |
| 44 | +def test_tenant_id_is_not_provided(): |
| 45 | + pass |
| 46 | + |
| 47 | + |
| 48 | +# -------------------------------------------------- |
| 49 | +# GIVEN |
| 50 | +# -------------------------------------------------- |
| 51 | + |
| 52 | + |
| 53 | +@given( |
| 54 | + "a configuration without tenant_id", |
| 55 | + target_fixture="config", |
| 56 | +) |
| 57 | +def config_without(): |
| 58 | + return { |
| 59 | + "url": "https://example.com", |
| 60 | + "token": "token", |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | +@given( |
| 65 | + "a configuration with tenant_id set to None", |
| 66 | + target_fixture="config", |
| 67 | +) |
| 68 | +def config_none(): |
| 69 | + return { |
| 70 | + "url": "https://example.com", |
| 71 | + "token": "token", |
| 72 | + "tenant_id": None, |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | +@given( |
| 77 | + parsers.parse('a configuration with tenant_id "{tenant_id}" invalid'), |
| 78 | + target_fixture="config", |
| 79 | +) |
| 80 | +def config_with_tenant_invalid(tenant_id): |
| 81 | + return { |
| 82 | + "url": "https://example.com", |
| 83 | + "token": "token", |
| 84 | + "tenant_id": tenant_id, |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | +@given( |
| 89 | + 'a configuration with tenant_id "2cffad3a-0001-4078-b0e2-ef74274022c3"', |
| 90 | + target_fixture="config", |
| 91 | +) |
| 92 | +def config_with_tenant_valid(): |
| 93 | + return { |
| 94 | + "url": "https://example.com", |
| 95 | + "token": "token", |
| 96 | + "tenant_id": "2cffad3a-0001-4078-b0e2-ef74274022c3", |
| 97 | + } |
| 98 | + |
| 99 | + |
| 100 | +# -------------------------------------------------- |
| 101 | +# WHEN |
| 102 | +# -------------------------------------------------- |
| 103 | + |
| 104 | + |
| 105 | +@when( |
| 106 | + "the configuration is loaded", |
| 107 | + target_fixture="result", |
| 108 | +) |
| 109 | +def load_config(config): |
| 110 | + try: |
| 111 | + return ConfigLoaderOAEV(**config) |
| 112 | + except ValidationError as err: |
| 113 | + return err |
| 114 | + |
| 115 | + |
| 116 | +# -------------------------------------------------- |
| 117 | +# THEN |
| 118 | +# -------------------------------------------------- |
| 119 | + |
| 120 | + |
| 121 | +@then("tenant_id should be None") |
| 122 | +def assert_none(result): |
| 123 | + assert result.tenant_id is None |
| 124 | + |
| 125 | + |
| 126 | +@then("tenant_id should be a valid UUID") |
| 127 | +def assert_uuid(result): |
| 128 | + assert isinstance(result.tenant_id, UUID) |
| 129 | + |
| 130 | + |
| 131 | +@then("a validation error should be raised") |
| 132 | +def assert_validation_error(result): |
| 133 | + assert isinstance(result, ValidationError) |
0 commit comments