Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/github/tests/Logging_.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 2012 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 6 # Copyright 2012 Zearin <zearin@gonk.net> # | |
| 7 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 8 # # | |
| 9 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ # | |
| 10 # # | |
| 11 # PyGithub is free software: you can redistribute it and/or modify it under # | |
| 12 # the terms of the GNU Lesser General Public License as published by the Free # | |
| 13 # Software Foundation, either version 3 of the License, or (at your option) # | |
| 14 # any later version. # | |
| 15 # # | |
| 16 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # | |
| 17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
| 18 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # | |
| 19 # details. # | |
| 20 # # | |
| 21 # You should have received a copy of the GNU Lesser General Public License # | |
| 22 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # | |
| 23 # # | |
| 24 # ############################################################################## | |
| 25 | |
| 26 import logging | |
| 27 import sys | |
| 28 | |
| 29 import github | |
| 30 | |
| 31 import Framework | |
| 32 | |
| 33 atMostPython32 = sys.hexversion < 0x03030000 | |
| 34 | |
| 35 | |
| 36 class Logging(Framework.BasicTestCase): | |
| 37 class MockHandler: | |
| 38 def __init__(self): | |
| 39 self.level = logging.DEBUG | |
| 40 self.handled = None | |
| 41 | |
| 42 def handle(self, record): | |
| 43 self.handled = record.getMessage() | |
| 44 | |
| 45 def setUp(self): | |
| 46 Framework.BasicTestCase.setUp(self) | |
| 47 logger = logging.getLogger("github") | |
| 48 logger.setLevel(logging.DEBUG) | |
| 49 self.__handler = self.MockHandler() | |
| 50 logger.addHandler(self.__handler) | |
| 51 | |
| 52 def testLoggingWithBasicAuthentication(self): | |
| 53 self.assertEqual(github.Github(self.login, self.password).get_user().name, "Vincent Jacques") | |
| 54 # In Python 3.3, dicts are not output in the same order as in Python 2.5 -> 3.2. | |
| 55 # So, logging is not deterministic and we cannot test it. | |
| 56 if atMostPython32: | |
| 57 self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'Basic (login and password removed)\', \'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'806\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'x-ratelimit-remaining\': \'4993\', \'server\': \'nginx\', \'last-modified\': \'Fri, 14 Sep 2012 18:47:46 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"434dfe5d3f50558fe3cea087cb95c401"\', \'cache-control\': \'private, s-maxage=60, max-age=60\', \'date\': \'Mon, 17 Sep 2012 17:12:32 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"jacquev6","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"vincent@vincent-jacques.net","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}') | |
| 58 | |
| 59 def testLoggingWithOAuthAuthentication(self): | |
| 60 self.assertEqual(github.Github(self.oauth_token).get_user().name, "Vincent Jacques") | |
| 61 if atMostPython32: | |
| 62 self.assertEqual(self.__handler.handled, 'GET https://api.github.com/user {\'Authorization\': \'token (oauth token removed)\', \'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'x-ratelimit-remaining\': \'4993\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'content-length\': \'628\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"c23ad6b5815fc3d6ec6341c4a47afe85"\', \'cache-control\': \'private, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:36:54 GMT\', \'x-oauth-scopes\': \'\', \'content-type\': \'application/json; charset=utf-8\', \'x-accepted-oauth-scopes\': \'user\'} {"type":"User","bio":"","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","blog":"http://vincent-jacques.net","public_repos":13,"created_at":"2010-07-09T06:10:06Z","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","email":"vincent@vincent-jacques.net","following":29,"name":"Vincent Jacques","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","hireable":false,"id":327146,"public_gists":3,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') | |
| 63 | |
| 64 def testLoggingWithoutAuthentication(self): | |
| 65 self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques") | |
| 66 if atMostPython32: | |
| 67 self.assertEqual(self.__handler.handled, 'GET https://api.github.com/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') | |
| 68 | |
| 69 def testLoggingWithBaseUrl(self): | |
| 70 # ReplayData forged, not recorded | |
| 71 self.assertEqual(github.Github(base_url="http://my.enterprise.com/my/prefix").get_user("jacquev6").name, "Vincent Jacques") | |
| 72 if atMostPython32: | |
| 73 self.assertEqual(self.__handler.handled, 'GET http://my.enterprise.com/my/prefix/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}') |
