-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mox.py
More file actions
62 lines (45 loc) · 2.25 KB
/
test_mox.py
File metadata and controls
62 lines (45 loc) · 2.25 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
__author__ = 'afreisthler'
from unittest import TestCase
import urllib2
import mox
from github import GitHub
class TestMox(TestCase):
def setUp(self):
self.github = GitHub('afreisthler')
self.urllib_mocker = mox.Mox()
def test_id(self):
self.urllib_mocker.StubOutWithMock(urllib2, 'urlopen')
urllib2.urlopen("https://api.github.com/users/afreisthler").AndReturn(file('./mock_data/urlopen1'))
self.urllib_mocker.ReplayAll()
user_id = self.github.get_id()
self.assertEqual(user_id, 1740138)
self.urllib_mocker.UnsetStubs()
self.urllib_mocker.VerifyAll()
def test_number_public_repos(self):
self.urllib_mocker.StubOutWithMock(urllib2, 'urlopen')
urllib2.urlopen("https://api.github.com/users/afreisthler").AndReturn(file('./mock_data/urlopen1'))
self.urllib_mocker.ReplayAll()
number_public_repos = self.github.get_number_public_repos()
self.assertEqual(number_public_repos, 4)
self.urllib_mocker.UnsetStubs()
self.urllib_mocker.VerifyAll()
def test_public_repos(self):
self.urllib_mocker.StubOutWithMock(urllib2, 'urlopen')
urllib2.urlopen("https://api.github.com/users/afreisthler/repos").AndReturn(file('./mock_data/urlopen2'))
self.urllib_mocker.ReplayAll()
public_repo_uris = self.github.get_public_repo_uris()
self.assertTrue(len(public_repo_uris) >= 4)
self.urllib_mocker.UnsetStubs()
self.urllib_mocker.VerifyAll()
def test_all_details(self):
self.urllib_mocker.StubOutWithMock(urllib2, 'urlopen')
urllib2.urlopen("https://api.github.com/users/afreisthler").AndReturn(file('./mock_data/urlopen1'))
urllib2.urlopen("https://api.github.com/users/afreisthler").AndReturn(file('./mock_data/urlopen1'))
urllib2.urlopen("https://api.github.com/users/afreisthler/repos").AndReturn(file('./mock_data/urlopen2'))
self.urllib_mocker.ReplayAll()
id, number_public_repos, public_repo_uris = self.github.get_all_details()
self.assertEqual(id, 1740138)
self.assertEqual(number_public_repos, 4)
self.assertTrue(len(public_repo_uris) >= 4)
self.urllib_mocker.UnsetStubs()
self.urllib_mocker.VerifyAll()