コード例 #1
0
def test_update_units_request_invalid(app):
    ''' The new_units query parameter is often missing '''
    sw = seanweather.SeanWeather()
    sw.previous = seanweather.CookieData(units='C', user_input='', num_hours=0)
    with app.test_request_context('?new_units=&num_hours=24'):
        sw.update_units()
    assert sw.units == seanweather.Units.C
コード例 #2
0
def test_update_weather_data_empty_response(session, app):
    sw = seanweather.SeanWeather()
    sw.location = Location(0, 'NYC', 'US')
    fake_weather_getter = lambda url, api_key: ([], sw.location)
    with app.test_request_context('?user_input=foo'):
        sw.update_weather_data(weather_getter=fake_weather_getter)
    assert sw.weather_data == []
コード例 #3
0
def test_update_weather_data_good_response(session, app):
    sw = seanweather.SeanWeather()
    sw.location = Location(0, 'NYC', 'US')
    weather_data = [dict(date=0, icon='', icon_pos=100, temp='100', pop='0',
                         feel='100', temp_c='35', feel_c='35')]*100
    fake_weather_getter = lambda url, api_key: (weather_data, sw.location)
    with app.test_request_context('?user_input=foo'):
        sw.update_weather_data(weather_getter=fake_weather_getter)
    assert sw.weather_data == weather_data
コード例 #4
0
def test_update_current_conditions_F():
    sw = seanweather.SeanWeather()
    sw.weather_data = _get_weather_data()

    sw.update_current_conditions()

    assert sw.current_temp == 83
    assert sw.max_temp == 85
    assert sw.min_temp == 81
    assert sw.icon == 'cloud'
コード例 #5
0
def test_update_current_conditions_C():
    sw = seanweather.SeanWeather()
    sw.units = seanweather.Units.C
    sw.weather_data = _get_weather_data()

    sw.update_current_conditions()

    assert sw.current_temp == 28
    assert sw.max_temp == 29
    assert sw.min_temp == 27
    assert sw.icon == 'cloud'
コード例 #6
0
def test_update_num_hours_bad_request(app):
    sw = seanweather.SeanWeather()
    sw.previous = seanweather.CookieData(units='', user_input='', num_hours='36')
    with app.test_request_context('?num_hours=tacos'):
        sw.update_num_hours()
    assert sw.num_hours == seanweather._DEFAULT_NUM_HOURS
コード例 #7
0
def test_update_units_request_new(app):
    sw = seanweather.SeanWeather()
    sw.previous = seanweather.CookieData(units='C', user_input='', num_hours=0)
    with app.test_request_context('?new_units=F'):
        sw.update_units()
    assert sw.units == seanweather.Units.F
コード例 #8
0
def test_update_num_hours_good_request(app):
    sw = seanweather.SeanWeather()
    sw.previous = seanweather.CookieData(units='', user_input='', num_hours='36')
    with app.test_request_context('?num_hours=48'):
        sw.update_num_hours()
    assert sw.num_hours == 48