DeepLcom / sql-mock

A Python library to test your SQL models using mocked input data
MIT License
33 stars 5 forks source link

Allow cte mocks #39

Closed Somtom closed 8 months ago

Somtom commented 8 months ago

Problem Context

We currently cannot mock CTEs which creates issues with dbt ephemeral models. Being able to mock CTEs also allows us to create even more granular unit tests

What changed

Added functionality to mock CTEs

Take an example: Now you can mock only cte_1 without the need of mocking some_table and another_table:

        @table_meta(table_ref="cte_1")
        class Cte1Mock(BaseTableMock):
            pass

        query = """
        WITH cte_1 AS (
            SELECT * 
            FROM some_table
           LEFT JOIN another_table USING(id)
        )

        SELECT * FROM cte_1
        """