Skip to content

Commit

Permalink
Cover the missing part with test
Browse files Browse the repository at this point in the history
  • Loading branch information
paraita committed Jan 26, 2017
1 parent 13acb0f commit aa1c7a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sophiabus230/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sophiabus230
from dateutil.tz import gettz
from mock import patch
from future.moves.urllib import request


class TestSophiabus230(TestCase):
Expand All @@ -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')

0 comments on commit aa1c7a0

Please sign in to comment.