def test_location_class(mocked_timeline, test_id, country, country_code,
                        province, latitude, longitude, confirmed_latest,
                        deaths_latest, recovered_latest):

    # id, country, province, coordinates, confirmed, deaths, recovered
    coordinate = coordinates.Coordinates(latitude=latitude,
                                         longitude=longitude)
    confirmed = timeline.Timeline(confirmed_latest)
    deaths = timeline.Timeline(deaths_latest)
    recovered = timeline.Timeline(recovered_latest)

    location_obj = location.Location(test_id, country, province, coordinate,
                                     confirmed, deaths, recovered)

    assert location_obj.country_code == country_code

    #validate serialize
    check_dict = {
        'id': test_id,
        'country': country,
        'province': province,
        'country_code': country_code,
        'coordinates': {
            'latitude': latitude,
            'longitude': longitude
        },
        'latest': {
            'confirmed': confirmed_latest,
            'deaths': deaths_latest,
            'recovered': recovered_latest
        }
    }

    assert location_obj.serialize() == check_dict
def test_location_class(mocked_timeline, test_id, country, country_code,
                        country_population, province, latitude, longitude,
                        confirmed_latest, deaths_latest, recovered_latest):

    # id, country, province, coordinates, confirmed, deaths, recovered
    coords = coordinates.Coordinates(latitude=latitude, longitude=longitude)

    # Timelines
    confirmed = timeline.Timeline(confirmed_latest)
    deaths = timeline.Timeline(deaths_latest)
    recovered = timeline.Timeline(recovered_latest)

    # Date now.
    now = datetime.utcnow().isoformat() + 'Z'

    # Location.
    location_obj = location.TimelinedLocation(test_id, country, province,
                                              coords, now, {
                                                  'confirmed': confirmed,
                                                  'deaths': deaths,
                                                  'recovered': recovered,
                                              })

    assert location_obj.country_code == country_code
    assert not location_obj.serialize() == None
Esempio n. 3
0
def test_timeline_class():
    # Unordered timeseries.
    timeseries = {
        '1/24/20': 5,
        '1/22/20': 2,
        '1/25/20': 7,
        '1/23/20': 3,
    }

    history_data = timeline.Timeline(history=timeseries)

    # validate last value
    assert history_data.latest == 7

    # validate order
    assert list(dict(history_data.timeline).keys()) == [
        '1/22/20', '1/23/20', '1/24/20', '1/25/20'
    ]

    # validate serialize
    check_serialize = {
        'latest':
        7,
        'timeline':
        OrderedDict([
            ('1/22/20', 2),
            ('1/23/20', 3),
            ('1/24/20', 5),
            ('1/25/20', 7),
        ])
    }

    assert dict(history_data.serialize()) == check_serialize
def test_timeline_class():
    # Unordered timeseries.
    timeseries = {
        "1/24/20": 5,
        "1/22/20": 2,
        "1/25/20": 7,
        "1/23/20": 3,
    }

    history_data = timeline.Timeline(history=timeseries)

    # validate last value
    assert history_data.latest == 7

    # validate order
    assert list(dict(history_data.timeline).keys()) == [
        "1/22/20",
        "1/23/20",
        "1/24/20",
        "1/25/20",
    ]

    # validate serialize
    check_serialize = {
        "latest": 7,
        "timeline": OrderedDict([("1/22/20", 2), ("1/23/20", 3), ("1/24/20", 5), ("1/25/20", 7),]),
    }

    assert dict(history_data.serialize()) == check_serialize
Esempio n. 5
0
def test_location_class(mocked_timeline, test_id, country, country_code,
                        province, latitude, longitude, confirmed_latest,
                        deaths_latest, recovered_latest):

    # id, country, province, coordinates, confirmed, deaths, recovered
    coords = coordinates.Coordinates(latitude=latitude, longitude=longitude)

    # Timelines
    confirmed = timeline.Timeline(confirmed_latest)
    deaths = timeline.Timeline(deaths_latest)
    recovered = timeline.Timeline(recovered_latest)

    # Date now.
    now = datetime.utcnow().isoformat() + 'Z'

    # Location.
    location_obj = location.TimelinedLocation(test_id, country, province,
                                              coords, now, {
                                                  'confirmed': confirmed,
                                                  'deaths': deaths,
                                                  'recovered': recovered,
                                              })

    assert location_obj.country_code == country_code

    #validate serialize
    check_dict = {
        'id': test_id,
        'country': country,
        'country_code': country_code,
        'province': province,
        'last_updated': now,
        'coordinates': {
            'latitude': latitude,
            'longitude': longitude
        },
        'latest': {
            'confirmed': confirmed_latest,
            'deaths': deaths_latest,
            'recovered': recovered_latest
        }
    }

    assert location_obj.serialize() == check_dict