File: basic.t

package info (click to toggle)
libpithub-perl 0.01033-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 928 kB
  • ctags: 321
  • sloc: perl: 3,282; makefile: 7
file content (134 lines) | stat: -rw-r--r-- 5,079 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use FindBin;
use lib "$FindBin::Bin/../lib";
use Pithub::Test::Factory;
use Test::Most;

BEGIN {
    use_ok('Pithub');
    use_ok('Pithub::Gists');
}

SKIP: {
    skip 'Set PITHUB_TEST_LIVE to true to run these tests', 1 unless $ENV{PITHUB_TEST_LIVE};

    my $p      = Pithub->new;
    my $result = $p->request(
        method => 'GET',
        path   => '/'
    );

    is $result->code,        200,               'HTTP status is 200';
    is $result->success,     1,                 'Successful';
    like $result->etag,      qr{^"[a-f0-9]+"$}, 'ETag';

    cmp_deeply $result->content, subhashof({
        "current_user_url" => "https://api.github.com/user",
        "authorizations_url" => "https://api.github.com/authorizations",
        "code_search_url" => "https://api.github.com/search/code?q={query}{&page,per_page,sort,order}",
        "emails_url" => "https://api.github.com/user/emails",
        "emojis_url" => "https://api.github.com/emojis",
        "events_url" => "https://api.github.com/events",
        "feeds_url" => "https://api.github.com/feeds",
        "following_url" => "https://api.github.com/user/following{/target}",
        "gists_url" => "https://api.github.com/gists{/gist_id}",
        "hub_url" => "https://api.github.com/hub",
        "issue_search_url" => "https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}",
        "issues_url" => "https://api.github.com/issues",
        "keys_url" => "https://api.github.com/user/keys",
        "notifications_url" => "https://api.github.com/notifications",
        "organization_repositories_url" => "https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}",
        "organization_url" => "https://api.github.com/orgs/{org}",
        "public_gists_url" => "https://api.github.com/gists/public",
        "rate_limit_url" => "https://api.github.com/rate_limit",
        "repository_url" => "https://api.github.com/repos/{owner}/{repo}",
        "repository_search_url" => "https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}",
        "current_user_repositories_url" => "https://api.github.com/user/repos{?type,page,per_page,sort}",
        "starred_url" => "https://api.github.com/user/starred{/owner}{/repo}",
        "starred_gists_url" => "https://api.github.com/gists/starred",
        "team_url" => "https://api.github.com/teams",
        "user_url" => "https://api.github.com/users/{user}",
        "user_organizations_url" => "https://api.github.com/user/orgs",
        "user_repositories_url" => "https://api.github.com/users/{user}/repos{?type,page,per_page,sort}",
        "user_search_url" => "https://api.github.com/search/users?q={query}{&page,per_page,sort,order}"
    }),
    'Empty response';
}

# These tests may break very easily because data on Github can and will change, of course.
# And they also might fail once the ratelimit has been reached.
SKIP: {
    skip 'Set PITHUB_TEST_LIVE_DATA to true to run these tests', 1 unless $ENV{PITHUB_TEST_LIVE_DATA};

    my $p = Pithub->new;

    # Pagination + per_page
    {
        my $g = Pithub::Gists->new( per_page => 2 );

        my @seen = ();

        my $test = sub {
            my ( $row, $seen ) = @_;
            my $verb = $seen ? 'did' : 'did not';
            my $id = $row->{id};
            ok $id, "Pithub::Gists->list found gist id ${id}";
            is grep( $_ eq $id, @seen ), $seen, "Pithub::Gists->list we ${verb} see id ${id}";
            push @seen, $id;
        };

        my $result = $g->list( public => 1 );
        is $result->success, 1, 'Pithub::Gists->list successful';
        is $result->count,   2, 'The per_page setting was successful';

        foreach my $page ( 1 .. 2 ) {
            while ( my $row = $result->next ) {
                $test->( $row, 0 );
            }
            $result = $result->next_page unless $page == 2;
        }

        # Browse to the last page and see if we can get some gist id's there
        $result = $result->last_page;
        while ( my $row = $result->next ) {
            $test->( $row, 0 );
        }

        # Browse to the previous page and see if we can get some gist id's there
        $result = $result->prev_page;
        while ( my $row = $result->next ) {
            $test->( $row, 0 );
        }

        # Browse to the first page and see if we can get some gist id's there
        $result = $result->first_page;
        while ( my $row = $result->next ) {
            $test->( $row, 1 );    # we saw those gists already!
        }
    }
}

done_testing;

# TODO: implement tests for following methods:

# Pithub::GitData::References->create

# Pithub::GitData::Tags->get
# Pithub::GitData::Tags->create

# Pithub::Gists->fork

# Pithub::Issues::Events->get
# Pithub::Issues::Events->list

# Pithub::Orgs::Members->delete

# Pithub::PullRequests->merge

# Pithub::PullRequests::Comments->create
# Pithub::PullRequests::Comments->delete
# Pithub::PullRequests::Comments->get
# Pithub::PullRequests::Comments->list
# Pithub::PullRequests::Comments->update

# Pithub::Repos->teams