<reponame>tomasfarias/dbt-core
import pytest


dupe_models__schema2_yml = """
version: 2
sources:
  - name: my_source
    overrides: localdep
    schema: "{{ target.schema }}"
    database: "{{ target.database }}"
    freshness:
      error_after: {count: 3, period: day}
    tables:
      - name: my_table
        identifier: my_real_seed
        # on the override, the "color" column is only unique, it can be null!
        columns:
          - name: id
            tests:
              - not_null
              - unique
          - name: color
            tests:
              - unique
      - name: my_other_table
        identifier: my_real_other_seed
      - name: snapshot_freshness
        identifier: snapshot_freshness_base
        freshness:
          error_after: {count: 1, period: day}

"""

dupe_models__schema1_yml = """
version: 2
sources:
  - name: my_source
    overrides: localdep
    schema: "{{ target.schema }}"
    database: "{{ target.database }}"
    freshness:
      error_after: {count: 3, period: day}
    tables:
      - name: my_table
        identifier: my_real_seed
        # on the override, the "color" column is only unique, it can be null!
        columns:
          - name: id
            tests:
              - not_null
              - unique
          - name: color
            tests:
              - unique
      - name: my_other_table
        identifier: my_real_other_seed
      - name: snapshot_freshness
        identifier: snapshot_freshness_base
        freshness:
          error_after: {count: 1, period: day}

"""

local_dependency__dbt_project_yml = """
config-version: 2
name: localdep

version: '1.0'

profile: 'default'

seeds:
  quote_columns: False

seed-paths: ['seeds']

"""

local_dependency__models__schema_yml = """
version: 2
sources:
  - name: my_source
    schema: invalid_schema
    database: invalid_database
    freshness:
      error_after: {count: 3, period: hour}
    tables:
      - name: my_table
        identifier: my_seed
        columns:
          - name: id
            tests:
              - unique
              - not_null
          - name: color
            tests:
              - unique
              - not_null
      - name: my_other_table
        identifier: my_other_seed
        columns:
          - name: id
            tests:
              - unique
              - not_null
          - name: letter
            tests:
              - unique
              - not_null
      - name: snapshot_freshness
        identifier: snapshot_freshness_base
        loaded_at_field: updated_at
        freshness:
          error_after: {count: 1, period: hour}
  - name: my_other_source
    schema: "{{ target.schema }}"
    database: "{{ target.database }}"
    freshness:
      error_after: {count: 1, period: day}
    tables:
      - name: never_fresh
        loaded_at_field: updated_at

"""

local_dependency__models__my_model_sql = """

{{ config(materialized="table") }}

with colors as (
  select id, color from {{ source('my_source', 'my_table') }}
),
letters as (
  select id, letter from {{ source('my_source', 'my_other_table') }}
)
select letter, color from colors join letters using (id)

"""

local_dependency__seeds__my_other_seed_csv = """id,letter
1,r
2,g
3,b
"""

local_dependency__seeds__my_seed_csv = """id,color
1,red
2,green
3,blue
"""

