From e18b107883bfc40ff43f2269a933049d94e30642 Mon Sep 17 00:00:00 2001 From: Bruce Richardson Date: Wed, 3 Oct 2018 04:51:59 +0100 Subject: [PATCH] Gists with since (#914) The Github gists api has a since parameter for the various gist searches. This adds that parameter to Github.get_gists(), NamedUser.get_gists() and Authenticator.get_gists(). Tests and replay data added/updated as needed. I added a Time module in the tests directory, containing just a UTCtzinfo class, which I felt I needed for one of the tests (and would probably be useful in other since/until tests). Might not be the best name for the module but it seemed the least invasive thing to do. --- github/AuthenticatedUser.py | 12 +++++-- github/MainClass.py | 12 +++++-- github/NamedUser.py | 12 +++++-- github/tests/AuthenticatedUser.py | 4 ++- github/tests/Github_.py | 6 ++++ github/tests/NamedUser.py | 2 ++ .../AuthenticatedUser.testGetGists.txt | 11 ++++++ .../Github.testGetGistsWithSince.txt | 11 ++++++ .../ReplayData/NamedUser.testGetGists.txt | 11 ++++++ github/tests/Time.py | 34 +++++++++++++++++++ 10 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 github/tests/ReplayData/Github.testGetGistsWithSince.txt create mode 100644 github/tests/Time.py diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index adb94d39..c9bcfbd5 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -14,12 +14,13 @@ # Copyright 2016 E. Dunham # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Balázs Rostás # +# Copyright 2017 Balázs Rostás # # Copyright 2017 Jannis Gebauer # # Copyright 2017 Simon # # Copyright 2018 Wan Liuyang # # Copyright 2018 bryanhuntesl <31992054+bryanhuntesl@users.noreply.github.com> # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -703,16 +704,21 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): None ) - def get_gists(self): + def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /gists `_ + :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + url_parameters = dict() + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( github.Gist.Gist, self._requester, "/gists", - None + url_parameters ) def get_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet): diff --git a/github/MainClass.py b/github/MainClass.py index 48f7ab8c..40b19f3b 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -27,6 +27,7 @@ # Copyright 2018 Svend Sorensen # # Copyright 2018 Wan Liuyang # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -46,6 +47,8 @@ # # ################################################################################ +import datetime + import urllib import pickle import time @@ -334,16 +337,21 @@ class Github(object): ) return github.Gist.Gist(self.__requester, headers, data, completed=True) - def get_gists(self): + def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /gists/public `_ + :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + url_parameters = dict() + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( github.Gist.Gist, self.__requester, "/gists/public", - None + url_parameters ) def search_repositories(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): diff --git a/github/NamedUser.py b/github/NamedUser.py index 63dd4988..6e3c7d5d 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -17,6 +17,7 @@ # Copyright 2018 Wan Liuyang # # Copyright 2018 namc # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -36,6 +37,8 @@ # # ################################################################################ +import datetime + import github.GithubObject import github.PaginatedList @@ -402,16 +405,21 @@ class NamedUser(github.GithubObject.CompletableGithubObject): None ) - def get_gists(self): + def get_gists(self, since=github.GithubObject.NotSet): """ :calls: `GET /users/:user/gists `_ + :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + url_parameters = dict() + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") return github.PaginatedList.PaginatedList( github.Gist.Gist, self._requester, self.url + "/gists", - None + url_parameters ) def get_keys(self): diff --git a/github/tests/AuthenticatedUser.py b/github/tests/AuthenticatedUser.py index c894509a..a92778f5 100644 --- a/github/tests/AuthenticatedUser.py +++ b/github/tests/AuthenticatedUser.py @@ -8,10 +8,11 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Balázs Rostás # +# Copyright 2017 Balázs Rostás # # Copyright 2017 Jannis Gebauer # # Copyright 2018 Jacopo Notarstefano # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -186,6 +187,7 @@ class AuthenticatedUser(Framework.TestCase): def testGetGists(self): self.assertListKeyEqual(self.user.get_gists(), lambda g: g.id, ["2793505", "2793179", "11cb445f8197e17d303d", "1942384", "dcb7de17e8a52b74541d"]) + self.assertListKeyEqual(self.user.get_gists(since=datetime.datetime(2012, 3, 1, 23, 0, 0)), lambda g: g.id, ["2793505", "2793179", "11cb445f8197e17d303d"]) def testGetStarredGists(self): self.assertListKeyEqual(self.user.get_starred_gists(), lambda g: g.id, ["1942384", "dcb7de17e8a52b74541d"]) diff --git a/github/tests/Github_.py b/github/tests/Github_.py index f66558b3..5966f481 100644 --- a/github/tests/Github_.py +++ b/github/tests/Github_.py @@ -12,6 +12,7 @@ # Copyright 2018 Svend Sorensen # # Copyright 2018 Wan Liuyang # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -35,6 +36,8 @@ import datetime import Framework +import Time + import github @@ -42,6 +45,9 @@ class Github(Framework.TestCase): def testGetGists(self): self.assertListKeyBegin(self.g.get_gists(), lambda g: g.id, ["2729695", "2729656", "2729597", "2729584", "2729569", "2729554", "2729543", "2729537", "2729536", "2729533", "2729525", "2729522", "2729519", "2729515", "2729506", "2729487", "2729484", "2729482", "2729441", "2729432", "2729420", "2729398", "2729372", "2729371", "2729351", "2729346", "2729316", "2729304", "2729296", "2729276", "2729272", "2729265", "2729195", "2729160", "2729143", "2729127", "2729119", "2729113", "2729103", "2729069", "2729059", "2729051", "2729029", "2729027", "2729026", "2729022", "2729002", "2728985", "2728979", "2728964", "2728937", "2728933", "2728884", "2728869", "2728866", "2728855", "2728854", "2728853", "2728846", "2728825", "2728814", "2728813", "2728812", "2728805", "2728802", "2728800", "2728798", "2728797", "2728796", "2728793", "2728758", "2728754", "2728751", "2728748", "2728721", "2728716", "2728715", "2728705", "2728701", "2728699", "2728697", "2728688", "2728683", "2728677", "2728649", "2728640", "2728625", "2728620", "2728615", "2728614", "2728565", "2728564", "2728554", "2728523", "2728519", "2728511", "2728497", "2728496", "2728495", "2728487"]) + def testGetGistsWithSince(self): + self.assertListKeyBegin(self.g.get_gists(since=datetime.datetime(2018,10,2,10,38,30,00,tzinfo=Time.UTCtzinfo())), lambda g: g.id, ["69b8a5831b74946db944c5451017fa40", "c22050a8705e93d170e0d4ca9c02e40c", "a7a95e1a194e07960364a5b32c56ac5f", "a25d9ace89b574f95bf0724f95a84fc2", "3195465"]) + def testGetHooks(self): hooks = self.g.get_hooks() hook = hooks[0] diff --git a/github/tests/NamedUser.py b/github/tests/NamedUser.py index 2961cc55..01371b7f 100644 --- a/github/tests/NamedUser.py +++ b/github/tests/NamedUser.py @@ -11,6 +11,7 @@ # Copyright 2017 Simon # # Copyright 2018 namc # # Copyright 2018 sfdye # +# Copyright 2018 itsbruce # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -107,6 +108,7 @@ class NamedUser(Framework.TestCase): def testGetGists(self): self.assertListKeyEqual(self.user.get_gists(), lambda g: g.description, ["Gist created by PyGithub", "FairThreadPoolPool.cpp", "How to error 500 Github API v3, as requested by Rick (GitHub Staff)", "Cadfael: order of episodes in French DVD edition"]) + self.assertListKeyEqual(self.user.get_gists(since=datetime.datetime(2012, 3, 1, 17, 0, 0)), lambda g: g.description, ["Gist created by PyGithub", "FairThreadPoolPool.cpp"]) def testGetFollowers(self): self.assertListKeyEqual(self.user.get_followers(), lambda f: f.login, ["jnorthrup", "brugidou", "regisb", "walidk", "afzalkhan", "sdanzan", "vineus", "gturri", "fjardon", "cjuniet", "jardon-u", "kamaradclimber", "L42y"]) diff --git a/github/tests/ReplayData/AuthenticatedUser.testGetGists.txt b/github/tests/ReplayData/AuthenticatedUser.testGetGists.txt index ee4acbe7..66a74a55 100644 --- a/github/tests/ReplayData/AuthenticatedUser.testGetGists.txt +++ b/github/tests/ReplayData/AuthenticatedUser.testGetGists.txt @@ -9,3 +9,14 @@ None [('status', '200 OK'), ('x-ratelimit-remaining', '4966'), ('content-length', '4507'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"868b9c31808f738e0f03284a2e538a41"'), ('date', 'Sat, 26 May 2012 20:14:40 GMT'), ('content-type', 'application/json; charset=utf-8')] [{"updated_at":"2012-05-26T11:08:22Z","url":"https://api.github.com/gists/2793505","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793505.git","git_push_url":"git@gist.github.com:2793505.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793505/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":null,"created_at":"2012-05-26T11:08:22Z","id":"2793505","html_url":"https://gist.github.com/2793505"},{"updated_at":"2012-05-26T10:09:33Z","url":"https://api.github.com/gists/2793179","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793179.git","git_push_url":"git@gist.github.com:2793179.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793179/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Gist created by PyGithub","created_at":"2012-05-26T09:50:02Z","id":"2793179","html_url":"https://gist.github.com/2793179"},{"updated_at":"2012-04-26T13:20:53Z","url":"https://api.github.com/gists/11cb445f8197e17d303d","comments":0,"public":false,"git_pull_url":"git://gist.github.com/11cb445f8197e17d303d.git","git_push_url":"git@gist.github.com:11cb445f8197e17d303d.git","files":{"FairThreadPoolPool.cpp":{"type":"text/plain","raw_url":"https://gist.github.com/raw/11cb445f8197e17d303d/0f72c6fe50eb011eacb4e39fa613bdfe2f7a0c51/FairThreadPoolPool.cpp","size":7779,"filename":"FairThreadPoolPool.cpp","language":"C++"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"FairThreadPoolPool.cpp","created_at":"2012-04-26T13:20:53Z","id":"11cb445f8197e17d303d","html_url":"https://gist.github.com/11cb445f8197e17d303d"},{"updated_at":"2012-02-29T16:47:12Z","url":"https://api.github.com/gists/1942384","comments":0,"public":true,"git_pull_url":"git://gist.github.com/1942384.git","git_push_url":"git@gist.github.com:1942384.git","files":{"fail_github.py":{"type":"application/python","raw_url":"https://gist.github.com/raw/1942384/2fb3aa84e0efa50dc0f4c18b5df5b7b9ab27076b/fail_github.py","size":1636,"filename":"fail_github.py","language":"Python"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"How to error 500 Github API v3, as requested by Rick (GitHub Staff)","created_at":"2012-02-29T16:47:12Z","id":"1942384","html_url":"https://gist.github.com/1942384"},{"updated_at":"2012-02-28T19:44:42Z","url":"https://api.github.com/gists/dcb7de17e8a52b74541d","comments":1,"public":false,"git_pull_url":"git://gist.github.com/dcb7de17e8a52b74541d.git","git_push_url":"git@gist.github.com:dcb7de17e8a52b74541d.git","files":{"cadfael.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/dcb7de17e8a52b74541d/48ca696645682d7430d73180814434e0284796b2/cadfael.txt","size":585,"filename":"cadfael.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Cadfael: order of episodes in French DVD edition","created_at":"2012-02-28T19:44:42Z","id":"dcb7de17e8a52b74541d","html_url":"https://gist.github.com/dcb7de17e8a52b74541d"}] +https +GET +api.github.com +None +/gists?since=2012-03-01T23%3A00%3A00Z +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4966'), ('content-length', '2637'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"683e9f38128c378e0a30284b2e539a14"'), ('date', 'Sat, 26 May 2012 20:15:03 GMT'), ('content-type', 'application/json; charset=utf-8')] +[{"updated_at":"2012-05-26T11:08:22Z","url":"https://api.github.com/gists/2793505","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793505.git","git_push_url":"git@gist.github.com:2793505.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793505/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":null,"created_at":"2012-05-26T11:08:22Z","id":"2793505","html_url":"https://gist.github.com/2793505"},{"updated_at":"2012-05-26T10:09:33Z","url":"https://api.github.com/gists/2793179","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793179.git","git_push_url":"git@gist.github.com:2793179.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793179/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Gist created by PyGithub","created_at":"2012-05-26T09:50:02Z","id":"2793179","html_url":"https://gist.github.com/2793179"},{"updated_at":"2012-04-26T13:20:53Z","url":"https://api.github.com/gists/11cb445f8197e17d303d","comments":0,"public":false,"git_pull_url":"git://gist.github.com/11cb445f8197e17d303d.git","git_push_url":"git@gist.github.com:11cb445f8197e17d303d.git","files":{"FairThreadPoolPool.cpp":{"type":"text/plain","raw_url":"https://gist.github.com/raw/11cb445f8197e17d303d/0f72c6fe50eb011eacb4e39fa613bdfe2f7a0c51/FairThreadPoolPool.cpp","size":7779,"filename":"FairThreadPoolPool.cpp","language":"C++"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"FairThreadPoolPool.cpp","created_at":"2012-04-26T13:20:53Z","id":"11cb445f8197e17d303d","html_url":"https://gist.github.com/11cb445f8197e17d303d"}] + diff --git a/github/tests/ReplayData/Github.testGetGistsWithSince.txt b/github/tests/ReplayData/Github.testGetGistsWithSince.txt new file mode 100644 index 00000000..9748985a --- /dev/null +++ b/github/tests/ReplayData/Github.testGetGistsWithSince.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/gists/public?since=2018-10-02T10%3A38%3A30Z +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Tue, 02 Oct 2018 10:39:11 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1538478827'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('ETag', 'W/"5437ff694e11dc6803fe9a1d5665c7ba"'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-Runtime-rack', '0.063530'), ('Content-Encoding', 'gzip')] +[{"url":"https://api.github.com/gists/69b8a5831b74946db944c5451017fa40","forks_url":"https://api.github.com/gists/69b8a5831b74946db944c5451017fa40/forks","commits_url":"https://api.github.com/gists/69b8a5831b74946db944c5451017fa40/commits","id":"69b8a5831b74946db944c5451017fa40","node_id":"MDQ6R2lzdDY5YjhhNTgzMWI3NDk0NmRiOTQ0YzU0NTEwMTdmYTQw","git_pull_url":"https://gist.github.com/69b8a5831b74946db944c5451017fa40.git","git_push_url":"https://gist.github.com/69b8a5831b74946db944c5451017fa40.git","html_url":"https://gist.github.com/69b8a5831b74946db944c5451017fa40","files":{"flasks.gs":{"filename":"flasks.gs","type":"text/plain","language":"JavaScript","raw_url":"https://gist.githubusercontent.com/Kungfumoo/69b8a5831b74946db944c5451017fa40/raw/6caa5966d3540b56b1b3da9a21f46318a78cfa65/flasks.gs","size":550}},"public":true,"created_at":"2018-10-02T10:38:40Z","updated_at":"2018-10-02T10:38:40Z","description":"Omen flasks cheat sheet generator","comments":0,"user":null,"comments_url":"https://api.github.com/gists/69b8a5831b74946db944c5451017fa40/comments","owner":{"login":"Kungfumoo","id":11707939,"node_id":"MDQ6VXNlcjExNzA3OTM5","avatar_url":"https://avatars3.githubusercontent.com/u/11707939?v=4","gravatar_id":"","url":"https://api.github.com/users/Kungfumoo","html_url":"https://github.com/Kungfumoo","followers_url":"https://api.github.com/users/Kungfumoo/followers","following_url":"https://api.github.com/users/Kungfumoo/following{/other_user}","gists_url":"https://api.github.com/users/Kungfumoo/gists{/gist_id}","starred_url":"https://api.github.com/users/Kungfumoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kungfumoo/subscriptions","organizations_url":"https://api.github.com/users/Kungfumoo/orgs","repos_url":"https://api.github.com/users/Kungfumoo/repos","events_url":"https://api.github.com/users/Kungfumoo/events{/privacy}","received_events_url":"https://api.github.com/users/Kungfumoo/received_events","type":"User","site_admin":false},"truncated":false},{"url":"https://api.github.com/gists/c22050a8705e93d170e0d4ca9c02e40c","forks_url":"https://api.github.com/gists/c22050a8705e93d170e0d4ca9c02e40c/forks","commits_url":"https://api.github.com/gists/c22050a8705e93d170e0d4ca9c02e40c/commits","id":"c22050a8705e93d170e0d4ca9c02e40c","node_id":"MDQ6R2lzdGMyMjA1MGE4NzA1ZTkzZDE3MGUwZDRjYTljMDJlNDBj","git_pull_url":"https://gist.github.com/c22050a8705e93d170e0d4ca9c02e40c.git","git_push_url":"https://gist.github.com/c22050a8705e93d170e0d4ca9c02e40c.git","html_url":"https://gist.github.com/c22050a8705e93d170e0d4ca9c02e40c","files":{"gistfile1.txt":{"filename":"gistfile1.txt","type":"text/plain","language":"Text","raw_url":"https://gist.githubusercontent.com/dev16pk/c22050a8705e93d170e0d4ca9c02e40c/raw/11bf41c91d5e5619970ebd789810245cd9dfe062/gistfile1.txt","size":23801}},"public":true,"created_at":"2018-10-02T09:33:17Z","updated_at":"2018-10-02T10:38:41Z","description":"","comments":0,"user":null,"comments_url":"https://api.github.com/gists/c22050a8705e93d170e0d4ca9c02e40c/comments","owner":{"login":"dev16pk","id":43778180,"node_id":"MDQ6VXNlcjQzNzc4MTgw","avatar_url":"https://avatars2.githubusercontent.com/u/43778180?v=4","gravatar_id":"","url":"https://api.github.com/users/dev16pk","html_url":"https://github.com/dev16pk","followers_url":"https://api.github.com/users/dev16pk/followers","following_url":"https://api.github.com/users/dev16pk/following{/other_user}","gists_url":"https://api.github.com/users/dev16pk/gists{/gist_id}","starred_url":"https://api.github.com/users/dev16pk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dev16pk/subscriptions","organizations_url":"https://api.github.com/users/dev16pk/orgs","repos_url":"https://api.github.com/users/dev16pk/repos","events_url":"https://api.github.com/users/dev16pk/events{/privacy}","received_events_url":"https://api.github.com/users/dev16pk/received_events","type":"User","site_admin":false},"truncated":false},{"url":"https://api.github.com/gists/a7a95e1a194e07960364a5b32c56ac5f","forks_url":"https://api.github.com/gists/a7a95e1a194e07960364a5b32c56ac5f/forks","commits_url":"https://api.github.com/gists/a7a95e1a194e07960364a5b32c56ac5f/commits","id":"a7a95e1a194e07960364a5b32c56ac5f","node_id":"MDQ6R2lzdGE3YTk1ZTFhMTk0ZTA3OTYwMzY0YTViMzJjNTZhYzVm","git_pull_url":"https://gist.github.com/a7a95e1a194e07960364a5b32c56ac5f.git","git_push_url":"https://gist.github.com/a7a95e1a194e07960364a5b32c56ac5f.git","html_url":"https://gist.github.com/a7a95e1a194e07960364a5b32c56ac5f","files":{"cube.py":{"filename":"cube.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/21d49b66ae3a73647d25e06eeb895ab74ff0111a/cube.py","size":4280},"orig.py":{"filename":"orig.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/d080a0ec78420d8d1ffee95e9f0e4efa628582bb/orig.py","size":658},"quad.py":{"filename":"quad.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/fc2b911d1e836d37eac9fc8345a3c24255983a7f/quad.py","size":3036},"red_triangle.py":{"filename":"red_triangle.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/a6a47c835b49e05b5038ecbcb0d42ea951e1c1c9/red_triangle.py","size":1845},"resources.txt":{"filename":"resources.txt","type":"text/plain","language":"Text","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/5da461e4e71d5066036d7533a145616295ac161f/resources.txt","size":208},"tex_quad.py":{"filename":"tex_quad.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/f076b974b417acc3765699e88115fef052448a88/tex_quad.py","size":4586},"tex_quad_png.py":{"filename":"tex_quad_png.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/0ceb0b41080051be64045f99d8dc3a52af2ab730/tex_quad_png.py","size":4872},"triangle.py":{"filename":"triangle.py","type":"application/x-python","language":"Python","raw_url":"https://gist.githubusercontent.com/DatHydroGuy/a7a95e1a194e07960364a5b32c56ac5f/raw/79f9926a5e68c97d7b5b595065d55556cbc25942/triangle.py","size":2625}},"public":true,"created_at":"2018-10-01T13:00:38Z","updated_at":"2018-10-02T10:39:06Z","description":"","comments":0,"user":null,"comments_url":"https://api.github.com/gists/a7a95e1a194e07960364a5b32c56ac5f/comments","owner":{"login":"DatHydroGuy","id":28946117,"node_id":"MDQ6VXNlcjI4OTQ2MTE3","avatar_url":"https://avatars2.githubusercontent.com/u/28946117?v=4","gravatar_id":"","url":"https://api.github.com/users/DatHydroGuy","html_url":"https://github.com/DatHydroGuy","followers_url":"https://api.github.com/users/DatHydroGuy/followers","following_url":"https://api.github.com/users/DatHydroGuy/following{/other_user}","gists_url":"https://api.github.com/users/DatHydroGuy/gists{/gist_id}","starred_url":"https://api.github.com/users/DatHydroGuy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DatHydroGuy/subscriptions","organizations_url":"https://api.github.com/users/DatHydroGuy/orgs","repos_url":"https://api.github.com/users/DatHydroGuy/repos","events_url":"https://api.github.com/users/DatHydroGuy/events{/privacy}","received_events_url":"https://api.github.com/users/DatHydroGuy/received_events","type":"User","site_admin":false},"truncated":false},{"url":"https://api.github.com/gists/a25d9ace89b574f95bf0724f95a84fc2","forks_url":"https://api.github.com/gists/a25d9ace89b574f95bf0724f95a84fc2/forks","commits_url":"https://api.github.com/gists/a25d9ace89b574f95bf0724f95a84fc2/commits","id":"a25d9ace89b574f95bf0724f95a84fc2","node_id":"MDQ6R2lzdGEyNWQ5YWNlODliNTc0Zjk1YmYwNzI0Zjk1YTg0ZmMy","git_pull_url":"https://gist.github.com/a25d9ace89b574f95bf0724f95a84fc2.git","git_push_url":"https://gist.github.com/a25d9ace89b574f95bf0724f95a84fc2.git","html_url":"https://gist.github.com/a25d9ace89b574f95bf0724f95a84fc2","files":{"cloudSettings":{"filename":"cloudSettings","type":"text/plain","language":null,"raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/32a15df0ba869ec808f71326318f53c6fea8f563/cloudSettings","size":69},"extensions.json":{"filename":"extensions.json","type":"application/json","language":"JSON","raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/91c63643f88e5a49e0535dac8cb4e032cc1d3ecb/extensions.json","size":4919},"keybindings.json":{"filename":"keybindings.json","type":"application/json","language":"JSON","raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/1aa5dc1d6d49433f0f8d3d76c850a9aa04afe7df/keybindings.json","size":252},"keybindingsMac.json":{"filename":"keybindingsMac.json","type":"application/json","language":"JSON","raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/3668f61b827e05ac961afc397c2508d96d8f52b6/keybindingsMac.json","size":451},"settings.json":{"filename":"settings.json","type":"application/json","language":"JSON","raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/22736bf652105853165f15c1bb21c7ab7de4a162/settings.json","size":1396},"vsicons.settings.json":{"filename":"vsicons.settings.json","type":"application/json","language":"JSON","raw_url":"https://gist.githubusercontent.com/lloydh/a25d9ace89b574f95bf0724f95a84fc2/raw/200c1042e6c2ba59597daf7981029cbd353fee6c/vsicons.settings.json","size":51}},"public":true,"created_at":"2018-07-05T12:23:18Z","updated_at":"2018-10-02T10:38:38Z","description":"Visual Studio Code Settings Sync Gist","comments":0,"user":null,"comments_url":"https://api.github.com/gists/a25d9ace89b574f95bf0724f95a84fc2/comments","owner":{"login":"lloydh","id":438273,"node_id":"MDQ6VXNlcjQzODI3Mw==","avatar_url":"https://avatars0.githubusercontent.com/u/438273?v=4","gravatar_id":"","url":"https://api.github.com/users/lloydh","html_url":"https://github.com/lloydh","followers_url":"https://api.github.com/users/lloydh/followers","following_url":"https://api.github.com/users/lloydh/following{/other_user}","gists_url":"https://api.github.com/users/lloydh/gists{/gist_id}","starred_url":"https://api.github.com/users/lloydh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lloydh/subscriptions","organizations_url":"https://api.github.com/users/lloydh/orgs","repos_url":"https://api.github.com/users/lloydh/repos","events_url":"https://api.github.com/users/lloydh/events{/privacy}","received_events_url":"https://api.github.com/users/lloydh/received_events","type":"User","site_admin":false},"truncated":false},{"url":"https://api.github.com/gists/3195465","forks_url":"https://api.github.com/gists/3195465/forks","commits_url":"https://api.github.com/gists/3195465/commits","id":"3195465","node_id":"MDQ6R2lzdDMxOTU0NjU=","git_pull_url":"https://gist.github.com/3195465.git","git_push_url":"https://gist.github.com/3195465.git","html_url":"https://gist.github.com/3195465","files":{"osx-for-hackers.sh":{"filename":"osx-for-hackers.sh","type":"application/x-sh","language":"Shell","raw_url":"https://gist.githubusercontent.com/brandonb927/3195465/raw/349f7b1d57733ac573177bc9af1b1be7ee35de1b/osx-for-hackers.sh","size":28235}},"public":true,"created_at":"2012-07-29T00:43:43Z","updated_at":"2018-10-02T10:39:05Z","description":"OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.","comments":134,"user":null,"comments_url":"https://api.github.com/gists/3195465/comments","owner":{"login":"brandonb927","id":1509352,"node_id":"MDQ6VXNlcjE1MDkzNTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1509352?v=4","gravatar_id":"","url":"https://api.github.com/users/brandonb927","html_url":"https://github.com/brandonb927","followers_url":"https://api.github.com/users/brandonb927/followers","following_url":"https://api.github.com/users/brandonb927/following{/other_user}","gists_url":"https://api.github.com/users/brandonb927/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonb927/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonb927/subscriptions","organizations_url":"https://api.github.com/users/brandonb927/orgs","repos_url":"https://api.github.com/users/brandonb927/repos","events_url":"https://api.github.com/users/brandonb927/events{/privacy}","received_events_url":"https://api.github.com/users/brandonb927/received_events","type":"User","site_admin":false},"truncated":false}] + diff --git a/github/tests/ReplayData/NamedUser.testGetGists.txt b/github/tests/ReplayData/NamedUser.testGetGists.txt index a252e028..83d40821 100644 --- a/github/tests/ReplayData/NamedUser.testGetGists.txt +++ b/github/tests/ReplayData/NamedUser.testGetGists.txt @@ -9,3 +9,14 @@ None [('status', '200 OK'), ('x-ratelimit-remaining', '4967'), ('content-length', '3681'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"5718165cec484b5936e6e08ff24eb2e5"'), ('date', 'Sat, 26 May 2012 10:09:40 GMT'), ('content-type', 'application/json; charset=utf-8')] [{"updated_at":"2012-05-26T10:09:33Z","url":"https://api.github.com/gists/2793179","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793179.git","git_push_url":"git@gist.github.com:2793179.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793179/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Gist created by PyGithub","created_at":"2012-05-26T09:50:02Z","id":"2793179","html_url":"https://gist.github.com/2793179"},{"updated_at":"2012-04-26T13:20:53Z","url":"https://api.github.com/gists/11cb445f8197e17d303d","comments":0,"public":false,"git_pull_url":"git://gist.github.com/11cb445f8197e17d303d.git","git_push_url":"git@gist.github.com:11cb445f8197e17d303d.git","files":{"FairThreadPoolPool.cpp":{"type":"text/plain","raw_url":"https://gist.github.com/raw/11cb445f8197e17d303d/0f72c6fe50eb011eacb4e39fa613bdfe2f7a0c51/FairThreadPoolPool.cpp","size":7779,"filename":"FairThreadPoolPool.cpp","language":"C++"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"FairThreadPoolPool.cpp","created_at":"2012-04-26T13:20:53Z","id":"11cb445f8197e17d303d","html_url":"https://gist.github.com/11cb445f8197e17d303d"},{"updated_at":"2012-02-29T16:47:12Z","url":"https://api.github.com/gists/1942384","comments":0,"public":true,"git_pull_url":"git://gist.github.com/1942384.git","git_push_url":"git@gist.github.com:1942384.git","files":{"fail_github.py":{"type":"application/python","raw_url":"https://gist.github.com/raw/1942384/2fb3aa84e0efa50dc0f4c18b5df5b7b9ab27076b/fail_github.py","size":1636,"filename":"fail_github.py","language":"Python"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"How to error 500 Github API v3, as requested by Rick (GitHub Staff)","created_at":"2012-02-29T16:47:12Z","id":"1942384","html_url":"https://gist.github.com/1942384"},{"updated_at":"2012-02-28T19:44:42Z","url":"https://api.github.com/gists/dcb7de17e8a52b74541d","comments":1,"public":false,"git_pull_url":"git://gist.github.com/dcb7de17e8a52b74541d.git","git_push_url":"git@gist.github.com:dcb7de17e8a52b74541d.git","files":{"cadfael.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/dcb7de17e8a52b74541d/48ca696645682d7430d73180814434e0284796b2/cadfael.txt","size":585,"filename":"cadfael.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Cadfael: order of episodes in French DVD edition","created_at":"2012-02-28T19:44:42Z","id":"dcb7de17e8a52b74541d","html_url":"https://gist.github.com/dcb7de17e8a52b74541d"}] +https +GET +api.github.com +None +/users/jacquev6/gists?since=2012-03-01T17%3A00%3A00Z +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4967'), ('content-length', '1811'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"7518615cec183b5396a6e08ef24eb2e9"'), ('date', 'Sat, 26 May 2012 10:10:17 GMT'), ('content-type', 'application/json; charset=utf-8')] +[{"updated_at":"2012-05-26T10:09:33Z","url":"https://api.github.com/gists/2793179","comments":0,"public":true,"git_pull_url":"git://gist.github.com/2793179.git","git_push_url":"git@gist.github.com:2793179.git","files":{"foobar.txt":{"type":"text/plain","raw_url":"https://gist.github.com/raw/2793179/73a1c7f17aa0ad5d7cbb5a8ca033ce47d3d23197/foobar.txt","size":24,"filename":"foobar.txt","language":"Text"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"Gist created by PyGithub","created_at":"2012-05-26T09:50:02Z","id":"2793179","html_url":"https://gist.github.com/2793179"},{"updated_at":"2012-04-26T13:20:53Z","url":"https://api.github.com/gists/11cb445f8197e17d303d","comments":0,"public":false,"git_pull_url":"git://gist.github.com/11cb445f8197e17d303d.git","git_push_url":"git@gist.github.com:11cb445f8197e17d303d.git","files":{"FairThreadPoolPool.cpp":{"type":"text/plain","raw_url":"https://gist.github.com/raw/11cb445f8197e17d303d/0f72c6fe50eb011eacb4e39fa613bdfe2f7a0c51/FairThreadPoolPool.cpp","size":7779,"filename":"FairThreadPoolPool.cpp","language":"C++"}},"user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"description":"FairThreadPoolPool.cpp","created_at":"2012-04-26T13:20:53Z","id":"11cb445f8197e17d303d","html_url":"https://gist.github.com/11cb445f8197e17d303d"}] + diff --git a/github/tests/Time.py b/github/tests/Time.py new file mode 100644 index 00000000..53077321 --- /dev/null +++ b/github/tests/Time.py @@ -0,0 +1,34 @@ +############################ Copyrights and license ############################ +# # +# Copyright 2018 itsbruce # +# # +# This file is part of PyGithub. # +# http://pygithub.readthedocs.io/ # +# # +# 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 . # +# # +################################################################################ + +from datetime import datetime, timedelta, tzinfo + +class UTCtzinfo(tzinfo): + def utcoffset(self, dt): + return timedelta(0) + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return timedelta(0) +