Skip to content

Commit

Permalink
fix: update to new grpc service suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jyecusch committed Jul 15, 2021
1 parent 7c12407 commit ca6b3f0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion contracts
6 changes: 4 additions & 2 deletions nitric/api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def starts_with(self, match) -> Expression:

def condition(name: str) -> _ExpressionBuilder:
"""
Convenience function for constructing query expressions builds.
Construct a query expressions builder, for convenience.
Expression builders in turn provides magic methods for constructing expressions.
Expand Down Expand Up @@ -276,7 +276,8 @@ def where(
:param expressions: a single expression or a set of expression args or a variadic/tuple/list of expressions.
Examples:
Examples
--------
.where('age', '>', 20)
.where(condition('age') > 20)
.where(condition('age').gt(20))
Expand All @@ -294,6 +295,7 @@ def where(
('age', '>', 20),
('age', '<', 50),
)
"""
for expression in self._flat_expressions(expressions):
self._expressions.append(expression)
Expand Down
8 changes: 4 additions & 4 deletions nitric/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
from typing import List, Union
from nitric.utils import new_default_channel, _struct_from_dict
from nitric.proto.nitric.event.v1 import EventStub, NitricEvent, TopicStub
from nitric.proto.nitric.event.v1 import EventServiceStub, NitricEvent, TopicServiceStub
from dataclasses import dataclass, field


Expand All @@ -43,7 +43,7 @@ def _event_to_wire(event: Event) -> NitricEvent:
class Topic(object):
"""A reference to a topic on an event service, used to perform operations on that topic."""

_stub: EventStub
_stub: EventServiceStub
name: str

