Skip to content

Commit b61bd4b

Browse files
authored
Merge pull request #1 from GoogleCloudPlatform/master
syncing
2 parents d40c363 + 6996c8e commit b61bd4b

Some content is hidden

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

49 files changed

+1351
-68
lines changed

appengine/flexible/tasks/snippets.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,41 +176,59 @@ def create_task_with_name(project, location, queue, task_name):
176176

177177

178178
def delete_task(project, location, queue):
179-
# [START taskqueues_setup]
179+
# [START taskqueues_deleting_tasks]
180180
client = tasks.CloudTasksClient()
181181

182182
# TODO(developer): Uncomment these lines and replace with your values.
183183
# project = 'my-project-id'
184184
# location = 'us- central1'
185185
# queue = 'queue1'
186-
# [START taskqueues_setup]
187186

188-
# [START taskqueues_deleting_tasks]
189187
task_path = client.task_path(project, location, queue, 'foo')
190188
response = client.delete_task(task_path)
191189
# [END taskqueues_deleting_tasks]
190+
return response
192191

192+
193+
def purge_queue(project, location, queue):
193194
# [START taskqueues_purging_tasks]
195+
client = tasks.CloudTasksClient()
196+
197+
# TODO(developer): Uncomment these lines and replace with your values.
198+
# project = 'my-project-id'
199+
# location = 'us- central1'
200+
# queue = 'queue1'
201+
194202
queue_path = client.queue_path(project, location, queue)
195203
response = client.purge_queue(queue_path)
196204
# [END taskqueues_purging_tasks]
205+
return response
206+
197207

208+
def pause_queue(project, location, queue):
198209
# [START taskqueues_pause_queue]
210+
client = tasks.CloudTasksClient()
211+
212+
# TODO(developer): Uncomment these lines and replace with your values.
213+
# project = 'my-project-id'
214+
# location = 'us- central1'
215+
# queue = 'queue1'
216+
199217
queue_path = client.queue_path(project, location, queue)
200218
response = client.pause_queue(queue_path)
201219
# [END taskqueues_pause_queues]
202220
return response
203221

204222

205223
def delete_queue(project, location, queue):
224+
# [START taskqueues_deleting_queues]
206225
client = tasks.CloudTasksClient()
207226

208227
# TODO(developer): Uncomment these lines and replace with your values.
209228
# project = 'my-project-id'
210229
# location = 'us- central1'
211230
# queue = 'queue1'
212231

213-
# [START taskqueues_deleting_queues]
214232
queue_path = client.queue_path(project, location, queue)
215233
response = client.delete_queue(queue_path)
216234
# [END taskqueues_deleting_queues]

appengine/flexible/tasks/snippets_test.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,30 @@ def test_create_task_with_name():
7171

