Exemple #1
0
    def test_skip_signal_is_raised_if_table_exists(self, monkeypatch):
        monkeypatch.setattr("prefect.tasks.gcp.bigquery.get_bigquery_client",
                            MagicMock())
        task = CreateBigQueryTable()
        with pytest.raises(prefect.engine.signals.SUCCESS) as exc:
            task.run()

        assert "already exists" in str(exc.value)
    def test_skip_signal_is_raised_if_table_exists(self, monkeypatch):
        monkeypatch.setattr("prefect.tasks.gcp.bigquery.get_bigquery_client",
                            MagicMock())
        task = CreateBigQueryTable(
            credentials_secret="GOOGLE_APPLICATION_CREDENTIALS")
        with pytest.raises(prefect.engine.signals.SUCCESS) as exc:
            with prefect.context(secrets=dict(
                    GOOGLE_APPLICATION_CREDENTIALS={"key": 42})):
                task.run()

        assert "already exists" in str(exc.value)
    def test_creds_are_pulled_from_secret_at_runtime(self, monkeypatch):
        task = CreateBigQueryTable(
            credentials_secret="GOOGLE_APPLICATION_CREDENTIALS")

        client_util = MagicMock(return_value=MagicMock(get_table=MagicMock(
            side_effect=NotFound("boy"))))
        monkeypatch.setattr("prefect.tasks.gcp.bigquery.get_bigquery_client",
                            client_util)
        with prefect.context(secrets=dict(
                GOOGLE_APPLICATION_CREDENTIALS={"key": 42})):
            task.run()

        assert client_util.call_args[1]["credentials"] == {"key": 42}
Exemple #4
0
 def test_additional_kwargs_passed_upstream(self):
     task = CreateBigQueryTable(name="test-task",
                                checkpoint=True,
                                tags=["bob"])
     assert task.name == "test-task"
     assert task.checkpoint is True
     assert task.tags == {"bob"}
Exemple #5
0
 def test_initializes_with_nothing_and_sets_defaults(self):
     task = CreateBigQueryTable()
     assert task.project is None
     assert task.dataset is None
     assert task.table is None
     assert task.schema is None
     assert task.clustering_fields is None
     assert task.time_partitioning is None
Exemple #6
0
 def test_initializes_attr_from_kwargs(self, attr):
     task = CreateBigQueryTable(**{attr: "my-value"})
     assert getattr(task, attr) == "my-value"