Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tasks] testing: use fixtures for the queue #4049

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tasks/create_http_task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,35 @@
# limitations under the License.

import os
import uuid

from google.cloud import tasks_v2
import pytest

import create_http_task

TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT')
TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1')
TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-queue')
TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}'


@pytest.fixture()
def test_queue():
client = tasks_v2.CloudTasksClient()
parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION)
queue = {
# The fully qualified path to the queue
'name': client.queue_path(
TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
}
q = client.create_queue(parent, queue)

yield q

client.delete_queue(q.name)


def test_create_http_task():
def test_create_http_task(test_queue):
url = 'https://example.com/task_handler'
result = create_http_task.create_http_task(
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url)
Expand Down
24 changes: 22 additions & 2 deletions tasks/create_http_task_with_token_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,37 @@
# limitations under the License.

import os
import uuid

from google.cloud import tasks_v2
import pytest

import create_http_task_with_token

TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT')
TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1')
TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-queue')
TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}'
TEST_SERVICE_ACCOUNT = (
'test-run-invoker@python-docs-samples-tests.iam.gserviceaccount.com')


def test_create_http_task_with_token():
@pytest.fixture()
def test_queue():
client = tasks_v2.CloudTasksClient()
parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION)
queue = {
# The fully qualified path to the queue
'name': client.queue_path(
TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
}
q = client.create_queue(parent, queue)

yield q

client.delete_queue(q.name)


def test_create_http_task_with_token(test_queue):
url = 'https://example.com/task_handler'
result = create_http_task_with_token.create_http_task(TEST_PROJECT_ID,
TEST_QUEUE_NAME,
Expand Down