local_dependency__seeds__keep__never_fresh_csv = """favorite_color,id,first_name,email,ip_address,updated_at
blue,1,Larry,<EMAIL>,'192.168.3.11',2008-09-12 19:08:31
blue,2,Larry,<EMAIL>,'192.168.127.12',1978-05-09 04:15:14
blue,3,Anna,<EMAIL>,'172.16.17.32',2011-10-16 04:07:57
blue,4,Sandra,<EMAIL>,'172.16.17.32',1973-07-19 10:52:43
blue,5,Fred,<EMAIL>,'192.168.127.12',2012-09-30 16:38:29
blue,6,Stephen,<EMAIL>,'172.16.17.32',1995-11-07 21:40:50
blue,7,William,<EMAIL>,'172.16.17.32',1982-09-05 03:11:59
blue,8,Jessica,<EMAIL>,'172.16.58.3',1991-10-16 11:03:15
blue,9,Douglas,<EMAIL>,'192.168.3.11',1979-10-01 09:49:48
blue,10,Lisa,<EMAIL>,'172.16.31.10',2011-05-26 07:45:49
blue,11,Ralph,<EMAIL>,'172.16.31.10',1972-11-18 19:06:11
blue,12,Louise,<EMAIL>,'172.16.31.10',2014-11-25 20:56:14
blue,13,Clarence,<EMAIL>,'172.16.58.3',2011-11-17 07:02:36
blue,14,Daniel,<EMAIL>,'172.16.17.32',1980-09-13 00:09:04
blue,15,Katherine,<EMAIL>,'172.16.31.10',1997-08-22 19:36:56
blue,16,Billy,<EMAIL>,'172.16.31.10',2003-10-19 02:14:47
blue,17,Annie,<EMAIL>,'172.16.31.10',1988-10-28 15:12:35
blue,18,Shirley,<EMAIL>,'172.16.58.3',1988-08-24 10:50:57
blue,19,Roger,<EMAIL>,'192.168.3.11',1985-12-31 15:17:15
blue,20,Lillian,<EMAIL>,'172.16.58.3',1970-06-08 02:09:05
blue,21,Aaron,<EMAIL>,'192.168.3.11',1985-10-11 23:07:49
blue,22,Patrick,<EMAIL>,'172.16.17.32',2006-03-29 12:53:56
blue,23,Phillip,<EMAIL>,'192.168.3.11',2011-11-07 15:35:43
blue,24,Henry,<EMAIL>,'192.168.127.12',2008-08-28 08:30:44
blue,25,Irene,<EMAIL>,'192.168.127.12',1994-04-01 07:15:02
blue,26,Andrew,<EMAIL>,'172.16.58.3',2000-11-01 06:03:25
blue,27,David,<EMAIL>,'172.16.17.32',1988-01-25 07:29:18
blue,28,Henry,<EMAIL>,'248.102.2.185',1983-01-01 13:36:37
blue,29,Evelyn,<EMAIL>,'172.16.17.32',1979-07-16 17:24:12
blue,30,Tammy,<EMAIL>,'249.246.167.88',2001-04-03 10:00:23
blue,31,Jacqueline,<EMAIL>,'127.181.97.47',1986-02-11 21:35:50
blue,32,Earl,<EMAIL>,'192.168.3.11',1996-07-06 08:16:27
blue,33,Juan,<EMAIL>,'172.16.17.32',1987-01-31 03:46:44
blue,34,Diane,<EMAIL>,'172.16.58.3',1994-06-11 02:30:05
blue,35,Randy,<EMAIL>,'172.16.58.3',2005-05-26 20:28:39
blue,36,Janice,<EMAIL>,'192.168.3.11',1990-02-09 04:16:52
blue,37,Laura,<EMAIL>,'172.16.31.10',2015-03-17 05:59:25
blue,38,Gary,<EMAIL>,'192.168.3.11',1970-01-27 10:04:51
blue,39,Jesse,<EMAIL>,'172.16.58.3',2009-03-14 08:14:29
blue,40,Sandra,<EMAIL>,'172.16.17.32',1993-05-21 14:08:54
blue,41,Scott,<EMAIL>,'172.16.31.10',1980-08-30 11:16:56
blue,42,Phillip,<EMAIL>,'192.168.3.11',2011-12-15 23:26:31
blue,43,Steven,<EMAIL>,'172.16.31.10',2011-10-29 19:03:28
blue,44,Deborah,<EMAIL>,'192.168.3.11',1995-04-10 14:36:07
blue,45,Lori,<EMAIL>,'172.16.58.3',1980-12-27 16:49:15
blue,46,Sean,<EMAIL>,'240.116.183.69',1988-06-12 21:24:45
blue,47,Terry,<EMAIL>,'192.168.127.12',1997-09-22 16:43:19
blue,48,Dorothy,<EMAIL>,'172.16.58.3',2005-02-28 13:33:24
blue,49,Samuel,<EMAIL>,'192.168.127.12',1989-01-19 21:15:48
blue,50,Ralph,<EMAIL>,'172.16.31.10',2007-08-11 10:21:49
"""

