Skip to content

Commit 727073f

Browse files
authored
Merge branch 'master' into http-tasks
2 parents b6248fe + 18cbdf3 commit 727073f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1759
-104
lines changed

.kokoro/presubmit_tests_tasks.cfg

Lines changed: 0 additions & 15 deletions
This file was deleted.

.kokoro/system_tests_tasks.cfg

Lines changed: 0 additions & 15 deletions
This file was deleted.

appengine/standard/endpoints/multiapi/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ def test_shelves(testbed):
2323

2424
def test_books(testbed):
2525
api = main.Books()
26-
response = api.bookmark(main.Request())
26+
response = api.get_bookmark(main.Request())
2727
assert response
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
# Python pycache:
17+
__pycache__/
18+
# Ignored by the build system
19+
/setup.cfg

appengine/standard_python37/bigquery/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
# limitations under the License.
1414

1515
# [START gae_python37_bigquery]
16+
import concurrent.futures
17+
1618
from flask import Flask, render_template
1719
from google.cloud import bigquery
1820

21+
1922
app = Flask(__name__)
2023
bigquery_client = bigquery.Client()
2124

@@ -34,7 +37,12 @@ def main():
3437
LIMIT 10
3538
""")
3639

37-
results = query_job.result()
40+
try:
41+
# Set a timeout because queries could take longer than one minute.
42+
results = query_job.result(timeout=30)
43+
except concurrent.futures.TimeoutError:
44+
return render_template('timeout.html', job_id=query_job.job_id)
45+
3846
return render_template('query_result.html', results=results)
3947

4048

appengine/standard_python37/bigquery/main_test.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,38 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import concurrent.futures
16+
from unittest import mock
1517

16-
def test_main():
18+
from google.cloud import bigquery
19+
import pytest
20+
21+
22+
@pytest.fixture
23+
def flask_client():
1724
import main
1825

1926
main.app.testing = True
20-
client = main.app.test_client()
27+
return main.app.test_client()
28+
2129

22-
r = client.get('/')
30+
def test_main(flask_client):
31+
r = flask_client.get('/')
2332
assert r.status_code == 200
2433
assert 'Query Result' in r.data.decode('utf-8')
34+
35+
36+
def test_main_timeout(flask_client, monkeypatch):
37+
import main
38+
39+
fake_job = mock.create_autospec(bigquery.QueryJob)
40+
fake_job.result.side_effect = concurrent.futures.TimeoutError()
41+
42+
def fake_query(query):
43+
return fake_job
44+
45+
monkeypatch.setattr(main.bigquery_client, 'query', fake_query)
46+
47+
r = flask_client.get('/')
48+
assert r.status_code == 200
49+
assert 'Query Timeout' in r.data.decode('utf-8')
Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
<!doctype <!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta charset="utf-8" />
5-
<title>Query Result</title>
6-
</head>
7-
<body>
8-
<table>
9-
<tr>
10-
<th>URL</th>
11-
<th>View Count</th>
12-
</tr>
13-
{% for result in results %}
14-
<tr>
15-
<td>{{ result[0] }}</td>
16-
<td>{{ result[1] }}</td>
17-
</tr>
18-
{% endfor %}
19-
</table>
20-
</body>
21-
</html>
1+
<!DOCTYPE html>
2+
{#
3+
Copyright 2019 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
#}
17+
<meta charset="utf-8" />
18+
<title>Query Result</title>
19+
20+
<table>
21+
<tr>
22+
<th>URL</th>
23+
<th>View Count</th>
24+
</tr>
25+
{% for result in results %}
26+
<tr>
27+
<td>{{ result[0] }}</td>
28+
<td>{{ result[1] }}</td>
29+
</tr>
30+
{% endfor %}
31+
</table>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
{#
3+
Copyright 2019 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
#}
17+
<meta charset="utf-8" />
18+
<title>Query Timeout</title>
19+
20+
<p>Query job {{ job_id }} timed out.

bigtable/hello_happybase/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def main(project_id, instance_id, table_name):
7272
#
7373
# https://cloud.google.com/bigtable/docs/schema-design
7474
row_key = 'greeting{}'.format(i)
75-
table.put(row_key, {column_name: value})
75+
table.put(
76+
row_key, {column_name.encode('utf-8'): value.encode('utf-8')}
77+
)
7678
# [END writing_rows]
7779

7880
# [START getting_a_row]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-happybase==0.32.1
1+
google-cloud-happybase==0.33.0

bigtable/metricscaler/metricscaler_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def test_scale_bigtable():
4646

4747
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, True)
4848

49-
time.sleep(3)
49+
time.sleep(10)
5050
cluster.reload()
5151

5252
new_node_count = cluster.serve_nodes
5353
assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP))
5454

5555
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, False)
56-
time.sleep(3)
56+
time.sleep(10)
5757
cluster.reload()
5858
final_node_count = cluster.serve_nodes
5959
assert final_node_count == original_node_count

compute/oslogin/service_account_ssh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def main(cmd, project, instance=None, zone=None,
107107
# Identify the service account ID if it is not already provided.
108108
account = account or requests.get(
109109
SERVICE_ACCOUNT_METADATA_URL, headers=HEADERS).text
110-
account = 'users/' + account
110+
if not account.startswith('users/'):
111+
account = 'users/' + account
111112

112113
# Create a new SSH key pair and associate it with the service account.
113114
private_key_file = create_ssh_key(oslogin, account)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2019 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from colors import bcolors
15+
import gateway
16+
import ledlight
17+
import lightsensor
18+
import thermostat
19+
20+
21+
# Check colors exist
22+
def test_check_colors(capsys):
23+
assert(bcolors.OKBLUE is not None)
24+
assert(bcolors.FAIL is not None)
25+
assert(bcolors.CEND is not None)
26+
27+
28+
# Check error code returns reasonable justifications
29+
def test_gateway_error_string(capsys):
30+
print(gateway.error_str(1))
31+
print(gateway.error_str(2))
32+
print(gateway.error_str(3))
33+
print(gateway.error_str(4))
34+
out, _ = capsys.readouterr()
35+
36+
assert 'memory' in out
37+
assert 'network' in out
38+
assert 'function arguments' in out
39+
assert 'currently connected' in out
40+
41+
42+
# Check gateway state is init to reasonable defaults
43+
def test_gateway_state(capsys):
44+
assert (gateway.GatewayState.mqtt_config_topic == '')
45+
assert (gateway.GatewayState.connected is False)
46+
assert (gateway.GatewayState.pending_responses == {})
47+
assert (gateway.GatewayState.pending_subscribes == {})
48+
assert (gateway.GatewayState.mqtt_bridge_port == 8883 or
49+
gateway.GatewayState.mqtt_bridge_ == 443)
50+
51+
52+
def test_check_ledlight(capsys):
53+
print(ledlight.make_message('test', 'action', data='1234'))
54+
out, _ = capsys.readouterr()
55+
56+
assert ('{ "device" : "test"' in out)
57+
58+
59+
def test_check_lightsensor(capsys):
60+
print(lightsensor.print_sensor_state())
61+
out, _ = capsys.readouterr()
62+
63+
assert ('Sensor is on, reporting lux every 1 seconds.' in out)
64+
65+
66+
def test_check_thermostat(capsys):
67+
print(thermostat.make_message('test', 'action', data='1234'))
68+
out, _ = capsys.readouterr()
69+
70+
assert ('{ "device" : "test"' in out)

iot/api-client/codelabs/colors.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2019 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
class bcolors:
17+
HEADER = '\033[95m'
18+
OKBLUE = '\033[94m'
19+
OKGREEN = '\033[92m'
20+
WARNING = '\033[93m'
21+
FAIL = '\033[91m'
22+
ENDC = '\033[0m'
23+
BOLD = '\033[1m'
24+
UNDERLINE = '\033[4m'
25+
26+
CEND = '\33[0m'
27+
CBOLD = '\33[1m'
28+
CITALIC = '\33[3m'
29+
CURL = '\33[4m'
30+
CBLINK = '\33[5m'
31+
CBLINK2 = '\33[6m'
32+
CSELECTED = '\33[7m'
33+
34+
CBLACK = '\33[30m'
35+
CRED = '\33[31m'
36+
CGREEN = '\33[32m'
37+
CYELLOW = '\33[33m'
38+
CBLUE = '\33[34m'
39+
CVIOLET = '\33[35m'
40+
CBEIGE = '\33[36m'
41+
CWHITE = '\33[37m'
42+
43+
CBLACKBG = '\33[40m'
44+
CREDBG = '\33[41m'
45+
CGREENBG = '\33[42m'
46+
CYELLOWBG = '\33[43m'
47+
CBLUEBG = '\33[44m'
48+
CVIOLETBG = '\33[45m'
49+
CBEIGEBG = '\33[46m'
50+
CWHITEBG = '\33[47m'
51+
52+
CGREY = '\33[90m'
53+
CRED2 = '\33[91m'
54+
CGREEN2 = '\33[92m'
55+
CYELLOW2 = '\33[93m'
56+
CBLUE2 = '\33[94m'
57+
CVIOLET2 = '\33[95m'
58+
CBEIGE2 = '\33[96m'
59+
CWHITE2 = '\33[97m'
60+
61+
CGREYBG = '\33[100m'
62+
CREDBG2 = '\33[101m'
63+
CGREENBG2 = '\33[102m'
64+
CYELLOWBG2 = '\33[103m'
65+
CBLUEBG2 = '\33[104m'
66+
CVIOLETBG2 = '\33[105m'
67+
CBEIGEBG2 = '\33[106m'
68+
CWHITEBG2 = '\33[107m'

0 commit comments

Comments
 (0)