-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test_base_resource.py
58 lines (47 loc) · 2.25 KB
/
test_base_resource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from dataclasses import dataclass
import pytest
from dbt.artifacts.resources.base import BaseResource
from dbt.artifacts.resources.types import NodeType
@dataclass
class BaseResourceWithDefaultField(BaseResource):
field_with_default: bool = True
class TestMinorSchemaChange:
@pytest.fixture
def base_resource(self):
return BaseResource(
name="test",
resource_type=NodeType.Model,
package_name="test_package",
path="test_path",
original_file_path="test_original_file_path",
unique_id="test_unique_id",
)
@pytest.fixture
def base_resource_new_default_field(self):
return BaseResourceWithDefaultField(
name="test",
resource_type=NodeType.Model,
package_name="test_package",
path="test_path",
original_file_path="test_original_file_path",
unique_id="test_unique_id",
field_with_default=False,
)
def test_serializing_new_default_field_is_backward_compatabile(
self, base_resource_new_default_field
):
# old code (using old class) can create an instance of itself given new data (new class)
BaseResource.from_dict(base_resource_new_default_field.to_dict())
def test_serializing_new_default_field_is_forward_compatible(self, base_resource):
# new code (using new class) can create an instance of itself given old data (old class)
BaseResourceWithDefaultField.from_dict(base_resource.to_dict())
def test_serializing_removed_default_field_is_backward_compatabile(self, base_resource):
# old code (using old class with default field) can create an instance of itself given new data (class w/o default field)
old_resource = BaseResourceWithDefaultField.from_dict(base_resource.to_dict())
# set to the default value when not provided in data
assert old_resource.field_with_default is True
def test_serializing_removed_default_field_is_forward_compatible(
self, base_resource_new_default_field
):
# new code (using class without default field) can create an instance of itself given old data (class with old field)
BaseResource.from_dict(base_resource_new_default_field.to_dict())