local_dependency__seeds__keep__snapshot_freshness_base_csv = """favorite_color,id,first_name,email,ip_address,updated_at
blue,1,Larry,<EMAIL>,'192.168.3.11',2008-09-12 19:08:31
blue,2,Larry,<EMAIL>,'192.168.127.12',1978-05-09 04:15:14
blue,3,Anna,<EMAIL>,'172.16.17.32',2011-10-16 04:07:57
blue,4,Sandra,<EMAIL>,'172.16.17.32',1973-07-19 10:52:43
blue,5,Fred,<EMAIL>,'192.168.127.12',2012-09-30 16:38:29
blue,6,Stephen,<EMAIL>,'172.16.17.32',1995-11-07 21:40:50
blue,7,William,<EMAIL>,'172.16.17.32',1982-09-05 03:11:59
blue,8,Jessica,<EMAIL>,'172.16.58.3',1991-10-16 11:03:15
blue,9,Douglas,<EMAIL>,'192.168.3.11',1979-10-01 09:49:48
blue,10,Lisa,<EMAIL>,'172.16.31.10',2011-05-26 07:45:49
blue,11,Ralph,<EMAIL>,'172.16.31.10',1972-11-18 19:06:11
blue,12,Louise,<EMAIL>,'172.16.31.10',2014-11-25 20:56:14
blue,13,Clarence,<EMAIL>,'172.16.58.3',2011-11-17 07:02:36
blue,14,Daniel,<EMAIL>,'172.16.17.32',1980-09-13 00:09:04
blue,15,Katherine,<EMAIL>,'172.16.31.10',1997-08-22 19:36:56
blue,16,Billy,<EMAIL>,'172.16.31.10',2003-10-19 02:14:47
blue,17,Annie,<EMAIL>,'172.16.31.10',1988-10-28 15:12:35
blue,18,Shirley,<EMAIL>,'172.16.58.3',1988-08-24 10:50:57
blue,19,Roger,<EMAIL>,'192.168.3.11',1985-12-31 15:17:15
blue,20,Lillian,<EMAIL>,'172.16.58.3',1970-06-08 02:09:05
blue,21,Aaron,<EMAIL>,'192.168.3.11',1985-10-11 23:07:49
blue,22,Patrick,<EMAIL>,'172.16.17.32',2006-03-29 12:53:56
blue,23,Phillip,<EMAIL>,'192.168.3.11',2011-11-07 15:35:43
blue,24,Henry,<EMAIL>,'192.168.127.12',2008-08-28 08:30:44
blue,25,Irene,<EMAIL>,'192.168.127.12',1994-04-01 07:15:02
blue,26,Andrew,<EMAIL>,'172.16.58.3',2000-11-01 06:03:25
blue,27,David,<EMAIL>,'172.16.17.32',1988-01-25 07:29:18
blue,28,Henry,<EMAIL>,'248.102.2.185',1983-01-01 13:36:37
blue,29,Evelyn,<EMAIL>.com,'172.16.17.32',1979-07-16 17:24:12
blue,30,Tammy,<EMAIL>,'249.246.167.88',2001-04-03 10:00:23
blue,31,Jacqueline,<EMAIL>,'127.181.97.47',1986-02-11 21:35:50
blue,32,Earl,<EMAIL>,'192.168.3.11',1996-07-06 08:16:27
blue,33,Juan,<EMAIL>,'172.16.17.32',1987-01-31 03:46:44
blue,34,Diane,<EMAIL>,'172.16.58.3',1994-06-11 02:30:05
blue,35,Randy,<EMAIL>,'172.16.58.3',2005-05-26 20:28:39
blue,36,Janice,<EMAIL>,'192.168.3.11',1990-02-09 04:16:52
blue,37,Laura,<EMAIL>,'172.16.31.10',2015-03-17 05:59:25
blue,38,Gary,<EMAIL>,'192.168.3.11',1970-01-27 10:04:51
blue,39,Jesse,<EMAIL>,'172.16.58.3',2009-03-14 08:14:29
blue,40,Sandra,<EMAIL>,'172.16.17.32',1993-05-21 14:08:54
blue,41,Scott,<EMAIL>,'172.16.31.10',1980-08-30 11:16:56
blue,42,Phillip,<EMAIL>,'192.168.3.11',2011-12-15 23:26:31
blue,43,Steven,<EMAIL>,'172.16.31.10',2011-10-29 19:03:28
blue,44,Deborah,<EMAIL>,'192.168.3.11',1995-04-10 14:36:07
blue,45,Lori,<EMAIL>,'172.16.58.3',1980-12-27 16:49:15
blue,46,Sean,<EMAIL>,'240.116.183.69',1988-06-12 21:24:45
blue,47,Terry,<EMAIL>,'192.168.127.12',1997-09-22 16:43:19
blue,48,Dorothy,<EMAIL>,'172.16.58.3',2005-02-28 13:33:24
blue,49,Samuel,<EMAIL>,'192.168.127.12',1989-01-19 21:15:48
blue,50,Ralph,<EMAIL>,'172.16.31.10',2007-08-11 10:21:49
green,51,Wayne,<EMAIL>,'192.168.3.11',1983-07-03 16:58:12
green,52,Rose,<EMAIL>,'240.83.81.10',1995-06-08 11:46:23
green,53,Louise,<EMAIL>,'192.168.3.11',2016-09-19 14:45:51
green,54,Kenneth,<EMAIL>,'192.168.127.12',1976-08-17 11:26:19
green,55,Donna,<EMAIL>,'172.16.31.10',2006-05-27 16:51:40
green,56,Johnny,<EMAIL>,'172.16.31.10',1975-11-17 08:42:32
green,57,Patrick,<EMAIL>,'172.16.17.32',1997-08-06 11:51:09
green,58,Helen,<EMAIL>web.com,'172.16.58.3',1993-08-04 19:53:40
green,59,Patricia,<EMAIL>,'172.16.17.32',1977-08-03 16:37:27
green,60,Joseph,<EMAIL>,'192.168.127.12',2005-07-23 20:22:06
green,61,Phillip,<EMAIL>,'172.16.31.10',1976-05-19 21:47:44
green,62,Joan,<EMAIL>,'192.168.3.11',1972-09-07 17:53:47
green,63,Phyllis,<EMAIL>,'192.168.127.12',2000-01-01 22:33:37
green,64,Katherine,<EMAIL>,'248.168.205.32',1991-01-09 06:40:24
green,65,Laura,<EMAIL>,'172.16.31.10',1997-10-23 12:04:56
green,66,Juan,<EMAIL>,'172.16.58.3',2004-11-10 05:07:35
green,67,Judith,<EMAIL>,'192.168.127.12',1977-08-02 17:01:45
green,68,Beverly,<EMAIL>,'192.168.3.11',2016-03-06 20:07:23
green,69,Lawrence,<EMAIL>,'172.16.17.32',1988-09-13 06:07:21
green,70,Gloria,<EMAIL>,'245.231.88.33',1995-03-18 22:32:46
green,71,Steven,<EMAIL>,'192.168.127.12',2001-08-05 21:26:20
green,72,Betty,<EMAIL>,'172.16.58.3',1981-12-14 21:26:54
green,73,Mildred,<EMAIL>,'172.16.31.10',2000-04-19 10:13:55
green,74,Donald,<EMAIL>,'172.16.58.3',1972-12-03 00:58:24
green,75,Eric,<EMAIL>,'192.168.3.11',1992-11-01 05:59:30
green,76,Joyce,<EMAIL>,'172.16.58.3',1985-10-24 06:50:01
green,77,Maria,<EMAIL>,'172.16.17.32',2005-10-05 05:17:42
green,78,Harry,<EMAIL>,'192.168.3.11',1978-03-26 05:53:33
green,79,Kevin,<EMAIL>,'192.168.127.12',1994-10-12 04:38:52
green,80,David,<EMAIL>,'172.16.17.32',1976-12-15 16:24:24
green,81,Kathy,<EMAIL>,'172.16.17.32',1979-03-04 02:58:56
green,82,Adam,<EMAIL>,'172.16.31.10',1982-11-07 11:46:59
green,83,Brandon,<EMAIL>,'192.168.3.11',2013-10-30 05:30:36
green,84,Henry,<EMAIL>,'192.168.3.11',1985-01-09 06:37:27
green,85,Eric,<EMAIL>,'172.16.17.32',2004-05-01 23:21:42
green,86,Jason,<EMAIL>,'192.168.127.12',1973-01-08 09:05:39
green,87,Diana,<EMAIL>,'172.16.58.3',1994-10-05 22:50:49
green,88,Andrea,<EMAIL>,'172.16.58.3',2002-04-26 08:41:44
green,89,Louis,<EMAIL>,'192.168.127.12',2003-08-25 07:56:39
green,90,Jane,<EMAIL>,'172.16.31.10',1987-03-20 20:39:04
green,91,Larry,<EMAIL>,'172.16.17.32',2000-09-07 20:26:19
green,92,Louis,<EMAIL>,'192.168.3.11',2011-09-16 20:12:14
green,93,Jennifer,<EMAIL>,'192.168.127.12',1988-07-15 05:06:49
green,94,Wayne,<EMAIL>,'172.16.17.32',2009-12-15 06:16:54
green,95,Lori,<EMAIL>,'192.168.127.12',1984-10-28 03:29:19
green,96,Judy,<EMAIL>,'192.168.127.12',1986-02-07 15:18:10
green,97,Phillip,<EMAIL>,'255.247.0.175',2002-12-26 08:44:45
green,98,Gloria,<EMAIL>,'172.16.17.32',1997-10-04 07:58:58
green,99,Paul,<EMAIL>,'192.168.127.12',1991-11-14 12:33:55
green,100,Frank,<EMAIL>,'172.16.17.32',2010-06-12 23:55:39
"""

