Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[asset] testing: use uuid instead of time
  • Loading branch information
Takashi Matsuo
Takashi Matsuo committed May 19, 2020
commit 363b4138bd7202f87093b6039b50be3c0df25a73
25 changes: 15 additions & 10 deletions asset/cloud-client/quickstart_batchgetassetshistory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
# limitations under the License.

import os
import time
import uuid

import backoff
from google.api_core.exceptions import InvalidArgument
from google.cloud import storage
import pytest

import quickstart_batchgetassetshistory

PROJECT = os.environ['GCLOUD_PROJECT']
BUCKET = 'assets-{}'.format(int(time.time()))
BUCKET = 'assets-{}'.format(uuid.uuid4().hex)


@pytest.fixture(scope='module')
Expand All @@ -47,12 +49,15 @@ def asset_bucket(storage_client):
def test_batch_get_assets_history(asset_bucket, capsys):
bucket_asset_name = '//storage.googleapis.com/{}'.format(BUCKET)
asset_names = [bucket_asset_name, ]
# There's some delay between bucket creation and when it's reflected in the
# backend.
time.sleep(15)
quickstart_batchgetassetshistory.batch_get_assets_history(
PROJECT, asset_names)
out, _ = capsys.readouterr()

if not out:

@backoff.on_exception(
backoff.expo, (AssertionError, InvalidArgument), max_time=30
)
def eventually_consistent_test():
quickstart_batchgetassetshistory.batch_get_assets_history(
PROJECT, asset_names)
out, _ = capsys.readouterr()

assert bucket_asset_name in out

eventually_consistent_test()
8 changes: 4 additions & 4 deletions asset/cloud-client/quickstart_createfeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import json
import os
import time
import uuid

from google.cloud import pubsub_v1
from google.cloud import resource_manager
Expand All @@ -27,9 +27,9 @@
json_data = open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]).read()
data = json.loads(json_data)
PROJECT = data['project_id']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))
ASSET_NAME = 'assets-{}'.format(uuid.uuid4().hex)
FEED_ID = 'feed-{}'.format(uuid.uuid4().hex)
TOPIC = 'topic-{}'.format(uuid.uuid4().hex)


def test_create_feed(capsys):
Expand Down
8 changes: 4 additions & 4 deletions asset/cloud-client/quickstart_deletefeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

import os
import time
import uuid

from google.cloud import pubsub_v1
from google.cloud import resource_manager
Expand All @@ -24,9 +24,9 @@
import quickstart_deletefeed

PROJECT = os.environ['GCLOUD_PROJECT']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))
ASSET_NAME = 'assets-{}'.format(uuid.uuid4().hex)
FEED_ID = 'feed-{}'.format(uuid.uuid4().hex)
TOPIC = 'topic-{}'.format(uuid.uuid4().hex)


def test_delete_feed(capsys):
Expand Down
4 changes: 2 additions & 2 deletions asset/cloud-client/quickstart_exportassets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.

import os
import time
import uuid

from google.cloud import storage
import pytest

import quickstart_exportassets

PROJECT = os.environ['GCLOUD_PROJECT']
BUCKET = 'assets-{}'.format(int(time.time()))
BUCKET = 'assets-{}'.format(uuid.uuid4().hex)


@pytest.fixture(scope='module')
Expand Down
8 changes: 4 additions & 4 deletions asset/cloud-client/quickstart_getfeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

import os
import time
import uuid

from google.cloud import pubsub_v1
from google.cloud import resource_manager
Expand All @@ -25,9 +25,9 @@
import quickstart_getfeed

PROJECT = os.environ['GCLOUD_PROJECT']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))
ASSET_NAME = 'assets-{}'.format(uuid.uuid4().hex)
FEED_ID = 'feed-{}'.format(uuid.uuid4().hex)
TOPIC = 'topic-{}'.format(uuid.uuid4().hex)


def test_get_feed(capsys):
Expand Down
10 changes: 5 additions & 5 deletions asset/cloud-client/quickstart_updatefeed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

import os
import time
import uuid

from google.cloud import pubsub_v1
from google.cloud import resource_manager
Expand All @@ -25,10 +25,10 @@
import quickstart_updatefeed

PROJECT = os.environ['GCLOUD_PROJECT']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))
NEW_TOPIC = 'new-topic-{}'.format(int(time.time()))
ASSET_NAME = 'assets-{}'.format(uuid.uuid4().hex)
FEED_ID = 'feed-{}'.format(uuid.uuid4().hex)
TOPIC = 'topic-{}'.format(uuid.uuid4().hex)
NEW_TOPIC = 'new-topic-{}'.format(uuid.uuid4().hex)


def test_update_feed(capsys):
Expand Down
3 changes: 2 additions & 1 deletion asset/cloud-client/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest==5.3.2
backoff==1.10.0
pytest==5.4.1