comparison venv/lib/python2.7/site-packages/github/tests/BadAttributes.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2
3 # ########################## Copyrights and license ############################
4 # #
5 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
6 # #
7 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
8 # #
9 # PyGithub is free software: you can redistribute it and/or modify it under #
10 # the terms of the GNU Lesser General Public License as published by the Free #
11 # Software Foundation, either version 3 of the License, or (at your option) #
12 # any later version. #
13 # #
14 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
16 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
17 # details. #
18 # #
19 # You should have received a copy of the GNU Lesser General Public License #
20 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
21 # #
22 # ##############################################################################
23
24 import datetime
25
26 import Framework
27 import github
28
29
30 # Replay data is forged to simulate bad things returned by Github
31 class BadAttributes(Framework.TestCase):
32 def testBadSimpleAttribute(self):
33 user = self.g.get_user("klmitch")
34 self.assertEqual(user.created_at, datetime.datetime(2011, 3, 23, 15, 42, 9))
35
36 raised = False
37 try:
38 user.name
39 except github.BadAttributeException, e:
40 raised = True
41 self.assertEqual(e.actual_value, 42)
42 self.assertEqual(e.expected_type, (str, unicode))
43 self.assertEqual(e.transformation_exception, None)
44 self.assertTrue(raised)
45
46 def testBadAttributeTransformation(self):
47 user = self.g.get_user("klmitch")
48 self.assertEqual(user.name, "Kevin L. Mitchell")
49
50 raised = False
51 try:
52 user.created_at
53 except github.BadAttributeException, e:
54 raised = True
55 self.assertEqual(e.actual_value, "foobar")
56 self.assertEqual(e.expected_type, (str, unicode))
57 self.assertEqual(e.transformation_exception.__class__, ValueError)
58 if Framework.atLeastPython26:
59 self.assertEqual(e.transformation_exception.args, ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",))
60 else:
61 self.assertEqual(e.transformation_exception.args, ('time data did not match format: data=foobar fmt=%Y-%m-%dT%H:%M:%SZ',))
62 self.assertTrue(raised)
63
64 def testBadTransformedAttribute(self):
65 user = self.g.get_user("klmitch")
66 self.assertEqual(user.name, "Kevin L. Mitchell")
67
68 raised = False
69 try:
70 user.updated_at
71 except github.BadAttributeException, e:
72 raised = True
73 self.assertEqual(e.actual_value, 42)
74 self.assertEqual(e.expected_type, (str, unicode))
75 self.assertEqual(e.transformation_exception, None)
76 self.assertTrue(raised)
77
78 def testBadSimpleAttributeInList(self):
79 hook = self.g.get_hook("activecollab")
80 self.assertEqual(hook.name, "activecollab")
81
82 raised = False
83 try:
84 hook.events
85 except github.BadAttributeException, e:
86 raised = True
87 self.assertEqual(e.actual_value, ["push", 42])
88 self.assertEqual(e.expected_type, [(str, unicode)])
89 self.assertEqual(e.transformation_exception, None)
90 self.assertTrue(raised)
91
92 def testBadAttributeInClassAttribute(self):
93 repo = self.g.get_repo("klmitch/turnstile")
94 owner = repo.owner
95 self.assertEqual(owner.id, 686398)
96
97 raised = False
98 try:
99 owner.avatar_url
100 except github.BadAttributeException, e:
101 raised = True
102 self.assertEqual(e.actual_value, 42)
103 self.assertTrue(raised)
104
105 def testBadTransformedAttributeInList(self):
106 commit = self.g.get_repo("klmitch/turnstile").get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26")
107
108 raised = False
109 try:
110 commit.files
111 except github.BadAttributeException, e:
112 raised = True
113 self.assertEqual(e.actual_value, [42])
114 self.assertEqual(e.expected_type, [dict])
115 self.assertEqual(e.transformation_exception, None)
116 self.assertTrue(raised)
117
118 def testBadTransformedAttributeInDict(self):
119 gist = self.g.get_gist("6437766")
120
121 raised = False
122 try:
123 gist.files
124 except github.BadAttributeException, e:
125 raised = True
126 self.assertEqual(e.actual_value, {"test.py": 42})
127 self.assertEqual(e.expected_type, {(str, unicode): dict})
128 self.assertEqual(e.transformation_exception, None)
129 self.assertTrue(raised)
130
131 def testIssue195(self):
132 hooks = self.g.get_hooks()
133 # We can loop on all hooks as long as we don't access circleci's events attribute
134 self.assertListKeyEqual(hooks, lambda h: h.name, [u'activecollab', u'acunote', u'agilebench', u'agilezen', u'amazonsns', u'apiary', u'apoio', u'appharbor', u'apropos', u'asana', u'backlog', u'bamboo', u'basecamp', u'bcx', u'blimp', u'boxcar', u'buddycloud', u'bugherd', u'bugly', u'bugzilla', u'campfire', u'cia', u'circleci', u'codeclimate', u'codeportingcsharp2java', u'codeship', u'coffeedocinfo', u'conductor', u'coop', u'copperegg', u'cube', u'depending', u'deployhq', u'devaria', u'docker', u'ducksboard', u'email', u'firebase', u'fisheye', u'flowdock', u'fogbugz', u'freckle', u'friendfeed', u'gemini', u'gemnasium', u'geocommit', u'getlocalization', u'gitlive', u'grmble', u'grouptalent', u'grove', u'habitualist', u'hakiri', u'hall', u'harvest', u'hipchat', u'hostedgraphite', u'hubcap', u'hubci', u'humbug', u'icescrum', u'irc', u'irker', u'ironmq', u'ironworker', u'jabber', u'jaconda', u'jeapie', u'jenkins', u'jenkinsgit', u'jira', u'jqueryplugins', u'kanbanery', u'kickoff', u'leanto', u'lechat', u'lighthouse', u'lingohub', u'loggly', u'mantisbt', u'masterbranch', u'mqttpub', u'nma', u'nodejitsu', u'notifo', u'ontime', u'pachube', u'packagist', u'phraseapp', u'pivotaltracker', u'planbox', u'planio', u'prowl', u'puppetlinter', u'pushalot', u'pushover', u'pythonpackages', u'railsbp', u'railsbrakeman', u'rally', u'rapidpush', u'rationaljazzhub', u'rationalteamconcert', u'rdocinfo', u'readthedocs', u'redmine', u'rubyforge', u'scrumdo', u'shiningpanda', u'sifter', u'simperium', u'slatebox', u'snowyevening', u'socialcast', u'softlayermessaging', u'sourcemint', u'splendidbacon', u'sprintly', u'sqsqueue', u'stackmob', u'statusnet', u'talker', u'targetprocess', u'tddium', u'teamcity', u'tender', u'tenxer', u'testpilot', u'toggl', u'trac', u'trajectory', u'travis', u'trello', u'twilio', u'twitter', u'unfuddle', u'web', u'weblate', u'webtranslateit', u'yammer', u'youtrack', u'zendesk', u'zohoprojects'])
135 for hook in hooks:
136 if hook.name != "circleci":
137 hook.events
138
139 raised = False
140 for hook in hooks:
141 if hook.name == "circleci":
142 try:
143 hook.events
144 except github.BadAttributeException, e:
145 raised = True
146 self.assertEqual(e.actual_value, [["commit_comment", "create", "delete", "download", "follow", "fork", "fork_apply", "gist", "gollum", "issue_comment", "issues", "member", "public", "pull_request", "pull_request_review_comment", "push", "status", "team_add", "watch"]])
147 self.assertEqual(e.expected_type, [(str, unicode)])
148 self.assertEqual(e.transformation_exception, None)
149 self.assertTrue(raised)