Example #1
0
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 \
Example #2
0
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 \
Example #3
0
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
Example #4
0
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
Example #5
0
def test_request_properties():
    r = m.Request(resource=m.RepoVulnAlerts, selection_updates=[])
    assert r.page_number == 0
    assert r.repo_owner is None
    assert r.repo_name is None
    assert r.parent_page_size is None
    assert r.parent_page_cursor is None
    assert r.page_size is None
    assert r.page_cursor is None
    assert r.log_str

    r = m.Request(
        resource=m.RepoVulnAlerts,
        selection_updates=[
            (["repository"], {
                "owner": "mozilla",
                "name": "browserid-local-verify"
            }),
            (["repository", "vulnerabilityAlerts"], {
                "first": 1
            }),
        ],
    )
    assert r.page_number == 0
    assert r.repo_owner == "mozilla"
    assert r.repo_name == "browserid-local-verify"
    assert r.parent_page_size is None
    assert r.parent_page_cursor is None
    assert r.page_size is 1
    assert r.page_cursor is None
    assert r.log_str

    r = m.Request(
        resource=m.RepoVulnAlertVulns,
        selection_updates=[
            (["repository"], {
                "owner": "mozilla",
                "name": "browserid-local-verify"
            }),
            (["repository", "vulnerabilityAlerts"], {
                "first": 1
            }),
            (["repository", "vulnerabilityAlerts"], {
                "after": "parent-end-cursor"
            }),
        ],
    )
    assert r.page_number == 0
    assert r.repo_owner == "mozilla"
    assert r.repo_name == "browserid-local-verify"
    assert r.parent_page_size is 1
    assert r.parent_page_cursor is "parent-end-cursor"
    assert r.page_size is None
    assert r.page_cursor is None
    assert r.log_str

    r = m.Request(
        resource=m.RepoVulnAlertVulns,
        selection_updates=[
            (["repository"], {
                "owner": "mozilla",
                "name": "browserid-local-verify"
            }),
            (m.RepoVulnAlertVulns.parent.next_page_selection_path, {
                "first": 1
            }),
            (
                m.RepoVulnAlertVulns.parent.next_page_selection_path,
                {
                    "after": "parent-end-cursor"
                },
            ),
            (m.RepoVulnAlertVulns.next_page_selection_path, {
                "first": 10
            }),
            (m.RepoVulnAlertVulns.next_page_selection_path, {
                "after": "end-cursor"
            }),
        ],
    )
    assert r.page_number == 0
    assert r.repo_owner == "mozilla"
    assert r.repo_name == "browserid-local-verify"
    assert r.parent_page_size is 1
    assert r.parent_page_cursor is "parent-end-cursor"
    assert r.page_size is 10
    assert r.page_cursor is "end-cursor"
    assert r.log_str