File: BadAttributes.py

package info (click to toggle)
pygithub 1.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,432 kB
  • ctags: 1,780
  • sloc: python: 10,689; makefile: 6
file content (149 lines) | stat: -rwxr-xr-x 8,361 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-

# ########################## Copyrights and license ############################
#                                                                              #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
#                                                                              #
# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/          #
#                                                                              #
# PyGithub is free software: you can redistribute it and/or modify it under    #
# the terms of the GNU Lesser General Public License as published by the Free  #
# Software Foundation, either version 3 of the License, or (at your option)    #
# any later version.                                                           #
#                                                                              #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details.                                                                     #
#                                                                              #
# You should have received a copy of the GNU Lesser General Public License     #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
#                                                                              #
# ##############################################################################

import datetime

import Framework
import github


# Replay data is forged to simulate bad things returned by Github
class BadAttributes(Framework.TestCase):
    def testBadSimpleAttribute(self):
        user = self.g.get_user("klmitch")
        self.assertEqual(user.created_at, datetime.datetime(2011, 3, 23, 15, 42, 9))

        raised = False
        try:
            user.name
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, 42)
            self.assertEqual(e.expected_type, (str, unicode))
            self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)

    def testBadAttributeTransformation(self):
        user = self.g.get_user("klmitch")
        self.assertEqual(user.name, "Kevin L. Mitchell")

        raised = False
        try:
            user.created_at
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, "foobar")
            self.assertEqual(e.expected_type, (str, unicode))
            self.assertEqual(e.transformation_exception.__class__, ValueError)
            if Framework.atLeastPython26:
                self.assertEqual(e.transformation_exception.args, ("time data 'foobar' does not match format '%Y-%m-%dT%H:%M:%SZ'",))
            else:
                self.assertEqual(e.transformation_exception.args, ('time data did not match format:  data=foobar  fmt=%Y-%m-%dT%H:%M:%SZ',))
        self.assertTrue(raised)

    def testBadTransformedAttribute(self):
        user = self.g.get_user("klmitch")
        self.assertEqual(user.name, "Kevin L. Mitchell")

        raised = False
        try:
            user.updated_at
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, 42)
            self.assertEqual(e.expected_type, (str, unicode))
            self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)

    def testBadSimpleAttributeInList(self):
        hook = self.g.get_hook("activecollab")
        self.assertEqual(hook.name, "activecollab")

        raised = False
        try:
            hook.events
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, ["push", 42])
            self.assertEqual(e.expected_type, [(str, unicode)])
            self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)

    def testBadAttributeInClassAttribute(self):
        repo = self.g.get_repo("klmitch/turnstile")
        owner = repo.owner
        self.assertEqual(owner.id, 686398)

        raised = False
        try:
            owner.avatar_url
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, 42)
        self.assertTrue(raised)

    def testBadTransformedAttributeInList(self):
        commit = self.g.get_repo("klmitch/turnstile").get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26")

        raised = False
        try:
            commit.files
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, [42])
            self.assertEqual(e.expected_type, [dict])
            self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)

    def testBadTransformedAttributeInDict(self):
        gist = self.g.get_gist("6437766")

        raised = False
        try:
            gist.files
        except github.BadAttributeException, e:
            raised = True
            self.assertEqual(e.actual_value, {"test.py": 42})
            self.assertEqual(e.expected_type, {(str, unicode): dict})
            self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)

    def testIssue195(self):
        hooks = self.g.get_hooks()
        # We can loop on all hooks as long as we don't access circleci's events attribute
        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'])
        for hook in hooks:
            if hook.name != "circleci":
                hook.events

        raised = False
        for hook in hooks:
            if hook.name == "circleci":
                try:
                    hook.events
                except github.BadAttributeException, e:
                    raised = True
                    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"]])
                    self.assertEqual(e.expected_type, [(str, unicode)])
                    self.assertEqual(e.transformation_exception, None)
        self.assertTrue(raised)