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("min_temp")
                CurrentWeather(**valid_data)

            self.assert_validation_error("value_error.missing", excinfo)
        def test_must_be_float(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.update({"min_temp": [1]})
                CurrentWeather(**valid_data)

            self.assert_validation_error("type_error.float", excinfo)
 def test_immutability(self, valid_data):
     tdi = CurrentWeather(**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):
         CurrentWeather(**invalid_data)
 def test_validation(self, valid_data):
     assert CurrentWeather(**valid_data)
        def test_must_be_float(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.update({"pressure": "some string"})
                CurrentWeather(**valid_data)

            self.assert_validation_error("type_error.integer", excinfo)
        def test_must_be_float(self, valid_data):
            with pytest.raises(ValidationError) as excinfo:
                valid_data.update({"weather_description": ["some string"]})
                CurrentWeather(**valid_data)

            self.assert_validation_error("type_error.str", excinfo)