/ tests / RateLimiting.py
RateLimiting.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
 4  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
 5  # Copyright 2013 Ed Jackson <ed.jackson@gmail.com>                             #
 6  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
 7  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 8  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 9  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
10  # Copyright 2023 Nikolay Yurin <yurinnick@meta.com>                            #
11  #                                                                              #
12  # This file is part of PyGithub.                                               #
13  # http://pygithub.readthedocs.io/                                              #
14  #                                                                              #
15  # PyGithub is free software: you can redistribute it and/or modify it under    #
16  # the terms of the GNU Lesser General Public License as published by the Free  #
17  # Software Foundation, either version 3 of the License, or (at your option)    #
18  # any later version.                                                           #
19  #                                                                              #
20  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
21  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
22  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
23  # details.                                                                     #
24  #                                                                              #
25  # You should have received a copy of the GNU Lesser General Public License     #
26  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
27  #                                                                              #
28  ################################################################################
29  
30  from datetime import datetime, timezone
31  
32  from . import Framework
33  
34  
35  class RateLimiting(Framework.TestCase):
36      def testRateLimiting(self):
37          self.assertEqual(self.g.rate_limiting, (4904, 5000))
38          self.g.get_user("yurinnick")
39          self.assertEqual(self.g.rate_limiting, (4903, 5000))
40          self.assertEqual(self.g.rate_limiting_resettime, 1684195041)
41  
42      def testResetTime(self):
43          self.assertEqual(self.g.rate_limiting_resettime, 1684195041)
44  
45      def testGetRateLimit(self):
46          rateLimit = self.g.get_rate_limit()
47          self.assertEqual(
48              repr(rateLimit),
49              "RateLimit(core=Rate(reset=2023-05-15 23:57:21+00:00, remaining=4904, limit=5000))",
50          )
51          self.assertEqual(
52              repr(rateLimit.core),
53              "Rate(reset=2023-05-15 23:57:21+00:00, remaining=4904, limit=5000)",
54          )
55          self.assertEqual(rateLimit.core.limit, 5000)
56          self.assertEqual(rateLimit.core.remaining, 4904)
57          self.assertEqual(rateLimit.core.used, 96)
58          self.assertEqual(rateLimit.core.reset, datetime(2023, 5, 15, 23, 57, 21, tzinfo=timezone.utc))