-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test minor artifact changes for backward + forward compatability (#10066
- Loading branch information
1 parent
29b8359
commit 3e8f2f1
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,57 @@ | ||
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()) |