public
Description: Python interface for talking to the github API
Clone URL: git://github.com/dustin/py-github.git
dustin (author)
Sat May 24 12:48:21 -0700 2008
commit  30659ad20a090751efa902a5a9db405c96fc8291
tree    f9af0f96726d97516d3494689b96cc841ef32437
parent  0942fc3164237e73dcdceddb66eef452849e2b7a
py-github / githubtest.py
100755 175 lines (148 sloc) 7.112 kb
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python
"""
 
Copyright (c) 2007 Dustin Sallings <dustin@spy.net>
"""
 
import unittest
 
import github
 
class GitHubTest(unittest.TestCase):
 
    def __gh(self, expUrl, filename):
        def opener(url):
            self.assertEquals(expUrl, url)
            return open(filename)
        return github.GitHub(opener)
 
    def __loadUser(self):
        return self.__gh('http://github.com/api/v1/xml/dustin',
            'data/user.xml').user('dustin')
 
    def __loadSearch(self):
        return self.__gh('http://github.com/api/v1/xml/search/merb+stuff',
            'data/search.xml').search('merb stuff')
 
    def __loadCommits(self):
        return self.__gh(
            'http://github.com/api/v1/xml/caged/gitnub/commits/master',
            'data/commits.xml').commits('caged', 'gitnub', 'master')
 
    def __loadCommit(self, which):
        id='00000010000101'
        return self.__gh(
            'http://github.com/api/v1/xml/dustin/py-github/commit/%s' % id,
            'data/' + which).commit('dustin', 'py-github', id)
 
    def testUserBase(self):
        """Test the base properties of the user object."""
        u=self.__loadUser()
        self.assertEquals("Dustin Sallings", u.name)
        self.assertEquals("dustin", u.login)
        self.assertEquals("dustin@spy.net", u.email)
        self.assertEquals("Santa Clara, CA", u.location)
        self.assertEquals("<<User dustin with 34 repos>>", repr(u))
 
    def testUserRepos(self):
        """Test the repositories within the user object."""
        u=self.__loadUser()
        self.assertEquals(34, len(u.repos))
        self.assertEquals('buildwatch', u.repos['buildwatch'].name)
        self.assertEquals('http://github.com/dustin/buildwatch',
            u.repos['buildwatch'].url)
        self.assertEquals('A buildbot GUI for OS X',
            u.repos['buildwatch'].description)
        self.assertEquals('http://code.google.com/p/buildwatch/',
            u.repos['buildwatch'].homepage)
        self.assertEquals("<<Repository buildwatch>>",
            repr(u.repos['buildwatch']))
 
    def testUserWatchers(self):
        """Test the watchers element in the user response."""
        u=self.__loadUser()
        self.assertEquals(10, u.repos['java-memcached-client'].watchers)
 
    def testUserForks(self):
        """Test the forks element in the user response."""
        u=self.__loadUser()
        self.assertEquals(3, u.repos['java-memcached-client'].forks)
 
    def testSearchLen(self):
        """Test search results len"""
        res=self.__loadSearch()
        self.assertEquals(30, len(res))
 
    def testSearchSplicing(self):
        """Test search results splicing operator"""
        res=self.__loadSearch()
        self.assertEquals(3, len(res[:3]))
        self.assertEquals(3, len(res[3:6]))
 
        self.assertEquals('merb-installer', res[-2:][0].name)
 
    def testSearchIteration(self):
        """Test search results iteration"""
        res=self.__loadSearch()
        c=0
        for r in res:
            c += 1
            self.assertTrue(isinstance(r.forks, int))
        self.assertEquals(30, c)
 
    def testSearchGetItem(self):
        """Test search results get item"""
        res=self.__loadSearch()
 
        self.assertEquals('merb-simple-model', res[1].name)
        self.assertEquals('merb_active_admin', res[-3].name)
 
    def testSearchRepr(self):
        """Test search results repr"""
        res=self.__loadSearch()
 
        self.assertEquals('<<SearchResults with 30 repos>>', `res`)
 
    def testCommitsBase(self):
        """Test getting commits."""
        commits=self.__loadCommits()
        self.assertEquals(30, len(commits))
        c=commits[0]
        self.assertEquals('da603ec86b62418e2ad433bb848ae6073cef7137', c.id)
        self.assertEquals("Consider .xib files binary.", c.message)
        self.assertEquals(
            "http://github.com/dustin/buildwatch/commit/%s" % c.id, c.url)
        self.assertEquals("2008-03-12T15:44:56-07:00", c.committedDate)
        self.assertEquals("2008-03-12T15:44:56-07:00", c.authoredDate)
        self.assertEquals("3c40e4178cedbc98214eb9a2b987b2d26a60d09c", c.tree)
        self.assertEquals(['c80c0d9557bc88ec236e7de9854f738c1d6c03b9'],
            c.parents)
        self.assertEquals('Dustin Sallings', c.author.name)
        self.assertEquals('Dustin Sallings', c.committer.name)
        self.assertEquals('dustin@spy.net', c.author.email)
        self.assertEquals('dustin@spy.net', c.committer.email)
 
    def testCommitWithAdd(self):
        """Testing a commit with some adds."""
        c= self.__loadCommit('commit-with-add.xml')
        self.assertEquals('33464f2c56ed5fd64319d8dcc52fdfdb5db9d8ae', c.id)
        self.assertEquals('b73e9af69c043f68b19aa000980e56377fddb600', c.tree)
        self.assertEquals('2008-04-11T21:43:32-07:00', c.committedDate)
        self.assertEquals('2008-04-11T21:43:32-07:00', c.authoredDate)
        self.assertEquals('Added support for listing recent commits.',
            c.message)
        self.assertEquals(['f54d6071a0dafadd3ce50dd0b01b3ca3b69818c7'],
            c.parents)
        self.assertEquals('http://github.com/dustin/py-github/commit/%s' % c.id,
            c.url)
        self.assertEquals('dustin@spy.net', c.author.email)
        self.assertEquals('dustin@spy.net', c.committer.email)
        self.assertEquals('Dustin Sallings', c.author.name)
        self.assertEquals('Dustin Sallings', c.committer.name)
        self.assertEquals(0, len(c.removed))
        self.assertEquals(['data/commits.xml'], c.added)
        self.assertEquals(['github.py', 'githubtest.py'],
            [m.filename for m in c.modified])
 
        self.assertTrue('Repository' in c.modified[0].diff)
        self.assertTrue('GitHubTest' in c.modified[1].diff)
 
    def testCommitWithMerge(self):
        """Testing a commit with a merge."""
        c= self.__loadCommit('commit-merge.xml')
        self.assertEquals('c80c0d9557bc88ec236e7de9854f738c1d6c03b9', c.id)
        self.assertEquals('27d3edfc5f719e1f59871b420a5a4af6616ddca0', c.tree)
        self.assertEquals('2008-03-12T00:05:00-07:00', c.committedDate)
        self.assertEquals('2008-03-12T00:05:00-07:00', c.authoredDate)
        self.assertEquals("Merge branch 'torelease'", c.message)
        self.assertEquals(['c47c0aaa9579fd27d185366ac189cacaa0d9f066',
            '40133467bedae260f9322325ee93ca27fd4fac6c'], c.parents)
        self.assertEquals('http://github.com/dustin/buildwatch/commit/%s'
            % c.id, c.url)
        self.assertEquals('dustin@spy.net', c.author.email)
        self.assertEquals('dustin@spy.net', c.committer.email)
        self.assertEquals('Dustin Sallings', c.author.name)
        self.assertEquals('Dustin Sallings', c.committer.name)
        self.assertEquals(0, len(c.removed))
        self.assertEquals(0, len(c.added))
        self.assertEquals(['ApplicationDelegate.m',
            'English.lproj/MainMenu.xib', 'Info.plist', 'buildwatch.xml'],
            [m.filename for m in c.modified])
 
if __name__ == '__main__':
    unittest.main()
    # gh=github.GitHub(hack)