|
| 1 | +import github3 |
| 2 | +import datetime |
| 3 | +from tests.utils import BaseCase, load, expect |
| 4 | + |
| 5 | + |
| 6 | +class TestLabel(BaseCase): |
| 7 | + def __init__(self, methodName='runTest'): |
| 8 | + super(TestLabel, self).__init__(methodName) |
| 9 | + self.l = github3.issues.Label(load('label')) |
| 10 | + self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" |
| 11 | + "labels/bug") |
| 12 | + |
| 13 | + def setUp(self): |
| 14 | + super(TestLabel, self).setUp() |
| 15 | + self.l = github3.issues.Label(self.l.to_json(), self.g) |
| 16 | + |
| 17 | + def test_repr(self): |
| 18 | + expect(repr(self.l)) == '<Label [{0}]>'.format(self.l.name) |
| 19 | + |
| 20 | + def test_str(self): |
| 21 | + expect(str(self.l)) == self.l.name |
| 22 | + |
| 23 | + def test_delete(self): |
| 24 | + self.response('', 204) |
| 25 | + self.delete(self.api) |
| 26 | + |
| 27 | + with expect.githuberror(): |
| 28 | + self.l.delete() |
| 29 | + |
| 30 | + self.not_called() |
| 31 | + self.login() |
| 32 | + expect(self.l.delete()).is_True() |
| 33 | + |
| 34 | + def test_update(self): |
| 35 | + self.response('label', 200) |
| 36 | + self.patch(self.api) |
| 37 | + self.conf = {'data': {'name': 'newname', 'color': 'afafaf'}} |
| 38 | + |
| 39 | + with expect.githuberror(): |
| 40 | + self.l.update(None, None) |
| 41 | + |
| 42 | + self.login() |
| 43 | + expect(self.l.update(None, None)).is_False() |
| 44 | + self.not_called() |
| 45 | + |
| 46 | + expect(self.l.update('newname', 'afafaf')).is_True() |
| 47 | + self.mock_assertions() |
| 48 | + |
| 49 | + expect(self.l.update('newname', '#afafaf')).is_True() |
| 50 | + self.mock_assertions() |
| 51 | + |
| 52 | + |
| 53 | +class TestMilestone(BaseCase): |
| 54 | + def __init__(self, methodName='runTest'): |
| 55 | + super(TestMilestone, self).__init__(methodName) |
| 56 | + self.m = github3.issues.Milestone(load('milestone')) |
| 57 | + self.api = ("https://api.github.com/repos/kennethreitz/requests/" |
| 58 | + "milestones/18") |
| 59 | + |
| 60 | + def setUp(self): |
| 61 | + super(TestMilestone, self).setUp() |
| 62 | + self.m = github3.issues.Milestone(self.m.to_json(), self.g) |
| 63 | + |
| 64 | + def test_repr(self): |
| 65 | + expect(repr(self.m)) == '<Milestone [v1.0.0]>' |
| 66 | + |
| 67 | + def test_str(self): |
| 68 | + expect(str(self.m)) == 'v1.0.0' |
| 69 | + |
| 70 | + def test_delete(self): |
| 71 | + self.response('', 204) |
| 72 | + self.delete(self.api) |
| 73 | + |
| 74 | + with expect.githuberror(): |
| 75 | + self.m.delete() |
| 76 | + |
| 77 | + self.not_called() |
| 78 | + self.login() |
| 79 | + expect(self.m.delete()).is_True() |
| 80 | + self.mock_assertions() |
| 81 | + |
| 82 | + def test_due_on(self): |
| 83 | + json = self.m.to_json().copy() |
| 84 | + json['due_on'] = '2012-12-31T23:59:59Z' |
| 85 | + m = github3.issues.Milestone(json) |
| 86 | + expect(m.due_on).isinstance(datetime.datetime) |
| 87 | + |
| 88 | + def test_iter_labels(self): |
| 89 | + self.response('label', _iter=True) |
| 90 | + self.get(self.api + '/labels') |
| 91 | + |
| 92 | + i = self.m.iter_labels() |
| 93 | + expect(i).isinstance(github3.structs.GitHubIterator) |
| 94 | + expect(next(i)).isinstance(github3.issues.Label) |
| 95 | + self.mock_assertions() |
| 96 | + |
| 97 | + def test_update(self): |
| 98 | + self.response('milestone', 200) |
| 99 | + self.patch(self.api) |
| 100 | + self.conf = { |
| 101 | + 'data': { |
| 102 | + 'title': 'foo', |
| 103 | + 'state': 'closed', |
| 104 | + 'description': ':sparkles:', |
| 105 | + 'due_on': '2013-12-31T23:59:59Z' |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + with expect.githuberror(): |
| 110 | + self.m.update(None) |
| 111 | + |
| 112 | + self.login() |
| 113 | + expect(self.m.update(None)).is_False() |
| 114 | + self.not_called() |
| 115 | + |
| 116 | + expect(self.m.update('foo', 'closed', ':sparkles:', |
| 117 | + '2013-12-31TZ23:59:59Z')).is_True() |
| 118 | + self.mock_assertions() |
| 119 | + |
| 120 | + |
| 121 | +class TestIssue(BaseCase): |
| 122 | + def __init__(self, methodName='runTest'): |
| 123 | + super(TestIssue, self).__init__(methodName) |
| 124 | + self.i = github3.issues.Issue(load('issue')) |
| 125 | + self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" |
| 126 | + "issues/1") |
| 127 | + |
| 128 | + def setUp(self): |
| 129 | + super(TestIssue, self).setUp() |
| 130 | + self.i = github3.issues.Issue(self.i.to_json(), self.g) |
| 131 | + |
| 132 | + def test_repr(self): |
| 133 | + expect(repr(self.i)) == '<Issue [sigmavirus24/github3.py #1]>' |
0 commit comments