Esempio n. 1
0
def valid_data_fixture() -> DataType:

    location = {
        "city_name": "Shuzenji",
        "longitude": 139,
        "latitude": 35,
    }

    current_weather = {
        "temp": 281.52,
        "max_temp": 283.71,
        "min_temp": 280.15,
        "weather_description": "clear sky",
        "humidity": 1016,
        "pressure": 93,
    }

    return {
        "location": Location(**location),
        "current_weather": CurrentWeather(**current_weather),
    }
Esempio n. 2
0
def valid_response_fixture():
    location = {
        "city_name": "Shuzenji",
        "longitude": 139,
        "latitude": 35,
    }

    current_weather = {
        "temp": 281.52,
        "max_temp": 283.71,
        "min_temp": 280.15,
        "weather_description": "clear sky",
        "humidity": 93,
        "pressure": 1016,
    }

    weather_info = {
        "location": Location(**location),
        "current_weather": CurrentWeather(**current_weather),
    }

    return WeatherInfo(**weather_info).dict()
        def test_is_required(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.pop("latitude")
                Location(**valid_data)

            self.assert_validation_error("value_error.missing", excinfo)
        def test_must_be_int(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.update({"latitude": "some latitude"})
                Location(**valid_data)

            self.assert_validation_error("type_error.integer", excinfo)
        def test_must_be_str(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.update({"city_name": [1]})
                Location(**valid_data)

            self.assert_validation_error("type_error.str", excinfo)
 def test_immutability(self, valid_data):
     tdi = Location(**valid_data)
     for key in tdi.dict().keys():
         with pytest.raises(TypeError):
             setattr(tdi, key, "some value")
 def test_invalidation(self, invalid_data):
     with pytest.raises(ValidationError):
         Location(**invalid_data)
 def test_validation(self, valid_data):
     assert Location(**valid_data)