Skip to content

Commit

Permalink
cls and paging
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Jul 30, 2019
1 parent dad636f commit 4d6a570
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 28 deletions.
10 changes: 8 additions & 2 deletions src/azure/Templates/AzurePagingMethodTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ else
{
@: def extract_data(response):
@: deserialized = self._deserialize('@(Model.PagedResponseClass.Name)', response)
@: return @(nextLinkName), iter(deserialized.@(Model.PagedMetadata.ItemProp.Name))
@: list_of_elem = deserialized.@(Model.PagedMetadata.ItemProp.Name)
@: if cls:
@: list_of_elem = cls(list_of_elem)
@: return @(nextLinkName), iter(list_of_elem)
@EmptyLine
@: def get_next(next_link=None):
@: request = prepare_request(next_link)
Expand All @@ -136,7 +139,10 @@ else
{
@: async def extract_data_async(response):
@: deserialized = self._deserialize('@(Model.PagedResponseClass.Name)', response)
@: return @(nextLinkName), AsyncList(deserialized.@(Model.PagedMetadata.ItemProp.Name))
@: list_of_elem = deserialized.@(Model.PagedMetadata.ItemProp.Name)
@: if cls:
@: list_of_elem = cls(list_of_elem)
@: return @(nextLinkName), AsyncList(list_of_elem))
@EmptyLine
@: async def get_next_async(next_link=None):
@: request = prepare_request(next_link)
Expand Down
9 changes: 9 additions & 0 deletions test/azure/AcceptanceTests/asynctests/test_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ async def paging_client():
async with AutoRestPagingTestService(cred, base_url="http://localhost:3000") as client:
yield client

@pytest.mark.asyncio
async def test_paging_cls(paging_client):
def cb(list_of_obj):
for obj in list_of_obj:
obj.marked = True
return list_of_obj
async for obj in paging_client.paging.get_single_pages(cls=cb):
assert obj.marked

@pytest.mark.asyncio
async def test_paging_happy_path(paging_client):

Expand Down
8 changes: 8 additions & 0 deletions test/azure/AcceptanceTests/test_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def paging_client():
with AutoRestPagingTestService(cred, base_url="http://localhost:3000") as client:
yield client

def test_paging_cls(paging_client):
def cb(list_of_obj):
for obj in list_of_obj:
obj.marked = True
return list_of_obj
pages = paging_client.paging.get_single_pages(cls=cb)
assert all(obj.marked for obj in pages)

def test_paging_happy_path(paging_client):

pages = paging_client.paging.get_single_pages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -143,7 +146,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -214,7 +220,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -291,7 +300,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -343,7 +355,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -396,7 +411,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -447,7 +465,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -498,7 +519,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -549,7 +573,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -615,7 +642,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -687,7 +717,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, AsyncList(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -140,7 +143,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -210,7 +216,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -286,7 +295,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -337,7 +349,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -389,7 +404,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -439,7 +457,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -489,7 +510,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -539,7 +563,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('ProductResult', response)
return deserialized.next_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -604,7 +631,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -675,7 +705,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('OdataProductResult', response)
return deserialized.odatanext_link, iter(deserialized.values)
list_of_elem = deserialized.values
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.odatanext_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('StorageAccountListResult', response)
return deserialized.next_link, AsyncList(deserialized.value)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -523,7 +526,10 @@ def prepare_request(next_link=None):

async def extract_data_async(response):
deserialized = self._deserialize('StorageAccountListResult', response)
return deserialized.next_link, AsyncList(deserialized.value)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, AsyncList(list_of_elem)

async def get_next_async(next_link=None):
request = prepare_request(next_link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('StorageAccountListResult', response)
return deserialized.next_link, iter(deserialized.value)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down Expand Up @@ -521,7 +524,10 @@ def prepare_request(next_link=None):

def extract_data(response):
deserialized = self._deserialize('StorageAccountListResult', response)
return deserialized.next_link, iter(deserialized.value)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link, iter(list_of_elem)

def get_next(next_link=None):
request = prepare_request(next_link)
Expand Down

0 comments on commit 4d6a570

Please sign in to comment.