Skip to content

Commit

Permalink
format and fixed number of pokemons
Browse files Browse the repository at this point in the history
  • Loading branch information
francescomucio committed Jan 27, 2025
1 parent c05a1d1 commit db264ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
19 changes: 5 additions & 14 deletions tests/sources/rest_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def paginate_by_page_number(
}

if paginator.next_page_url_params:
response["next_page"] = create_next_page_url(
request, paginator, use_absolute_url
)
response["next_page"] = create_next_page_url(request, paginator, use_absolute_url)

return response

Expand Down Expand Up @@ -98,9 +96,7 @@ def posts_header_link(request, context):

@router.get(r"/posts_relative_next_url(\?page=\d+)?$")
def posts_relative_next_url(request, context):
return paginate_by_page_number(
request, generate_posts(), use_absolute_url=False
)
return paginate_by_page_number(request, generate_posts(), use_absolute_url=False)

@router.get(r"/posts_offset_limit(\?offset=\d+&limit=\d+)?$")
def posts_offset_limit(request, context):
Expand Down Expand Up @@ -176,9 +172,7 @@ def post_detail_204(request, context):

@router.get(r"/posts_under_a_different_key$")
def posts_with_results_key(request, context):
return paginate_by_page_number(
request, generate_posts(), records_key="many-results"
)
return paginate_by_page_number(request, generate_posts(), records_key="many-results")

@router.post(r"/posts/search_by_id/\d+$")
def search_posts_by_id(request, context):
Expand Down Expand Up @@ -311,12 +305,9 @@ def oauth_authorize(request):
)


def assert_pagination(
pages, page_size=DEFAULT_PAGE_SIZE, total_pages=DEFAULT_TOTAL_PAGES
):
def assert_pagination(pages, page_size=DEFAULT_PAGE_SIZE, total_pages=DEFAULT_TOTAL_PAGES):
assert len(pages) == total_pages
for i, page in enumerate(pages):
assert page == [
{"id": i, "title": f"Post {i}"}
for i in range(i * page_size, (i + 1) * page_size)
{"id": i, "title": f"Post {i}"} for i in range(i * page_size, (i + 1) * page_size)
]
8 changes: 5 additions & 3 deletions tests/sources/rest_api/test_rest_api_source.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import dlt
import pytest

from dlt.common.configuration.specs.config_providers_context import ConfigProvidersContainer
from dlt.common.configuration.specs.config_providers_context import (
ConfigProvidersContainer,
)

from dlt.sources.rest_api.typing import RESTAPIConfig
from dlt.sources.helpers.rest_client.paginators import SinglePagePaginator
Expand Down Expand Up @@ -79,9 +81,9 @@ def test_rest_api_source(destination_name: str, invocation_type: str) -> None:

assert table_counts.keys() == {"pokemon_list", "berry", "location"}

assert table_counts["pokemon_list"] == 1302
assert table_counts["pokemon_list"] == 1304
assert table_counts["berry"] == 64
assert table_counts["location"] == 1036
assert table_counts["location"] == 1039


@pytest.mark.parametrize("destination_name", ALL_DESTINATIONS)
Expand Down

0 comments on commit db264ae

Please sign in to comment.