|
| 1 | +""" |
| 2 | +Copyright (c) 2022, Oracle and/or its affiliates. |
| 3 | +Copyright (c) 2020, Vitor Avancini |
| 4 | +
|
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + you may not use this file except in compliance with the License. |
| 7 | + You may obtain a copy of the License at |
| 8 | +
|
| 9 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +""" |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | +from dbt.tests.adapter.grants.test_model_grants import BaseModelGrants, model_schema_yml |
| 21 | +from dbt.tests.adapter.grants.test_incremental_grants import BaseIncrementalGrants, incremental_model_schema_yml |
| 22 | +from dbt.tests.adapter.grants.test_invalid_grants import BaseInvalidGrants |
| 23 | +from dbt.tests.adapter.grants.test_seed_grants import BaseSeedGrants |
| 24 | +from dbt.tests.adapter.grants.test_snapshot_grants import BaseSnapshotGrants, snapshot_schema_yml |
| 25 | + |
| 26 | +my_model_sql = """ |
| 27 | + select 1 as fun from dual |
| 28 | +""" |
| 29 | + |
| 30 | +my_incremental_model_sql = """ |
| 31 | + select 1 as fun from dual |
| 32 | +""" |
| 33 | + |
| 34 | +my_invalid_model_sql = """ |
| 35 | + select 1 as fun from dual |
| 36 | +""" |
| 37 | + |
| 38 | +my_snapshot_sql = """ |
| 39 | +{% snapshot my_snapshot %} |
| 40 | + {{ config( |
| 41 | + check_cols='all', unique_key='id', strategy='check', |
| 42 | + target_database=database, target_schema=schema |
| 43 | + ) }} |
| 44 | + select 1 as id, cast('blue' as {{ type_string() }}) as color from dual |
| 45 | +{% endsnapshot %} |
| 46 | +""".strip() |
| 47 | + |
| 48 | + |
| 49 | +class TestSeedGrantsOracle(BaseSeedGrants): |
| 50 | + pass |
| 51 | + |
| 52 | + |
| 53 | +class TestModelGrantsOracle(BaseModelGrants): |
| 54 | + |
| 55 | + @pytest.fixture(scope="class") |
| 56 | + def models(self): |
| 57 | + updated_schema = self.interpolate_name_overrides(model_schema_yml) |
| 58 | + |
| 59 | + return { |
| 60 | + "my_model.sql": my_model_sql, |
| 61 | + "schema.yml": updated_schema, |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | +class TestIncrementalGrantsOracle(BaseIncrementalGrants): |
| 66 | + |
| 67 | + @pytest.fixture(scope="class") |
| 68 | + def models(self): |
| 69 | + updated_schema = self.interpolate_name_overrides(incremental_model_schema_yml) |
| 70 | + return { |
| 71 | + "my_incremental_model.sql": my_incremental_model_sql, |
| 72 | + "schema.yml": updated_schema, |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | +class TestInvalidGrantsOracle(BaseInvalidGrants): |
| 77 | + |
| 78 | + def grantee_does_not_exist_error(self): |
| 79 | + return "ORA-01917: user or role" |
| 80 | + |
| 81 | + def privilege_does_not_exist_error(self): |
| 82 | + return "ORA-00990: missing or invalid privilege" |
| 83 | + |
| 84 | + @pytest.fixture(scope="class") |
| 85 | + def models(self): |
| 86 | + return { |
| 87 | + "my_invalid_model.sql": my_invalid_model_sql, |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | +class TestSnapshotGrantsOracle(BaseSnapshotGrants): |
| 92 | + |
| 93 | + @pytest.fixture(scope="class") |
| 94 | + def snapshots(self): |
| 95 | + return { |
| 96 | + "my_snapshot.sql": my_snapshot_sql, |
| 97 | + "schema.yml": self.interpolate_name_overrides(snapshot_schema_yml), |
| 98 | + } |
0 commit comments