7272
@pytest.mark.order6
7373
def test_delete_task():
74+
result = snippets.delete_task(
75+
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
76+
assert result is None
77+
78+
79+
@pytest.mark.order7
80+
def test_purge_queue():
7481
name = "projects/{}/locations/{}/queues/{}".format(
7582
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
76-
result = snippets.delete_task(
83+
result = snippets.purge_queue(
7784
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
7885
assert name in result.name
7986

8087

81-
@pytest.mark.order7
88+
@pytest.mark.order8
89+
def test_pause_queue():
90+
name = "projects/{}/locations/{}/queues/{}".format(
91+
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
92+
result = snippets.pause_queue(
93+
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
94+
assert name in result.name
95+
96+
97+
@pytest.mark.order9
8298
def test_delete_queue():
8399
result = snippets.delete_queue(
84100
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
@@ -89,7 +105,7 @@ def test_delete_queue():
89105
assert result is None
90106

91107

92-
@pytest.mark.order8
108+
@pytest.mark.order10
93109
def test_retry_task():
94110
QUEUE_SIZE = 3
95111
QUEUE_NAME = []

appengine/standard/i18n/i18n_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
The idea of this example, especially for how to translate strings in
2020
Javascript is originally from an implementation of Django i18n.
2121
"""
22-
22+
from __future__ import print_function
2323

2424
import gettext
2525
import json
@@ -31,6 +31,11 @@
3131

3232
from webob import Request
3333

34+
try:
35+
basestring
36+
except NameError:
37+
basestring = str
38+
3439

3540
def _get_plural_forms(js_translations):
3641
"""Extracts the parameters for what constitutes a plural.
@@ -49,15 +54,15 @@ def _get_plural_forms(js_translations):
4954
for l in js_translations._catalog[''].split('\n'):
5055
if l.startswith('Plural-Forms:'):
5156
plural = l.split(':', 1)[1].strip()
52-
print "plural is %s" % plural
57+
print('plural is {}'.format(plural))
5358
if plural is not None:
5459
for raw_element in plural.split(';'):
5560
element = raw_element.strip()
5661
if element.startswith('nplurals='):
5762
n_plural = int(element.split('=', 1)[1])
5863
elif element.startswith('plural='):
5964
plural = element.split('=', 1)[1]
60-
print "plural is now %s" % plural
65+
print('plural is now {}'.format(plural))
6166
else:
6267
n_plural = 2
6368
plural = '(n == 1) ? 0 : 1'
@@ -83,9 +88,9 @@ def convert_translations_to_dict(js_translations):
8388
for key, value in js_translations._catalog.items():
8489
if key == '':
8590
continue
86-
if type(key) in (str, unicode):
91+
if isinstance(key, basestring):
8792
translations_dict['catalog'][key] = value
88-
elif type(key) == tuple:
93+
elif isinstance(key, tuple):
8994
if key[0] not in translations_dict['catalog']:
9095
translations_dict['catalog'][key[0]] = [''] * n_plural
9196
translations_dict['catalog'][key[0]][int(key[1])] = value

appengine/standard/mail/header.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,7 +41,7 @@ def get(self):
4041
</form></body></html>""")
4142

4243
def post(self):
43-
print repr(self.request.POST)
44+
print(repr(self.request.POST))
4445
id = self.request.POST['thread_id']
4546
send_example_mail('{}@appspot.gserviceaccount.com'.format(
4647
app_identity.get_application_id()), id)

appengine/standard/ndb/properties/snippets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -147,4 +148,4 @@ class Part(ndb.Model):
147148

148149
def print_part():
149150
p1 = Part(name='foo', color=Color.RED)
150-
print p1.color # prints "RED"
151+
print(p1.color) # prints "RED"

appengine/standard/ndb/queries/snippets_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -343,7 +344,7 @@ def test_fetch_message_accounts_inefficient(testbed):
343344

344345
assert len(message_account_pairs) == 5
345346

346-
print repr(message_account_pairs)
347+
print(repr(message_account_pairs))
347348
for i in range(1, 6):
348349
message, account = message_account_pairs[i - 1]
349350
assert message.content == 'Message %s' % i
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Django==2.1.10
1+
Django==2.1.11
22
PyMySQL==0.9.3
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
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+
# http://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+
18+
import argparse
19+
20+
21+
def create_feed(project_id, feed_id, asset_names, topic):
22+
# [START asset_quickstart_create_feed]
23+
from google.cloud import asset_v1p2beta1
24+
from google.cloud.asset_v1p2beta1.proto import asset_service_pb2
25+
26+
# TODO project_id = 'Your Google Cloud Project ID'
27+
# TODO feed_id = 'Feed ID you want to create'
28+
# TODO asset_names = 'List of asset names the feed listen to'
29+
# TODO topic = "Topic name of the feed"
30+
31+
client = asset_v1p2beta1.AssetServiceClient()
32+
parent = "projects/{}".format(project_id)
33+
feed = asset_service_pb2.Feed()
34+
feed.asset_names.extend(asset_names)
35+
feed.feed_output_config.pubsub_destination.topic = topic
36+
response = client.create_feed(parent, feed_id, feed)
37+
print('feed: {}'.format(response))
38+
# [END asset_quickstart_create_feed]
39+
40+
41+
if __name__ == '__main__':
42+
parser = argparse.ArgumentParser(
43+
description=__doc__,
44+
formatter_class=argparse.RawDescriptionHelpFormatter)
45+
parser.add_argument('project_id', help='Your Google Cloud project ID')
46+
parser.add_argument('feed_id', help='Feed ID you want to create')
47+
parser.add_argument('asset_names',
48+
help='List of asset names the feed listen to')
49+
parser.add_argument('topic', help='Topic name of the feed')
50+
args = parser.parse_args()
51+
create_feed(args.project_id, args.feed_id, args.asset_names, args.topic)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2018 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+
# http://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+
import json
18+
import os
19+
import time
20+
21+
import quickstart_createfeed
22+
import quickstart_deletefeed
23+
from google.cloud import resource_manager
24+
25+
json_data = open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]).read()
26+
data = json.loads(json_data)
27+
PROJECT = data['project_id']
28+
ASSET_NAME = 'assets-{}'.format(int(time.time()))
29+
FEED_ID = 'feed-{}'.format(int(time.time()))
30+
TOPIC = 'topic-{}'.format(int(time.time()))
31+
32+
33+
def test_create_feed(capsys):
34+
client = resource_manager.Client()
35+
project_number = client.fetch_project(PROJECT).number
36+
full_topic_name = "projects/{}/topics/{}".format(PROJECT, TOPIC)
37+
quickstart_createfeed.create_feed(
38+
PROJECT, FEED_ID, [ASSET_NAME, ], full_topic_name)
39+
out, _ = capsys.readouterr()
40+
assert "feed" in out
41+
42+
# Clean up, delete the feed
43+
feed_name = "projects/{}/feeds/{}".format(project_number, FEED_ID)
44+
quickstart_deletefeed.delete_feed(feed_name)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2018 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+
# http://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+
18+
import argparse
19+
20+
21+
def delete_feed(feed_name):
22+
# [START asset_quickstart_delete_feed]
23+
from google.cloud import asset_v1p2beta1
24+
25+
# TODO feed_name = 'Feed name you want to delete'
26+
27+
client = asset_v1p2beta1.AssetServiceClient()
28+
client.delete_feed(feed_name)
29+
print('deleted_feed')
30+
# [END asset_quickstart_delete_feed]
31+
32+
33+
if __name__ == '__main__':
34+
parser = argparse.ArgumentParser(
35+
description=__doc__,
36+
formatter_class=argparse.RawDescriptionHelpFormatter)
37+
parser.add_argument('feed_name', help='Feed name you want to delete')
38+
args = parser.parse_args()
39+
delete_feed(args.feed_name)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2018 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+
# http://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+
import os
18+
import time
19+
20+
import quickstart_createfeed
21+
import quickstart_deletefeed
22+
from google.cloud import resource_manager
23+
24+
PROJECT = os.environ['GCLOUD_PROJECT']
25+
ASSET_NAME = 'assets-{}'.format(int(time.time()))
26+
FEED_ID = 'feed-{}'.format(int(time.time()))
27+
TOPIC = 'topic-{}'.format(int(time.time()))
28+
29+
30+
def test_delete_feed(capsys):
31+
client = resource_manager.Client()
32+
project_number = client.fetch_project(PROJECT).number
33+
# First create the feed, which will be deleted later
34+
full_topic_name = "projects/{}/topics/{}".format(PROJECT, TOPIC)
35+
quickstart_createfeed.create_feed(
36+
PROJECT, FEED_ID, [ASSET_NAME, ], full_topic_name)
37+
38+
feed_name = "projects/{}/feeds/{}".format(project_number, FEED_ID)
39+
quickstart_deletefeed.delete_feed(feed_name)
40+
41+
out, _ = capsys.readouterr()
42+
assert "deleted_feed" in out

0 commit comments

Comments
 (0)