Skip to content

Commit e61ad8d

Browse files
authored
replacing hyphens in MockTableMeta cte_name (#32)
1 parent 65cc5de commit e61ad8d

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Changed
1717

1818
### Fixed
19+
* Fixed generation of CTE names from references with hyphens
1920

2021
## [0.5.0]
2122

src/sql_mock/table_mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,4 @@ class MockTableMeta(BaseModel):
343343
@property
344344
def cte_name(self):
345345
if getattr(self, "table_ref", None):
346-
return self.table_ref.replace('"', "").replace(".", "__")
346+
return self.table_ref.replace('"', "").replace(".", "__").replace("-", "_")

tests/sql_mock/test_table_mocks.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from sql_mock.column_mocks import ColumnMock
4-
from sql_mock.table_mocks import BaseMockTable, table_meta
4+
from sql_mock.table_mocks import BaseMockTable, MockTableMeta, table_meta
55

66

77
class IntTestColumn(ColumnMock):
@@ -180,3 +180,11 @@ def test_to_sql_model_multiple_provided(self):
180180
")"
181181
)
182182
assert sql_model == expected_sql_model
183+
184+
185+
def test_cte_name():
186+
mock_table_meta = MockTableMeta(table_ref='"my-project.schema.table_name"')
187+
188+
expected_cte_name = "my_project__schema__table_name"
189+
190+
assert mock_table_meta.cte_name == expected_cte_name

0 commit comments

Comments
 (0)