forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_models.py
More file actions
70 lines (54 loc) · 2.14 KB
/
test_models.py
File metadata and controls
70 lines (54 loc) · 2.14 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
from datetime import timedelta
import github3
import requests
from tests.utils import BaseCase, TestCase, RequestsBytesIO, is_py3
class TestGitHubObject(TestCase):
def test_from_json(self):
o = github3.models.GitHubObject.from_json({})
assert isinstance(o, github3.models.GitHubObject)
class TestGitHubCore(BaseCase):
def setUp(self):
super(TestGitHubCore, self).setUp()
self.g = github3.models.GitHubCore({})
def test_repr(self):
g = self.g
assert repr(g) == '<github3-core at 0x{0:x}>'.format(id(g))
def test_json(self):
r = requests.Response()
r.headers['Last-Modified'] = 'foo'
r.headers['ETag'] = 'bar'
r.raw = RequestsBytesIO('{}'.encode() if is_py3 else '{}')
r.status_code = 200
json = self.g._json(r, 200)
assert json['Last-Modified'] == 'foo'
assert json['ETag'] == 'bar'
def test_boolean(self):
r = requests.Response()
r.status_code = 512
r.raw = RequestsBytesIO('{}'.encode() if is_py3 else '{}')
self.assertRaises(github3.GitHubError, self.g._boolean, r, 200, 404)
def test_strptime(self):
dt = self.g._strptime('2013-06-18T19:53:04Z')
assert dt.tzname() == 'UTC'
assert dt.dst() == timedelta(0)
assert dt.utcoffset() == timedelta(0)
class TestGitHubError(TestCase):
def __init__(self, methodName='runTest'):
super(TestGitHubError, self).__init__(methodName)
self.r = requests.Response()
self.r.status_code = 400
message = '{"message": "m", "errors": ["e"]}'
self.r.raw = RequestsBytesIO(message.encode() if is_py3 else message)
self.error = github3.models.GitHubError(self.r)
def test_repr(self):
assert repr(self.error) == '<GitHubError [m]>'
def test_str(self):
assert str(self.error) == '400 m'
def test_message(self):
assert self.error.message == self.error.msg
def test_amazon(self):
r = requests.Response()
r.status_code = 400
r.raw = RequestsBytesIO()
e = github3.models.GitHubError(r)
assert e.message == '[No message]'