Skip to content

Commit

Permalink
add test for dupe exposures and dupe model/exposure name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley committed Jan 13, 2021
1 parent d82a07c commit c14e6f4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 71 deletions.
2 changes: 1 addition & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def parse_file(self, block: FileBlock) -> None:
elif key == NodeType.Analysis:
parser = AnalysisPatchParser(self, yaml_block, plural)
elif key == NodeType.Exposure:
# handle exposures seperately, but they are
# handle exposures separately, but they are
# technically still "documentable"
continue
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
exposures:
- name: something
type: dashboard
owner:
email: [email protected]
- name: something
type: dashboard
owner:
email: [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
models:
- name: something
description: This table has basic information about orders, as well as some derived facts based on payments
exposures:
- name: something
type: dashboard
owner:
email: [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from dbt.exceptions import CompilationException
from test.integration.base import DBTIntegrationTest, use_profile


class TestDuplicateExposure(DBTIntegrationTest):

@property
def schema(self):
return "duplicate_exposure_025"

@property
def models(self):
return "models-exposure-dupes"

@use_profile("postgres")
def test_postgres_duplicate_exposure(self):
# message = "dbt found two resources with the name"
try:
self.run_dbt(["compile"])
self.assertTrue(False, "dbt did not throw for duplicate exposures")
except CompilationException as e:
pass
# self.assertTrue(message in str(
# e), "dbt did not throw the correct error message")
46 changes: 4 additions & 42 deletions test/integration/025_duplicate_model_test/test_duplicate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,15 @@ def schema(self):
def models(self):
return "models-1"

@property
def profile_config(self):
return {
"test": {
"outputs": {
"dev": {
"type": "postgres",
"threads": 1,
"host": self.database_host,
"port": 5432,
"user": "root",
"pass": "password",
"dbname": "dbt",
"schema": self.unique_schema()
},
},
"target": "dev"
}
}

@use_profile("postgres")
def test_postgres_duplicate_model_enabled(self):
message = "dbt found two resources with the name"
try:
self.run_dbt(["run"])
self.assertTrue(False, "dbt did not throw for duplicate models")
except CompilationException as e:
self.assertTrue(message in str(e), "dbt did not throw the correct error message")
self.assertTrue(message in str(
e), "dbt did not throw the correct error message")


class TestDuplicateModelDisabled(DBTIntegrationTest):
Expand All @@ -52,26 +33,6 @@ def schema(self):
def models(self):
return "models-2"

@property
def profile_config(self):
return {
"test": {
"outputs": {
"dev": {
"type": "postgres",
"threads": 1,
"host": self.database_host,
"port": 5432,
"user": "root",
"pass": "password",
"dbname": "dbt",
"schema": self.unique_schema()
},
},
"target": "dev"
}
}

@use_profile("postgres")
def test_postgres_duplicate_model_disabled(self):
try:
Expand Down Expand Up @@ -124,7 +85,8 @@ def test_postgres_duplicate_model_enabled_across_packages(self):
self.run_dbt(["run"])
self.assertTrue(False, "dbt did not throw for duplicate models")
except CompilationException as e:
self.assertTrue(message in str(e), "dbt did not throw the correct error message")
self.assertTrue(message in str(
e), "dbt did not throw the correct error message")


class TestDuplicateModelDisabledAcrossPackages(DBTIntegrationTest):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from dbt.exceptions import CompilationException
from test.integration.base import DBTIntegrationTest, use_profile


class TestDuplicateSchemaResource(DBTIntegrationTest):

@property
def schema(self):
return "duplicate_resource_025"

@property
def models(self):
return "models-naming-dupes-1"

@use_profile("postgres")
def test_postgres_duplicate_model_and_exposure(self):
try:
self.run_dbt(["compile"])
except CompilationException:
self.fail("Compilation Exception raised on model and "
"exposure with the same name")
25 changes: 3 additions & 22 deletions test/integration/025_duplicate_model_test/test_duplicate_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,12 @@ def schema(self):
def models(self):
return "models-source-dupes"

@property
def profile_config(self):
return {
"test": {
"outputs": {
"dev": {
"type": "postgres",
"threads": 1,
"host": self.database_host,
"port": 5432,
"user": "root",
"pass": "password",
"dbname": "dbt",
"schema": self.unique_schema()
},
},
"target": "dev"
}
}

@use_profile("postgres")
def test_postgres_duplicate_model_enabled(self):
def test_postgres_duplicate_source_enabled(self):
message = "dbt found two resources with the name"
try:
self.run_dbt(["compile"])
self.assertTrue(False, "dbt did not throw for duplicate sources")
except CompilationException as e:
self.assertTrue(message in str(e), "dbt did not throw the correct error message")
self.assertTrue(message in str(
e), "dbt did not throw the correct error message")
6 changes: 0 additions & 6 deletions test/unit/test_contracts_graph_unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ class TestUnparsedExposure(ContractTestCase):

def get_ok_dict(self):
return {
'yaml_key': 'exposures',
'name': 'my_exposure',
'type': 'dashboard',
'owner': {
Expand All @@ -592,22 +591,17 @@ def get_ok_dict(self):
'ref("my_model")',
'source("raw", "source_table")',
],
'original_file_path': '/some/fake/path',
'package_name': 'test'
}

def test_ok(self):
exposure = self.ContractType(
yaml_key='exposures',
name='my_exposure',
type=ExposureType.Dashboard,
owner=ExposureOwner(email='[email protected]'),
maturity=MaturityType.Medium,
url='https://example.com/dashboards/1',
description='A exposure',
depends_on=['ref("my_model")', 'source("raw", "source_table")'],
original_file_path='/some/fake/path',
package_name='test'
)
dct = self.get_ok_dict()
self.assert_symmetric(exposure, dct)
Expand Down

0 comments on commit c14e6f4

Please sign in to comment.