Skip to content

Commit

Permalink
fix: more linting/formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Jul 12, 2023
1 parent 2403303 commit 276e1c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 69 deletions.
2 changes: 1 addition & 1 deletion tests/momento/cache_client/shared_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing_extensions import Protocol

from momento import CacheClient, TopicClientAsync
from momento import CacheClient
from momento.auth import CredentialProvider
from momento.config import Configuration
from momento.errors import MomentoErrorCode
Expand Down
2 changes: 1 addition & 1 deletion tests/momento/cache_client/shared_behaviors_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import Protocol

from momento import CacheClientAsync, TopicClientAsync
from momento import CacheClientAsync
from momento.auth import CredentialProvider
from momento.config import Configuration
from momento.errors import MomentoErrorCode
Expand Down
100 changes: 42 additions & 58 deletions tests/momento/topic_client/test_topics.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,43 @@
# from functools import partial
from functools import partial

from momento import CacheClient, TopicClient
from pytest import fixture
from pytest_describe import behaves_like

from momento import CacheClient, TopicClientAsync
from momento.errors import MomentoErrorCode
from momento.responses import TopicPublish, TopicSubscribe, TopicSubscriptionItem
from tests.utils import uuid_str

# from pytest import fixture
# from pytest_describe import behaves_like


# from ..cache_client.shared_behaviors_async import a_cache_name_validator, TCacheNameValidator
from ..cache_client.shared_behaviors import (
TCacheNameValidator,
TTopicValidator,
a_cache_name_validator,
a_topic_validator,
)


# @behaves_like(a_cache_name_validator)
@behaves_like(a_cache_name_validator, a_topic_validator)
def describe_publish() -> None:

# @fixture
# def cache_name_validator(topic_client_async: TopicClientAsync) -> TCacheNameValidator:
# topic_name = uuid_str()
# value = uuid_str()
# return partial(topic_client_async.publish, topic_name, value)

def with_success(client: CacheClient, topic_client: TopicClient, cache_name: str) -> None:
topic = uuid_str()
@fixture
def cache_name_validator(topic_client: TopicClientAsync) -> TCacheNameValidator:
topic_name = uuid_str()
value = uuid_str()
return partial(topic_client.publish, topic_name=topic_name, value=value)

resp = topic_client.publish(cache_name, topic_name=topic, value=value)
assert isinstance(resp, TopicPublish.Success)

def with_invalid_cache(topic_client: TopicClient) -> None:
@fixture
def topic_validator(topic_client: TopicClientAsync) -> TTopicValidator:
cache_name = uuid_str()
topic = uuid_str()
value = uuid_str()
return partial(topic_client.publish, cache_name=cache_name, value=value)

resp = topic_client.publish(cache_name, topic, value)
assert isinstance(resp, TopicPublish.Error)
if isinstance(resp, TopicPublish.Error):
assert resp.error_code == MomentoErrorCode.NOT_FOUND_ERROR

def with_empty_cache_name(topic_client: TopicClient):
cache_name = ""
def publish_happy_path(client: CacheClient, topic_client: TopicClientAsync, cache_name: str) -> None:
topic = uuid_str()
value = uuid_str()

resp = topic_client.publish(cache_name, topic, value)
assert isinstance(resp, TopicPublish.Error)
if isinstance(resp, TopicPublish.Error):
assert resp.error_code == MomentoErrorCode.INVALID_ARGUMENT_ERROR
resp = topic_client.publish(cache_name, topic_name=topic, value=value)
assert isinstance(resp, TopicPublish.Success)

def with_empty_topic_name(topic_client: TopicClient, cache_name: str):
def with_empty_topic_name(topic_client: TopicClientAsync, cache_name: str):
topic = ""
value = uuid_str()

Expand All @@ -58,48 +47,43 @@ def with_empty_topic_name(topic_client: TopicClient, cache_name: str):
assert resp.error_code == MomentoErrorCode.INVALID_ARGUMENT_ERROR


@behaves_like(a_cache_name_validator, a_topic_validator)
def describe_subscribe() -> None:
def happy_path(client: CacheClient, topic_client: TopicClient, cache_name: str) -> None:
@fixture
def cache_name_validator(topic_client: TopicClientAsync) -> TCacheNameValidator:
topic_name = uuid_str()
return partial(topic_client.subscribe, topic_name=topic_name)

@fixture
def topic_validator(topic_client: TopicClientAsync) -> TTopicValidator:
cache_name = uuid_str()
return partial(topic_client.subscribe, cache_name=cache_name)

def subscribe_happy_path(client: CacheClient, topic_client: TopicClientAsync, cache_name: str) -> None:
topic = uuid_str()
value = uuid_str()

subscribe_response = topic_client.subscribe(cache_name, topic_name=topic)
assert isinstance(subscribe_response, TopicSubscribe.Subscription)
assert isinstance(subscribe_response, TopicSubscribe.SubscriptionAsync)

item_task = subscribe_response.item()
publish_response = topic_client.publish(cache_name, topic_name=topic, value=value)

item_response = subscribe_response.item()
print(publish_response)
item_response = item_task
assert isinstance(item_response, TopicSubscriptionItem.Success)
assert item_response.value_string == value

def errors_with_invalid_cache(topic_client: TopicClient) -> None:
cache_name = uuid_str()
topic = uuid_str()

resp = topic_client.subscribe(cache_name, topic)
assert isinstance(resp, TopicSubscribe.Error)
if isinstance(resp, TopicSubscribe.Error):
assert resp.error_code == MomentoErrorCode.NOT_FOUND_ERROR

def errors_with_empty_cache_name(topic_client: TopicClient):
cache_name = ""
topic = uuid_str()

resp = topic_client.subscribe(cache_name, topic)
assert isinstance(resp, TopicSubscribe.Error)
if isinstance(resp, TopicSubscribe.Error):
assert resp.error_code == MomentoErrorCode.INVALID_ARGUMENT_ERROR

def errors_with_empty_topic_name(topic_client: TopicClient, cache_name: str):
def errors_with_empty_topic_name(topic_client: TopicClientAsync, cache_name: str):
topic = ""

resp = topic_client.subscribe(cache_name, topic)
assert isinstance(resp, TopicSubscribe.Error)
if isinstance(resp, TopicSubscribe.Error):
assert resp.error_code == MomentoErrorCode.INVALID_ARGUMENT_ERROR

def succeeds_with_nonexistent_topic(client: CacheClient, topic_client: TopicClient, cache_name: str) -> None:
def succeeds_with_nonexistent_topic(client: CacheClient, topic_client: TopicClientAsync, cache_name: str) -> None:
topic = uuid_str()

resp = topic_client.subscribe(cache_name, topic)
assert isinstance(resp, TopicSubscribe.Subscription)
assert isinstance(resp, TopicSubscribe.SubscriptionAsync)
10 changes: 1 addition & 9 deletions tests/momento/topic_client/test_topics_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@

from momento import CacheClientAsync, TopicClientAsync
from momento.errors import MomentoErrorCode
from momento.responses import (
PubsubResponse,
TopicPublish,
TopicSubscribe,
TopicSubscriptionItem,
)
from momento.responses import TopicPublish, TopicSubscribe, TopicSubscriptionItem
from tests.utils import uuid_str

from ..cache_client.shared_behaviors_async import (
TCacheName,
TCacheNameValidator,
TConnectionValidator,
TTopicValidator,
a_cache_name_validator,
a_connection_validator,
a_topic_validator,
)

Expand Down

0 comments on commit 276e1c9

Please sign in to comment.