Updated code and added tests

This commit is contained in:
Ken Tsang
2017-04-25 19:03:59 +01:00
parent 55a0ed22d9
commit 260dfb1e32
4 changed files with 215 additions and 14 deletions

View File

@@ -240,6 +240,83 @@ def test_usage_page(
assert '206,246 text messages at 1.65p' in table
@freeze_time("2012-03-31 12:12:12")
def test_international_usage_page(
logged_in_client,
mock_get_international_usage,
mock_get_billable_international_units,
):
response = logged_in_client.get(url_for('main.usage', service_id=SERVICE_ONE_ID))
assert response.status_code == 200
mock_get_billable_international_units.assert_called_once_with(SERVICE_ONE_ID, 2011)
mock_get_international_usage.assert_called_once_with(SERVICE_ONE_ID, 2011)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
cols = page.find_all('div', {'class': 'column-half'})
nav = page.find('ul', {'class': 'pill', 'role': 'tablist'})
nav_links = nav.find_all('a')
assert normalize_spaces(nav_links[0].text) == '2010 to 2011 financial year'
assert normalize_spaces(nav.find('li', {'aria-selected': 'true'}).text) == '2011 to 2012 financial year'
assert normalize_spaces(nav_links[1].text) == '2012 to 2013 financial year'
assert '0' in cols[0].text
assert 'Emails' in cols[0].text
assert '252,390' in cols[1].text
assert 'Text messages' in cols[1].text
table = page.find('table').text.strip()
print(table)
assert '249,900 UK free text messages' in table
assert '100 international free text messages' in table
assert '900 international text messages at 1.65p' in table
assert 'April' in table
assert 'March' in table
assert '£20.30' in table
assert '£19.14' in table
@freeze_time("2012-03-31 12:12:12")
def test_international_usage_page(
logged_in_client,
mock_get_international_usage,
mock_get_billable_international_units,
):
response = logged_in_client.get(url_for('main.usage', service_id=SERVICE_ONE_ID))
assert response.status_code == 200
mock_get_billable_international_units.assert_called_once_with(SERVICE_ONE_ID, 2011)
mock_get_international_usage.assert_called_once_with(SERVICE_ONE_ID, 2011)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
cols = page.find_all('div', {'class': 'column-half'})
nav = page.find('ul', {'class': 'pill', 'role': 'tablist'})
nav_links = nav.find_all('a')
assert '252,390' in cols[1].text
assert 'Text messages' in cols[1].text
table = page.find('table').text.strip()
print(table)
assert '249,900 UK free text messages' in table
assert '100 international free text messages' in table
assert '900 international text messages at 1.65p' in table
assert 'April' in table
assert 'March' in table
assert '£20.30' in table
assert '£19.14' in table
def test_usage_page_with_year_argument(
logged_in_client,
mock_get_usage,

View File

@@ -1336,6 +1336,80 @@ def mock_get_billable_units(mocker):
'app.service_api_client.get_billable_units', side_effect=_get_usage)
@pytest.fixture(scope='function')
def mock_get_international_usage(mocker, service_one, fake_uuid):
def _get_usage(service_id, year=None):
return {'data': {
"sms_count": 252390,
"email_count": 0
}}
return mocker.patch(
'app.service_api_client.get_service_usage', side_effect=_get_usage)
@pytest.fixture(scope='function')
def mock_get_billable_international_units(mocker):
def _get_usage(service_id, year):
return {
"April": [
{
"international": False,
"rate": 1.65,
"multiplier": 1,
"units": 249900
},
{
"international": True,
"rate": 1.65,
"multiplier": 1,
"units": 1000
},
{
"international": True,
"rate": 1.65,
"multiplier": 2,
"units": 100
},
{
"international": True,
"rate": 1.65,
"multiplier": 3,
"units": 20
},
],
"March": [
{
"international": False,
"rate": 1.65,
"multiplier": 1,
"units": 1000
},
{
"international": True,
"rate": 1.65,
"multiplier": 1,
"units": 100
},
{
"international": True,
"rate": 1.65,
"multiplier": 2,
"units": 50
},
{
"international": True,
"rate": 1.65,
"multiplier": 3,
"units": 10
},
]
}
return mocker.patch(
'app.service_api_client.get_billable_units', side_effect=_get_usage)
@pytest.fixture(scope='function')
def mock_events(mocker):
def _create_event(event_type, event_data):