-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathtest_unit.py
More file actions
116 lines (83 loc) · 3.37 KB
/
test_unit.py
File metadata and controls
116 lines (83 loc) · 3.37 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
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2012 Adam Vandenberg <[email protected]>
# James Rowe <[email protected]>
# Jeremy Dunck <[email protected]>
# modocache <[email protected]>
#
# This file is part of python-github2, and is made available under the 3-clause
# BSD license. See LICENSE for the full details.
import unittest
from mock import patch
from nose.tools import (eq_, ok_, raises)
from github2.core import (AuthError, repr_string, requires_auth)
from github2.issues import Issue
from github2.client import Github
import utils
class ReprTests(unittest.TestCase):
"""__repr__ must return strings, not unicode objects."""
def test_issue(self):
"""Issues can have non-ASCII characters in the title."""
title = 'abcdé'
i = Issue(title=title)
eq_(str, type(repr(i)))
class HostSetting(unittest.TestCase):
def test_default_host(self):
client = Github()
eq_(client.request.github_url, 'https://github.com')
def test_non_standard_host(self):
client = Github(github_url="http://your-github-enterprise-url.com/")
eq_(client.request.github_url,
'http://your-github-enterprise-url.com/')
class RateLimits(utils.HttpMockTestCase):
"""Test API rate-limiting."""
@patch('github2.request.time.sleep')
def test_delays(self, sleep):
"""Test calls in quick succession are delayed."""
client = Github(requests_per_second=.5)
client.users.show('defunkt')
client.users.show('mojombo')
# 0.5 requests per second, means a two second delay
sleep.assert_called_once_with(2.0)
class BaseDataIter(utils.HttpMockTestCase):
"""Test iter availability of objects."""
def test_iter(self):
commit_id = '1c83cde9b5a7c396a01af1007fb7b88765b9ae45'
commit = self.client.commits.show('ask/python-github2', commit_id)
ok_('__iter__' in dir(commit))
class BaseDataDict(utils.HttpMockTestCase):
"""Test dict compatibility on objects."""
def test_getitem(self):
user = self.client.users.show('defunkt')
eq_(user['blog'], user.blog)
eq_(user['company'], user.company)
eq_(user['email'], user.email)
eq_(user['location'], user.location)
eq_(user['login'], user.login)
eq_(user['name'], user.name)
@raises(KeyError)
def test_getitem_failure(self):
user = self.client.users.show('defunkt')
ok_(user['invalid_key'])
def test_setitem(self):
user = self.client.users.show('defunkt')
user['blog'] = 'http://example.com'
eq_(user['blog'], 'http://example.com')
@raises(KeyError)
def test_setitem_failure(self):
user = self.client.users.show('defunkt')
user['invalid_key'] = 'test'
def test_project_for_user_repo():
client = Github()
eq_(client.project_for_user_repo('JNRowe', 'misc-overlay'),
'JNRowe/misc-overlay')
def test_repr_string():
eq_(repr_string('test'), 'test')
eq_(repr_string('abcdefghijklmnopqrst'), 'abcdefghijklmnopqrst')
eq_(repr_string('abcdefghijklmnopqrstu'), 'abcdefghijklmnopq...')
class RequiresAuth(utils.HttpMockTestCase):
@raises(AuthError)
def test_no_auth(self):
f = lambda: None
f.__doc__ = 'test func'
wrapped = requires_auth(f)
wrapped(self.client)