async def publish(
Expand Down Expand Up @@ -78,8 +78,8 @@ class Events(object):
def __init__(self):
"""Construct a Nitric Event Client."""
self.channel = new_default_channel()
self._stub = EventStub(channel=self.channel)
self._topic_stub = TopicStub(channel=self.channel)
self._stub = EventServiceStub(channel=self.channel)
self._topic_stub = TopicServiceStub(channel=self.channel)

def __del__(self):
# close the channel when this client is destroyed
Expand Down
4 changes: 2 additions & 2 deletions nitric/api/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from typing import List, Union
from nitric.utils import new_default_channel, _struct_from_dict, _dict_from_struct
from nitric.proto.nitric.queue.v1 import QueueStub, NitricTask, FailedTask as WireFailedTask
from nitric.proto.nitric.queue.v1 import QueueServiceStub, NitricTask, FailedTask as WireFailedTask
from dataclasses import dataclass, field


Expand Down Expand Up @@ -184,7 +184,7 @@ class Queues(object):
def __init__(self):
"""Construct a Nitric Queue Client."""
self.channel = new_default_channel()
self._queue_stub = QueueStub(channel=self.channel)
self._queue_stub = QueueServiceStub(channel=self.channel)

def __del__(self):
# close the channel when this client is destroyed
Expand Down
8 changes: 4 additions & 4 deletions nitric/api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass

from nitric.utils import new_default_channel
from nitric.proto.nitric.storage.v1 import StorageStub
from nitric.proto.nitric.storage.v1 import StorageServiceStub


class Storage(object):
Expand All @@ -32,7 +32,7 @@ class Storage(object):
def __init__(self):
"""Construct a Nitric Storage Client."""
self.channel = new_default_channel()
self._storage_stub = StorageStub(channel=self.channel)
self._storage_stub = StorageServiceStub(channel=self.channel)

def __del__(self):
# close the channel when this client is destroyed
Expand All @@ -48,7 +48,7 @@ def bucket(self, name: str):
class Bucket(object):
"""A reference to a bucket in a storage service, used to the perform operations on that bucket."""

_storage_stub: StorageStub
_storage_stub: StorageServiceStub
name: str

def file(self, key: str):
Expand All @@ -60,7 +60,7 @@ def file(self, key: str):
class File(object):
"""A reference to a file in a bucket, used to perform operations on that file."""

_storage_stub: StorageStub
_storage_stub: StorageServiceStub
_bucket: str
key: str

Expand Down
4 changes: 2 additions & 2 deletions nitric/faas/faas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from nitric.utils import new_default_channel
from nitric.faas import Trigger, Response
from nitric.proto.nitric.faas.v1 import FaasStub, InitRequest, ClientMessage
from nitric.proto.nitric.faas.v1 import FaasServiceStub, InitRequest, ClientMessage
import asyncio


Expand All @@ -40,7 +40,7 @@ async def _register_faas_worker(
:param func: handler function for incoming triggers. Can be sync or async, async is preferred.
"""
channel = new_default_channel()
client = FaasStub(channel)
client = FaasServiceStub(channel)
request_channel = AsyncChannel(close=True)
# We can start be sending all the requests we already have
try:
Expand Down
10 changes: 5 additions & 5 deletions tests/api/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def test_publish(self):

payload = {"content": "of event"}

with patch("nitric.proto.nitric.event.v1.EventStub.publish", mock_publish):
with patch("nitric.proto.nitric.event.v1.EventServiceStub.publish", mock_publish):
topic = Events().topic("test-topic")
event = await topic.publish(Event(payload=payload))

Expand All @@ -63,7 +63,7 @@ async def test_publish_dict(self):

payload = {"content": "of event"}

with patch("nitric.proto.nitric.event.v1.EventStub.publish", mock_publish):
with patch("nitric.proto.nitric.event.v1.EventServiceStub.publish", mock_publish):
topic = Events().topic("test-topic")
await topic.publish({"id": "123", "payload": payload})

Expand All @@ -83,7 +83,7 @@ async def test_publish_invalid_type(self):

payload = {"content": "of event"}

with patch("nitric.proto.nitric.event.v1.EventStub.publish", mock_publish):
with patch("nitric.proto.nitric.event.v1.EventServiceStub.publish", mock_publish):
topic = Events().topic("test-topic")
with pytest.raises(Exception):
await topic.publish((1, 2, 3))
Expand All @@ -96,7 +96,7 @@ async def test_publish_none(self):

payload = {"content": "of event"}

with patch("nitric.proto.nitric.event.v1.EventStub.publish", mock_publish):
with patch("nitric.proto.nitric.event.v1.EventServiceStub.publish", mock_publish):
topic = Events().topic("test-topic")
await topic.publish()

Expand All @@ -119,7 +119,7 @@ async def test_get_topics(self):

payload = {"content": "of event"}

with patch("nitric.proto.nitric.event.v1.TopicStub.list", mock_list_topics):
with patch("nitric.proto.nitric.event.v1.TopicServiceStub.list", mock_list_topics):
topics = await Events().topics()

# Check expected values were passed to Stub
Expand Down
20 changes: 10 additions & 10 deletions tests/api/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def test_send(self):

payload = {"content": "of task"}

with patch("nitric.proto.nitric.queue.v1.QueueStub.send", mock_send):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.send", mock_send):
queue = Queues().queue("test-queue")
await queue.send(Task(payload=payload))

Expand Down Expand Up @@ -73,7 +73,7 @@ async def test_send_with_failed(self):
]
)

with patch("nitric.proto.nitric.queue.v1.QueueStub.send_batch", mock_send):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.send_batch", mock_send):
queue = Queues().queue("test-queue")
failed = await queue.send([Task(payload=payload) for i in range(2)])

Expand All @@ -93,7 +93,7 @@ async def test_send_dict(self):

payload = {"content": "of task"}

with patch("nitric.proto.nitric.queue.v1.QueueStub.send", mock_send):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.send", mock_send):
queue = Queues().queue("test-queue")
await queue.send({"id": "123", "payload": payload})

Expand All @@ -112,7 +112,7 @@ async def test_send_invalid_type(self):

payload = {"content": "of task"}

with patch("nitric.proto.nitric.queue.v1.QueueStub.send", mock_send):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.send", mock_send):
queue = Queues().queue("test-queue")
with pytest.raises(AttributeError):
await queue.send((1, 2, 3))
Expand All @@ -124,7 +124,7 @@ async def test_send_none(self):

payload = {"content": "of task"}

with patch("nitric.proto.nitric.queue.v1.QueueStub.send", mock_send):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.send", mock_send):
queue = Queues().queue("test-queue")
await queue.send()

Expand Down Expand Up @@ -153,7 +153,7 @@ async def test_receive(self):
]
)

with patch("nitric.proto.nitric.queue.v1.QueueStub.receive", mock_receive):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.receive", mock_receive):
queueing = Queues()
queue = queueing.queue("test-queue")
(task,) = await queue.receive()
Expand Down Expand Up @@ -183,7 +183,7 @@ async def test_receive_custom_limit(self):
]
)

with patch("nitric.proto.nitric.queue.v1.QueueStub.receive", mock_receive):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.receive", mock_receive):
await Queues().queue("test-queue").receive(limit=3) # explicitly set a limit

# Check expected values were passed to Stub
Expand All @@ -203,7 +203,7 @@ async def test_receive_below_minimum_limit(self):
]
)

with patch("nitric.proto.nitric.queue.v1.QueueStub.receive", mock_receive):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.receive", mock_receive):
await Queues().queue("test-queue").receive(limit=0) # explicitly set a limit

# Check expected values were passed to Stub
Expand All @@ -214,7 +214,7 @@ async def test_receive_task_without_payload(self):
mock_receive = AsyncMock()
mock_receive.return_value = QueueReceiveResponse(tasks=[NitricTask(id="test-task", lease_id="test-lease")])

with patch("nitric.proto.nitric.queue.v1.QueueStub.receive", mock_receive):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.receive", mock_receive):
(task,) = await Queues().queue("test-queue").receive(limit=0) # explicitly set a limit

# Verify that an empty dict is returned for payload and no payload type.
Expand All @@ -229,7 +229,7 @@ async def test_complete(self):
queueing = Queues()
task = Task(lease_id="test-lease", _queueing=queueing, _queue=queueing.queue("test-queue"))

with patch("nitric.proto.nitric.queue.v1.QueueStub.complete", mock_complete):
with patch("nitric.proto.nitric.queue.v1.QueueServiceStub.complete", mock_complete):
await task.complete()

# Check expected values were passed to Stub
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def test_write(self):

contents = b"some text as bytes"

with patch("nitric.proto.nitric.storage.v1.StorageStub.write", mock_write):
with patch("nitric.proto.nitric.storage.v1.StorageServiceStub.write", mock_write):
bucket = Storage().bucket("test-bucket")
file = bucket.file("test-file")
await file.write(contents)
Expand All @@ -53,7 +53,7 @@ async def test_read(self):
mock_response.body = contents
mock_read.return_value = mock_response

with patch("nitric.proto.nitric.storage.v1.StorageStub.read", mock_read):
with patch("nitric.proto.nitric.storage.v1.StorageServiceStub.read", mock_read):
bucket = Storage().bucket("test-bucket")
file = bucket.file("test-file")
response = await file.read()
Expand All @@ -69,7 +69,7 @@ async def test_delete(self):
mock_read = AsyncMock()
mock_read.return_value = Object()

with patch("nitric.proto.nitric.storage.v1.StorageStub.delete", mock_read):
with patch("nitric.proto.nitric.storage.v1.StorageServiceStub.delete", mock_read):
bucket = Storage().bucket("test-bucket")
file = bucket.file("test-file")
await file.delete()
Expand Down
16 changes: 8 additions & 8 deletions tests/faas/test_faas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -120,7 +120,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -153,7 +153,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -182,7 +182,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -221,7 +221,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -261,7 +261,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -301,7 +301,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down Expand Up @@ -342,7 +342,7 @@ async def mock_stream(self, request_iterator):
yield message

with patch("nitric.faas.faas.AsyncChannel", mock_async_channel_init), patch(
"nitric.proto.nitric.faas.v1.FaasStub.trigger_stream", mock_stream
"nitric.proto.nitric.faas.v1.FaasServiceStub.trigger_stream", mock_stream
), patch("nitric.faas.faas.new_default_channel", mock_grpc_channel):
await faas._register_faas_worker(mock_handler)

Expand Down

0 comments on commit ca6b3f0

Please sign in to comment.