import pytest

from meteoflow.exceptions import ValidationError
from meteoflow.location import LocationCoords, LocationIP, LocationSlug, location_to_params


def test_location_slug_params():
    loc = LocationSlug("paris")
    assert location_to_params(loc) == {"slug": "paris"}


def test_location_coords_params():
    loc = LocationCoords(10.5, -20.25)
    assert location_to_params(loc) == {"lat": 10.5, "lon": -20.25}


def test_location_ip_params():
    loc = LocationIP("8.8.8.8")
    assert location_to_params(loc) == {"ip": "8.8.8.8"}


def test_location_invalid_slug():
    with pytest.raises(ValidationError):
        LocationSlug("")


def test_location_invalid_coords():
    with pytest.raises(ValidationError):
        LocationCoords(91, 0)


def test_location_invalid_ip():
    with pytest.raises(ValidationError):
        LocationIP("999.999.999.999")
