Ejemplo n.º 1
0
 def create_table_data_dataset_does_not_exist(self):
     dataset_id = DATASET_ID + "6"
     table_id = TABLE_ID + "1"
     table_with_new_dataset = gbq._Table(PROJECT_ID, dataset_id)
     df = make_mixed_dataframe_v2(10)
     table_with_new_dataset.create(table_id, gbq._generate_bq_schema(df))
     self.assertTrue(self.dataset.exists(dataset_id), 'Expected dataset to exist')
     self.assertTrue(table_with_new_dataset.exists(table_id), 'Expected dataset to exist')
Ejemplo n.º 2
0
    def test_generate_schema(self):
        df = tm.makeMixedDataFrame()
        schema = gbq._generate_bq_schema(df)

        test_schema = {'fields': [{'name': 'A', 'type': 'FLOAT'},
                                  {'name': 'B', 'type': 'FLOAT'},
                                  {'name': 'C', 'type': 'STRING'},
                                  {'name': 'D', 'type': 'TIMESTAMP'}]}

        self.assertEqual(schema, test_schema)
Ejemplo n.º 3
0
    def test_upload_data_if_table_exists_fail(self):
        destination_table = DESTINATION_TABLE + "2"

        test_size = 10
        df = make_mixed_dataframe_v2(test_size)
        self.table.create(TABLE_ID + "2", gbq._generate_bq_schema(df))

        # Test the default value of if_exists is 'fail'
        with tm.assertRaises(gbq.TableCreationError):
            gbq.to_gbq(df, destination_table, PROJECT_ID)

        # Test the if_exists parameter with value 'fail'
        with tm.assertRaises(gbq.TableCreationError):
            gbq.to_gbq(df, destination_table, PROJECT_ID, if_exists='fail')
Ejemplo n.º 4
0
    def test_upload_data_if_table_exists_fail(self):
        destination_table = DESTINATION_TABLE + "2"

        test_size = 10
        df = make_mixed_dataframe_v2(test_size)
        self.table.create(TABLE_ID + "2", gbq._generate_bq_schema(df))

        # Test the default value of if_exists is 'fail'
        with tm.assertRaises(gbq.TableCreationError):
            gbq.to_gbq(df, destination_table, PROJECT_ID)

        # Test the if_exists parameter with value 'fail'
        with tm.assertRaises(gbq.TableCreationError):
            gbq.to_gbq(df, destination_table, PROJECT_ID, if_exists='fail')
Ejemplo n.º 5
0
    def test_generate_schema(self):
        df = tm.makeMixedDataFrame()
        schema = gbq._generate_bq_schema(df)

        test_schema = {
            "fields": [
                {"name": "A", "type": "FLOAT"},
                {"name": "B", "type": "FLOAT"},
                {"name": "C", "type": "STRING"},
                {"name": "D", "type": "TIMESTAMP"},
            ]
        }

        self.assertEqual(schema, test_schema)