models__schema_yml = """
version: 2
sources:
  - name: my_source
    overrides: localdep
    schema: "{{ target.schema }}"
    database: "{{ target.database }}"
    freshness:
      error_after: {count: 3, period: day}
    tables:
      - name: my_table
        identifier: my_real_seed
        # on the override, the "color" column is only unique, it can be null!
        columns:
          - name: id
            tests:
              - not_null
              - unique
          - name: color
            tests:
              - unique
      - name: my_other_table
        identifier: my_real_other_seed
      - name: snapshot_freshness
        identifier: snapshot_freshness_base
        freshness:
          error_after: {count: 1, period: day}

"""

seeds__expected_result_csv = """letter,color
c,cyan
m,magenta
y,yellow
k,key
"""

seeds__my_real_other_seed_csv = """id,letter
1,c
2,m
3,y
4,k
"""

seeds__my_real_seed_csv = """id,color
1,cyan
2,magenta
3,yellow
4,key
5,NULL
"""


@pytest.fixture(scope="class")
def local_dependency():
    return {
        "dbt_project.yml": local_dependency__dbt_project_yml,
        "models": {
            "schema.yml": local_dependency__models__schema_yml,
            "my_model.sql": local_dependency__models__my_model_sql,
        },
        "seeds": {
            "my_other_seed.csv": local_dependency__seeds__my_other_seed_csv,
            "my_seed.csv": local_dependency__seeds__my_seed_csv,
            "keep": {
                "never_fresh.csv": local_dependency__seeds__keep__never_fresh_csv,
                "snapshot_freshness_base.csv": local_dependency__seeds__keep__snapshot_freshness_base_csv,
            },
        },
    }
