Skip to content

Commit 9e1636e

Browse files
arithmetic1728busunkim96
authored andcommitted
feat!: migrate to use microgen (#38)
* feat!: migrate to use microgen * Update UPGRADING.md Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: Bu Sun Kim <[email protected]>
1 parent 26dd3b7 commit 9e1636e

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

cloud_tasks/snippets/create_queue.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def create_queue(project, queue_name, location):
2222
client = tasks_v2.CloudTasksClient()
2323

2424
# Construct the fully qualified location path.
25-
parent = client.location_path(project, location)
25+
parent = f"projects/{project}/locations/{location}"
2626

2727
# Construct the create queue request.
28-
queue = {'name': client.queue_path(project, location, queue_name)}
28+
queue = {"name": client.queue_path(project, location, queue_name)}
2929

3030
# Use the client to create the queue.
31-
response = client.create_queue(parent, queue)
31+
response = client.create_queue(request={"parent": parent, "queue": queue})
3232

33-
print('Created queue {}'.format(response.name))
33+
print("Created queue {}".format(response.name))
3434
return response
35+
36+
3537
# [END cloud_tasks_create_queue]

cloud_tasks/snippets/create_queue_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import create_queue
2222

23-
TEST_PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT']
24-
TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1')
25-
TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}'
23+
TEST_PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
24+
TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1")
25+
TEST_QUEUE_NAME = f"my-queue-{uuid.uuid4().hex}"
2626

2727

2828
@pytest.fixture()
@@ -32,9 +32,9 @@ def test_queue():
3232

3333
yield q
3434

35-
client.delete_queue(q.name)
35+
client.delete_queue(request={"name": q.name})
3636

3737

3838
def test_create_queue(capsys, test_queue):
3939
out, _ = capsys.readouterr()
40-
assert 'Created queue' in out
40+
assert "Created queue" in out

cloud_tasks/snippets/delete_queue.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def delete_queue(project, queue_name, location):
2525
queue = client.queue_path(project, location, queue_name)
2626

2727
# Use the client to delete the queue.
28-
client.delete_queue(queue)
29-
print('Deleted queue')
28+
client.delete_queue(request={"name": queue})
29+
print("Deleted queue")
30+
31+
3032
# [END cloud_tasks_delete_queue]

cloud_tasks/snippets/delete_queue_test.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,32 @@
2222
import delete_queue
2323

2424

25-
TEST_PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT']
26-
TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1')
27-
TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}'
25+
TEST_PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
26+
TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1")
27+
TEST_QUEUE_NAME = f"my-queue-{uuid.uuid4().hex}"
2828

2929

3030
@pytest.fixture()
3131
def test_queue():
3232
client = tasks_v2.CloudTasksClient()
33-
parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION)
33+
parent = f"projects/{TEST_PROJECT_ID}/locations/{TEST_LOCATION}"
3434
queue = {
3535
# The fully qualified path to the queue
36-
'name': client.queue_path(
37-
TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
36+
"name": client.queue_path(TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
3837
}
39-
q = client.create_queue(parent, queue)
38+
q = client.create_queue(request={"parent": parent, "queue": queue})
4039

4140
yield q
4241

4342
try:
4443
# Attempt to delete the queue in case the sample failed.
45-
client.delete_queue(q.name)
44+
client.delete_queue(request={"name": q.name})
4645
except exceptions.NotFound:
4746
# The queue was already successfully deleted.
48-
print('Queue already deleted successfully')
47+
print("Queue already deleted successfully")
4948

5049

5150
def test_delete_queue(capsys, test_queue):
52-
delete_queue.delete_queue(
53-
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION
54-
)
51+
delete_queue.delete_queue(TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION)
5552
out, _ = capsys.readouterr()
56-
assert 'Deleted queue' in out
53+
assert "Deleted queue" in out

cloud_tasks/snippets/list_queues.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ def list_queues(project, location):
2222
client = tasks_v2.CloudTasksClient()
2323

2424
# Construct the fully qualified location path.
25-
parent = client.location_path(project, location)
25+
parent = f"projects/{project}/locations/{location}"
2626

2727
# Use the client to obtain the queues.
28-
response = client.list_queues(parent)
28+
response = client.list_queues(request={"parent": parent})
2929

3030
# Print the results.
31+
num_results = 0
3132
for queue in response:
33+
num_results = num_results + 1
3234
print(queue.name)
3335

34-
if response.num_results == 0:
35-
print('No queues found!')
36+
if num_results == 0:
37+
print("No queues found!")
38+
39+
3640
# [END cloud_tasks_list_queues]

cloud_tasks/snippets/list_queues_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,35 @@
2020

2121
import list_queues
2222

23-
TEST_PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT']
24-
TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1')
25-
TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}'
23+
TEST_PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
24+
TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1")
25+
TEST_QUEUE_NAME = f"my-queue-{uuid.uuid4().hex}"
2626

2727

2828
@pytest.fixture()
2929
def test_queue():
3030
client = tasks_v2.CloudTasksClient()
31-
parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION)
31+
parent = f"projects/{TEST_PROJECT_ID}/locations/{TEST_LOCATION}"
3232
queue = {
3333
# The fully qualified path to the queue
34-
'name': client.queue_path(
35-
TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
34+
"name": client.queue_path(TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
3635
}
37-
q = client.create_queue(parent, queue)
36+
q = client.create_queue(request={"parent": parent, "queue": queue})
3837

3938
yield q
4039

41-
client.delete_queue(q.name)
40+
client.delete_queue(request={"name": q.name})
4241

4342

4443
def test_list_queues_not_present(capsys):
4544
list_queues.list_queues(TEST_PROJECT_ID, TEST_LOCATION)
4645
out, _ = capsys.readouterr()
4746

48-
assert(TEST_QUEUE_NAME not in out)
47+
assert TEST_QUEUE_NAME not in out
4948

5049

5150
def test_list_queues_present(capsys, test_queue):
5251
list_queues.list_queues(TEST_PROJECT_ID, TEST_LOCATION)
5352
out, _ = capsys.readouterr()
5453

55-
assert(TEST_QUEUE_NAME in out)
54+
assert TEST_QUEUE_NAME in out

0 commit comments

Comments
 (0)