Esempio n. 1
0
    def test_creating_table_that_exists_with_different_column_families_gc_rule_in__table(
            self, mock_hook):
        op = BigtableCreateTableOperator(
            project_id=PROJECT_ID,
            instance_id=INSTANCE_ID,
            table_id=TABLE_ID,
            initial_split_keys=INITIAL_SPLIT_KEYS,
            column_families={"cf-id": MaxVersionsGCRule(1)},
            task_id="id",
            gcp_conn_id=GCP_CONN_ID)

        cf_mock = mock.Mock()
        cf_mock.gc_rule = mock.Mock(return_value=MaxVersionsGCRule(2))

        mock_hook.return_value.get_column_families_for_table.return_value = {
            "cf-id": cf_mock
        }
        mock_hook.return_value.create_table.side_effect = mock.Mock(
            side_effect=google.api_core.exceptions.AlreadyExists(
                "Table already exists."))

        with self.assertRaises(AirflowException) as e:
            op.execute(None)
        err = e.exception
        self.assertEqual(
            str(err),
            "Table '{}' already exists with different Column Families.".format(
                TABLE_ID))
        mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
Esempio n. 2
0
 def test_instance_not_exists(self, mock_hook):
     op = BigtableCreateTableOperator(project_id=PROJECT_ID,
                                      instance_id=INSTANCE_ID,
                                      table_id=TABLE_ID,
                                      initial_split_keys=INITIAL_SPLIT_KEYS,
                                      column_families=EMPTY_COLUMN_FAMILIES,
                                      task_id="id",
                                      gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.get_instance.return_value = None
     with self.assertRaises(AirflowException) as e:
         op.execute(None)
     err = e.exception
     self.assertEqual(
         str(err),
         "Dependency: instance '{}' does not exist in project '{}'.".format(
             INSTANCE_ID, PROJECT_ID))
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
Esempio n. 3
0
 def test_create_execute(self, mock_hook):
     op = BigtableCreateTableOperator(project_id=PROJECT_ID,
                                      instance_id=INSTANCE_ID,
                                      table_id=TABLE_ID,
                                      initial_split_keys=INITIAL_SPLIT_KEYS,
                                      column_families=EMPTY_COLUMN_FAMILIES,
                                      task_id="id",
                                      gcp_conn_id=GCP_CONN_ID)
     instance = mock_hook.return_value.get_instance.return_value = mock.Mock(
         Instance)
     op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.create_table.assert_called_once_with(
         instance=instance,
         table_id=TABLE_ID,
         initial_split_keys=INITIAL_SPLIT_KEYS,
         column_families=EMPTY_COLUMN_FAMILIES)
Esempio n. 4
0
    def test_creating_table_that_exists_empty_project_id(self, mock_hook):
        op = BigtableCreateTableOperator(instance_id=INSTANCE_ID,
                                         table_id=TABLE_ID,
                                         initial_split_keys=INITIAL_SPLIT_KEYS,
                                         column_families=EMPTY_COLUMN_FAMILIES,
                                         task_id="id",
                                         gcp_conn_id=GCP_CONN_ID)

        mock_hook.return_value.get_column_families_for_table.return_value = \
            EMPTY_COLUMN_FAMILIES
        instance = mock_hook.return_value.get_instance.return_value = mock.Mock(
            Instance)
        mock_hook.return_value.create_table.side_effect = mock.Mock(
            side_effect=google.api_core.exceptions.AlreadyExists(
                "Table already exists."))
        op.execute(None)

        mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
        mock_hook.return_value.create_table.assert_called_once_with(
            instance=instance,
            table_id=TABLE_ID,
            initial_split_keys=INITIAL_SPLIT_KEYS,
            column_families=EMPTY_COLUMN_FAMILIES)