Skip to content

Commit 9b1f1ab

Browse files
author
Jerjou Cheng
committed
Add test to load_data_by_post.
1 parent ec81550 commit 9b1f1ab

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2015, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#
14+
import os
15+
import re
16+
17+
from nose.plugins.attrib import attr
18+
19+
import tests
20+
21+
from .load_data_by_post import load_data
22+
23+
24+
@attr('slow')
25+
class TestLoadDataByPost(tests.CloudBaseTest):
26+
dataset_id = 'ephemeral_dataset'
27+
table_id = 'load_data_by_post'
28+
29+
def test_load_csv_data(self):
30+
schema_path = os.path.join(self.resource_path, 'schema.json')
31+
data_path = os.path.join(self.resource_path, 'data.csv')
32+
with tests.capture_stdout() as mock_stdout:
33+
load_data(schema_path,
34+
data_path,
35+
self.project_id,
36+
self.dataset_id,
37+
self.table_id
38+
)
39+
40+
stdout = mock_stdout.getvalue()
41+
42+
self.assertRegexpMatches(stdout, re.compile(
43+
r'Waiting for job to finish.*Job complete.', re.DOTALL))
44+
45+
def test_load_json_data(self):
46+
schema_path = os.path.join(self.resource_path, 'schema.json')
47+
data_path = os.path.join(self.resource_path, 'data.json')
48+
49+
with tests.capture_stdout() as mock_stdout:
50+
load_data(schema_path,
51+
data_path,
52+
self.project_id,
53+
self.dataset_id,
54+
self.table_id
55+
)
56+
57+
stdout = mock_stdout.getvalue()
58+
59+
self.assertRegexpMatches(stdout, re.compile(
60+
r'Waiting for job to finish.*Job complete.', re.DOTALL))

tests/resources/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Name": "Gandalf", "Age": 2000, "Weight": 140.0, "IsMagic": true}

0 commit comments

Comments
 (0)