Skip to content

Commit 1c76b88

Browse files
committed
More tests
1 parent ffb34cb commit 1c76b88

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

sdk/core/azure-core/tests/azure_core_asynctests/test_polling.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ def finished(self):
105105
def resource(self):
106106
return self._deserialization_callback(self._initial_response)
107107

108+
def get_continuation_token(self):
109+
return self._initial_response
110+
111+
@classmethod
112+
def from_continuation_token(cls, continuation_token, **kwargs):
113+
# type(str, Any) -> Tuple
114+
initial_response = continuation_token
115+
deserialization_callback = kwargs['deserialization_callback']
116+
return None, initial_response, deserialization_callback
117+
108118

109119
@pytest.mark.asyncio
110120
async def test_poller(client):
@@ -138,6 +148,21 @@ def deserialization_callback(response):
138148
assert result == "Treated: "+initial_response
139149
assert poller.status() == "succeeded"
140150

151+
# Test continuation token
152+
cont_token = poller.continuation_token()
153+
154+
method = PollingTwoSteps(sleep=1)
155+
new_poller = AsyncLROPoller.from_continuation_token(
156+
continuation_token=cont_token,
157+
client=client,
158+
initial_response=initial_response,
159+
deserialization_callback=Model,
160+
polling_method=method
161+
)
162+
result = await poller.result()
163+
assert result == "Treated: "+initial_response
164+
assert poller.status() == "succeeded"
165+
141166

142167
@pytest.mark.asyncio
143168
async def test_broken_poller(client):

sdk/core/azure-core/tests/test_polling.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ def finished(self):
131131
def resource(self):
132132
return self._deserialization_callback(self._initial_response)
133133

134+
def get_continuation_token(self):
135+
return self._initial_response
136+
137+
@classmethod
138+
def from_continuation_token(cls, continuation_token, **kwargs):
139+
# type(str, Any) -> Tuple
140+
initial_response = continuation_token
141+
deserialization_callback = kwargs['deserialization_callback']
142+
return None, initial_response, deserialization_callback
143+
144+
134145
def test_poller(client):
135146

136147
# Same the poller itself doesn't care about the initial_response, and there is no type constraint here
@@ -177,6 +188,22 @@ def deserialization_callback(response):
177188
poller.remove_done_callback(done_cb)
178189
assert "Process is complete" in str(excinfo.value)
179190

191+
# Test continuation token
192+
cont_token = poller.continuation_token()
193+
194+
method = PollingTwoSteps(sleep=1)
195+
new_poller = LROPoller.from_continuation_token(
196+
continuation_token=cont_token,
197+
client=client,
198+
initial_response=initial_response,
199+
deserialization_callback=Model,
200+
polling_method=method
201+
)
202+
result = poller.result()
203+
assert result == "Treated: "+initial_response
204+
assert poller.status() == "succeeded"
205+
206+
180207
def test_broken_poller(client):
181208

182209
class NoPollingError(PollingTwoSteps):

0 commit comments

Comments
 (0)