-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
297 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
import os | ||
|
||
from mopidy import config, ext | ||
|
||
import mopidy_waitforinternet | ||
|
||
__version__ = mopidy_waitforinternet.__version__ | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WaitForTimeSyncExtension(ext.Extension): | ||
dist_name = 'Mopidy-WaitForInternet' | ||
ext_name = 'waitfortimesync' | ||
version = __version__ | ||
|
||
def get_default_config(self): | ||
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf') | ||
return config.read(conf_file) | ||
|
||
def setup(self, registry): | ||
mopidy_waitforinternet.WaitForInternetExtension.wait_for_internet(True, logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[waitfortimesync] | ||
enabled = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import time | ||
import unittest | ||
|
||
from freezegun import freeze_time | ||
|
||
import mock | ||
|
||
import mopidy_waitfortimesync | ||
|
||
import responses | ||
|
||
import mopidy_waitforinternet | ||
|
||
|
||
@responses.activate | ||
def TestDateHeaders(test, ext): | ||
responses.add(responses.GET, 'https://nosuchhost.nosuchdomain.arpa/date-header-invalid', headers={'Date': 'not a date'}) | ||
responses.add(responses.GET, 'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-20', headers={'Date': 'Fri, 01 Jul 2022 14:00:20 GMT'}) | ||
responses.add(responses.GET, 'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-30', headers={'Date': 'Fri, 01 Jul 2022 14:00:30 GMT'}) | ||
responses.add(responses.GET, 'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-40', headers={'Date': 'Fri, 01 Jul 2022 14:00:40 GMT'}) | ||
responses.add(responses.GET, 'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-50', headers={'Date': 'Fri, 01 Jul 2022 14:00:50 GMT'}) | ||
registry = mock.Mock() | ||
|
||
t_start = time.monotonic() | ||
ext.setup(registry) | ||
t_stop = time.monotonic() | ||
|
||
registry.add.assert_not_called() | ||
return t_stop - t_start | ||
|
||
|
||
class TestsWithInvalidDateHeader(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.backup_check_urls = mopidy_waitforinternet.check_urls | ||
mopidy_waitforinternet.check_urls = [ | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-invalid', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-20', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-30', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-40', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-50' | ||
] | ||
|
||
def test_waitforinternet_setup_complex_actual_date(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:00', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at140000(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:20', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at140020(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 18:18:20', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at181820(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:20', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140020(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 1) | ||
self.assertLess(duration, 1.4) | ||
|
||
@freeze_time('2022-07-01 14:00:35', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140035(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 2) | ||
self.assertLess(duration, 2.4) | ||
|
||
@freeze_time('2022-07-01 14:00:59', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140059(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 4) | ||
self.assertLess(duration, 4.4) | ||
|
||
def tearDown(self): | ||
mopidy_waitforinternet.check_urls = self.backup_check_urls | ||
|
||
|
||
class TestsNoInvalidDateHeader(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.backup_check_urls = mopidy_waitforinternet.check_urls | ||
mopidy_waitforinternet.check_urls = [ | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-20', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-30', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-40', | ||
'https://nosuchhost.nosuchdomain.arpa/date-header-2022-07-01-14-00-50' | ||
] | ||
|
||
def test_waitforinternet_setup_complex_actual_date(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:00', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at140000(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:20', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at140020(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 18:18:20', ignore=['tests']) | ||
def test_waitforinternet_setup_complex_at181820(self): | ||
duration = TestDateHeaders(self, mopidy_waitforinternet.WaitForInternetExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:20', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140020(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 0) | ||
self.assertLess(duration, 0.4) | ||
|
||
@freeze_time('2022-07-01 14:00:35', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140035(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 1) | ||
self.assertLess(duration, 1.4) | ||
|
||
@freeze_time('2022-07-01 14:00:59', ignore=['tests']) | ||
def test_waitfortimesync_setup_complex_at140059(self): | ||
duration = TestDateHeaders(self, mopidy_waitfortimesync.WaitForTimeSyncExtension()) | ||
self.assertGreaterEqual(duration, 3) | ||
self.assertLess(duration, 3.4) | ||
|
||
def tearDown(self): | ||
mopidy_waitforinternet.check_urls = self.backup_check_urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.