def test_get_next_requests_for_last_page_returns_no_more_requests_for_resource( logger, github_args_dict, owner_repo_dict, last_resource, github_schema): context = m.ChainMap( owner_repo_dict, github_args_dict, { "github_query_type": all_resource_kinds, "parent_after": "test_parent_first_page_after_cursor", # only for nested pages }, ) last_exchange = m.RequestResponseExchange( request=m.Request( resource=last_resource, selection_updates=m.get_first_page_selection_updates( last_resource, context), ), response=m.Response( resource=last_resource, json=load_json_fixture( f"{last_resource.kind.name}_first_page_response_no_next_page"), ), ) next_requests = list(m.get_next_requests(logger, context, last_exchange)) for r in next_requests: assert r.resource != last_resource assert r.page_number == 0 assert_selection_is_sane(r.graphql, github_schema) assert str(r.graphql) == load_graphql_fixture( f"{r.resource.kind.name}_nested_first_selection" ), f"did not matched expected serialized \
def test_get_next_requests_only_returns_requests_for_enabled_resource( logger, github_args_dict, owner_repo_dict, github_schema): last_resource = m.RepoManifests context = m.ChainMap( owner_repo_dict, github_args_dict, { "github_query_type": [m.RepoManifests], "parent_after": "test_parent_after_cursor", # only for nested pages }, ) last_exchange = m.RequestResponseExchange( request=m.Request( resource=last_resource, selection_updates=m.get_first_page_selection_updates( last_resource, m.ChainMap(context, owner_repo_dict)), ), response=m.Response( resource=last_resource, json=load_json_fixture( f"{last_resource.kind.name}_first_page_response_next_page"), ), ) next_requests = list(m.get_next_requests(logger, context, last_exchange)) assert len(next_requests) == 1 r = next_requests[0] assert r.resource == m.RepoManifests assert_selection_is_sane(r.graphql, github_schema) assert str(r.graphql) == load_graphql_fixture( f"{r.resource.kind.name}_next_selection" ), f"did not matched expected serialized \
def test_get_next_requests_does_not_grow_request_selection_updates( logger, github_args_dict, owner_repo_dict, last_resource, github_schema): context = m.ChainMap( owner_repo_dict, github_args_dict, { "github_query_type": all_resource_kinds, "parent_after": "test_parent_after_cursor", # only for nested pages }, ) first_exchange = m.RequestResponseExchange( request=m.Request( resource=last_resource, selection_updates=m.get_first_page_selection_updates( last_resource, context), ), response=m.Response( resource=last_resource, json=load_json_fixture( f"{last_resource.kind.name}_first_page_response_next_page"), ), ) r = next(m.get_next_requests(logger, context, first_exchange)) assert r.page_number == 1 assert_selection_is_sane(r.graphql, github_schema) assert r.resource not in last_resource.children assert len(r.selection_updates) == len(r.resource.first_page_diffs) + 1 second_exchange = m.RequestResponseExchange( request=r, response=m.Response( resource=last_resource, json=load_json_fixture( f"{last_resource.kind.name}_first_page_response_next_page"), ), ) r = next(m.get_next_requests(logger, context, second_exchange)) assert r.page_number == 2 assert_selection_is_sane(r.graphql, github_schema) assert r.resource not in last_resource.children for update in r.selection_updates: print(update) assert len(r.selection_updates) == len(r.resource.first_page_diffs) + 1
def test_get_next_requests_returns_more_pages_of_the_same_resource_and_linked_resources( logger, github_args_dict, owner_repo_dict, last_resource, github_schema): context = m.ChainMap( owner_repo_dict, github_args_dict, { "github_query_type": all_resource_kinds, "parent_after": "test_parent_after_cursor", # only for nested pages }, ) last_exchange = m.RequestResponseExchange( request=m.Request( resource=last_resource, selection_updates=m.get_first_page_selection_updates( last_resource, context), ), response=m.Response( resource=last_resource, json=load_json_fixture( f"{last_resource.kind.name}_first_page_response_next_page"), ), ) next_requests = list(m.get_next_requests(logger, context, last_exchange)) assert len(next_requests) == 1 + len(last_resource.children) for r in next_requests: assert_selection_is_sane(r.graphql, github_schema) if r.resource in last_resource.children: assert r.page_number == 0 assert str(r.graphql) == load_graphql_fixture( f"{r.resource.kind.name}_nested_first_selection" ), f"did not matched expected serialized \ gql for next {r.resource.kind} from {last_exchange.request.resource.kind}" assert len(r.selection_updates) == len(r.resource.first_page_diffs) else: assert r.page_number == 1 assert str(r.graphql) == load_graphql_fixture( f"{r.resource.kind.name}_next_selection" ), f"did not matched expected serialized \ gql for next {r.resource.kind} from {last_exchange.request.resource.kind}" assert len( r.selection_updates) == len(r.resource.first_page_diffs) + 1