|
7 | 7 | # This file is part of python-github2, and is made available under the 3-clause |
8 | 8 | # BSD license. See LICENSE for the full details. |
9 | 9 |
|
10 | | -import datetime |
11 | 10 | import unittest |
12 | 11 |
|
| 12 | +from mock import patch |
13 | 13 | from nose.tools import (eq_, ok_, raises) |
14 | | -from nose.plugins.attrib import attr |
15 | 14 |
|
16 | 15 | from github2.core import (AuthError, repr_string, requires_auth) |
17 | 16 | from github2.issues import Issue |
@@ -44,23 +43,17 @@ def test_non_standard_host(self): |
44 | 43 |
|
45 | 44 | class RateLimits(utils.HttpMockTestCase): |
46 | 45 |
|
47 | | - """Test API rate-limitting.""" |
| 46 | + """Test API rate-limiting.""" |
48 | 47 |
|
49 | | - @attr('slow') |
50 | | - def test_delays(self): |
51 | | - """Test call delay is at least one second.""" |
| 48 | + @patch('github2.request.time.sleep') |
| 49 | + def test_delays(self, sleep): |
| 50 | + """Test calls in quick succession are delayed.""" |
52 | 51 | client = Github(requests_per_second=.5) |
53 | 52 | client.users.show('defunkt') |
54 | | - start = datetime.datetime.utcnow() |
55 | 53 | client.users.show('mojombo') |
56 | | - end = datetime.datetime.utcnow() |
57 | 54 |
|
58 | | - delta = end - start |
59 | | - delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds |
60 | | - |
61 | | - ok_(delta_seconds >= 2, |
62 | | - "Expected .5 reqs per second to require a 2 second delay between " |
63 | | - "calls.") |
| 55 | + # 0.5 requests per second, means a two second delay |
| 56 | + sleep.assert_called_once_with(2.0) |
64 | 57 |
|
65 | 58 |
|
66 | 59 | class BaseDataIter(utils.HttpMockTestCase): |
|
0 commit comments