Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Использование API openweathermap.org

-----------------------------------------------------------------------------------------------------------------------------------------------------
{"name": "Moscow", "coord": {"lon": 37.6156, "lat": 55.7522}, "country": "RU", "feels_like": 15.92, "timezone": "UTC+3"}
-----------------------------------------------------------------------------------------------------------------------------------------------------
{"name": "Saint Petersburg", "coord": {"lon": 30.2642, "lat": 59.8944}, "country": "RU", "feels_like": 13.68, "timezone": "UTC+3"}
-----------------------------------------------------------------------------------------------------------------------------------------------------
{"name": "Dhaka", "coord": {"lon": 90.4074, "lat": 23.7104}, "country": "BD", "feels_like": 35.99, "timezone": "UTC+6"}
-----------------------------------------------------------------------------------------------------------------------------------------------------

Тесты проекта

import getweatherdata
import pytest

key = '******************'


def test_without_key():
    assert getweatherdata.get_weather_data(
        "moscow") is None, \
        " Для получения данных необходимо задать значение для api_key "


def test_in_riga():
    assert getweatherdata.get_weather_data("Riga",
                                           api_key=key) is not None, \
        " Type of response is not none while using the key "


def test_of_res():
    assert type(getweatherdata.get_weather_data("Riga",
                                                api_key=key)) is str, \
        " Type of response is not none while using the key "


def test_args_error():
    assert getweatherdata.get_weather_data(
        '') is None, \
        " There should be one positional argument: 'city' and one keyword argument 'key_arg'"


def test_pos_arg_error():
    assert getweatherdata.get_weather_data('',
                                           api_key=key) is None, \
        " There should be one positional argument: 'city' "


def test_coords_dim():
    import json

    assert len(
        json.loads(getweatherdata.get_weather_data('Riga', api_key=key)).get('coord')) == 2, \
        " Dimension is 2: lon and lat "


def test_temp_type():
    import json

    assert type(json.loads(getweatherdata.get_weather_data('Riga', api_key=key)).get(
        'feels_like')) is float, \
        " Error with type of feels_like attribute "


inp_params_1 = "city, api_key, expected_country"
exp_params_countries = [("Chicago", key, 'US'),
                        ("Saint Petersburg", key, 'RU'), ("Dakka", key, 'BD'),
                        ("Minsk", key, 'BY'), ("Kioto", key, 'JP'),
                        ("Anchorage", key, 'US'), ("Havana", key, 'CU')]


@pytest.mark.parametrize(inp_params_1, exp_params_countries)
def test_countries(city, api_key, expected_country):
    import json

    assert json.loads(getweatherdata.get_weather_data(city, api_key=key)).get('country',
                                                                              'NoValue') == expected_country, \
        " Error with country code "


#
# Проверить что такое DST и как оно может влиять на этот тест.
inp_params_2 = "city, api_key, expected_time"
exp_params_timezones = [("Chicago", key, 'UTC-5'),
                        ("Saint Petersburg", key, 'UTC+3'),
                        ("Dakka", key, 'UTC+6'), ("Minsk", key, 'UTC+3'),
                        ("Kioto", key, 'UTC+9'), ("Anchorage", key, 'UTC-8'),
                        ("Havana", key, 'UTC-4')]


@pytest.mark.parametrize(inp_params_2, exp_params_timezones)
def test_utc_time(city, api_key, expected_time):
    import json
    assert json.loads(getweatherdata.get_weather_data(city, api_key=key)).get('timezone',
                                                                              'NoValue') == expected_time, \
        " Error with timezone "

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages