diff --git a/sophiabus230/__init__.py b/sophiabus230/__init__.py index d152e96..95f292c 100644 --- a/sophiabus230/__init__.py +++ b/sophiabus230/__init__.py @@ -10,7 +10,7 @@ from dateutil.parser import parse from dateutil.tz import gettz from bs4 import BeautifulSoup -from future.moves.urllib.request import urlopen +from future.moves.urllib import request def _get_html_from_cg06(stop_id): @@ -22,7 +22,7 @@ def _get_html_from_cg06(stop_id): :rtype: str """ cg06_url = "http://cg06.tsi.cityway.fr/qrcode/?id={0}" - req = urlopen(cg06_url.format(stop_id)) + req = request.urlopen(cg06_url.format(stop_id)) content = req.read() return content diff --git a/sophiabus230/tests/test_get_next_buses.py b/sophiabus230/tests/test_sophiabus230.py similarity index 75% rename from sophiabus230/tests/test_get_next_buses.py rename to sophiabus230/tests/test_sophiabus230.py index e8758ea..8b965d6 100644 --- a/sophiabus230/tests/test_get_next_buses.py +++ b/sophiabus230/tests/test_sophiabus230.py @@ -8,6 +8,7 @@ import sophiabus230 from dateutil.tz import gettz from mock import patch +from future.moves.urllib import request class TestSophiabus230(TestCase): @@ -34,3 +35,12 @@ def test_get_next_buses(self, mock_content): # assert actual_bus_time.day == expected_bus_time.day # assert actual_bus_time.hour == expected_bus_time.hour # assert actual_bus_time.minute == expected_bus_time.minute + + @patch('future.moves.urllib.request.urlopen') + def test_get_html_from_cg06(self, mock_urlopen): + parent_path = os.path.dirname(os.path.abspath(__file__)) + with open(parent_path + os.sep + "example_content.html", 'rb') as fd: + mock_urlopen.return_value = fd + sophiabus230._get_html_from_cg06(1939) + assert mock_urlopen.called + mock_urlopen.assert_called_once_with('http://cg06.tsi.cityway.fr/qrcode/?id=1939')