<gh_stars>10-100
# Copyright (c) 2020 <NAME>
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

from google.cloud.bigquery.table import Table as BQTable
from google.cloud.bigquery.table import TimePartitioning

from bq_test_kit.bq_dsl.bq_resources.partitions import TimeField
from bq_test_kit.bq_dsl.bq_resources.partitions.time_partitionning_type import \
    TimePartitioningType


def test_default_apply_time_field():
    """TimePartitiongType in TimeField was using BigQuery's API. Closes #3.
    """
    table = BQTable("project.dataset.table")
    assert table.time_partitioning is None
    table = TimeField("f1").apply(table)
    assert isinstance(table.time_partitioning, TimePartitioning)
    assert table.time_partitioning.field == "f1"
    assert table.time_partitioning.type_ == TimePartitioningType.DAY.value


def test_apply_time_field():
    table = BQTable("project.dataset.table")
    assert table.time_partitioning is None
    table = TimeField("f1", type_=TimePartitioningType.DAY).apply(table)
    assert isinstance(table.time_partitioning, TimePartitioning)
    assert table.time_partitioning.field == "f1"
    assert table.time_partitioning.type_ == TimePartitioningType.DAY.value

# Copyright (c) 2020 <NAME>
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

from google.cloud.bigquery.table import Table as BQTable
from google.cloud.bigquery.table import TimePartitioning

from bq_test_kit.bq_dsl.bq_resources.partitions import TimeField
from bq_test_kit.bq_dsl.bq_resources.partitions.time_partitionning_type import \
    TimePartitioningType


def test_default_apply_time_field():
    """TimePartitiongType in TimeField was using BigQuery's API. Closes #3.
    """
    table = BQTable("project.dataset.table")
    assert table.time_partitioning is None
    table = TimeField("f1").apply(table)
    assert isinstance(table.time_partitioning, TimePartitioning)
    assert table.time_partitioning.field == "f1"
    assert table.time_partitioning.type_ == TimePartitioningType.DAY.value


def test_apply_time_field():
    table = BQTable("project.dataset.table")
    assert table.time_partitioning is None
    table = TimeField("f1", type_=TimePartitioningType.DAY).apply(table)
    assert isinstance(table.time_partitioning, TimePartitioning)
    assert table.time_partitioning.field == "f1"
    assert table.time_partitioning.type_ == TimePartitioningType.DAY.value
# Copyright (c) 2020 <NAME> # # This software is released under the MIT License. # https://opensource.org/licenses/MIT TimePartitiongType in TimeField was using BigQuery's API. Closes #3.