コード例 #1
0
def test_client_get_organizations_error(mocker, error_message, capsys):
    """Test that Client.get_organizations correctly handles error response"""
    mocker.patch("tracker_client.client.get_auth_token")
    mocker.patch("tracker_client.client.create_client")
    test_client = Client()
    test_client.execute_query = mocker.MagicMock(return_value=error_message)

    with pytest.raises(ValueError, match=r"Unable to get your organizations"):
        test_client.get_organizations()

    captured = capsys.readouterr()
    assert "Server error:" in captured.out
コード例 #2
0
def test_client_get_organizations(mocker, client_all_orgs_input):
    """Test that Client.get_organizations produces correct output"""
    mocker.patch("tracker_client.client.get_auth_token")
    mocker.patch("tracker_client.client.create_client")
    test_client = Client()
    test_client.execute_query = mocker.MagicMock(
        return_value=client_all_orgs_input)

    org_list = test_client.get_organizations()

    test_client.execute_query.assert_called_once_with(queries.GET_ALL_ORGS, {
        "after": "abc",
        "search": ""
    })
    assert org_list[0].acronym == "FOO"
    assert org_list[1].name == "Fizz Bang"
    assert org_list[0].domain_count == 10
    assert org_list[1].verified
コード例 #3
0
def test_client_get_organizations_pagination(mocker, client_all_orgs_input,
                                             client_all_orgs_has_next_input):
    """Test that Client.get_organizations correctly requests more organizations if hasNextPage is true"""
    def mock_return(query, params):
        if params["after"] == "abc":
            return client_all_orgs_input
        return client_all_orgs_has_next_input

    mocker.patch("tracker_client.client.get_auth_token")
    mocker.patch("tracker_client.client.create_client")
    test_client = Client()
    test_client.execute_query = mock_return

    org_list = test_client.get_organizations()

    # If get_domains didn't try to paginate, len(domain_list) will be 2.
    # If it didn't stop trying to get more domains after hasNextPage became false
    # then the length will be greater than 4.
    assert len(org_list) == 4