11import pytest
2-
3- from tests .fixtures import *
42from pydantic import ValidationError
53
64from src .models .point import Point
75from src .models .prediction import Prediction
86from src .models .weather_data import WeatherData
7+ from tests .fixtures import *
8+
99
1010class TestModels :
1111
@@ -14,10 +14,7 @@ async def test_point_model_valid(self, app):
1414 valid_point = {
1515 "title" : "Point title" ,
1616 "type" : "field" ,
17- "location" : {
18- "type" : "Point" ,
19- "coordinates" : [55.43989 , 43.121 ]
20- }
17+ "location" : {"type" : "Point" , "coordinates" : [55.43989 , 43.121 ]},
2118 }
2219 point = Point (** valid_point )
2320 assert point .title == "Point title"
@@ -28,49 +25,40 @@ async def test_point_model_invalid_point_type(self, app):
2825 invalid_point = {
2926 "title" : "Point title" ,
3027 "type" : "lala" ,
31- "location" : {
32- "type" : "Point" ,
33- "coordinates" : [55.43989 , 43.121 ]
34- }
28+ "location" : {"type" : "Point" , "coordinates" : [55.43989 , 43.121 ]},
3529 }
3630 with pytest .raises (ValidationError ):
3731 Point (** invalid_point )
3832
3933 @pytest .mark .anyio
4034 async def test_prediction_model_valid (self , app ):
4135 valid_prediction = {
42- "value" : 32.3 ,
43- "timestamp" : "2024-06-21T15:00:00.000Z" ,
44- "source" : "openweathermaps" ,
45- "data_type" : "weather" ,
46- "measurement_type" : "ambient_temperature" ,
47- "spatial_entity" : {
48- "id" : "bad6cd67-638f-42d8-82b8-d4d191174dd6" ,
49- "type" : "POI" ,
50- "location" : {
51- "type" : "Point" ,
52- "coordinates" : [ 39.1436 , 26.40518 ]
53- },
54- },
55- }
36+ "value" : 32.3 ,
37+ "timestamp" : "2024-06-21T15:00:00.000Z" ,
38+ "source" : "openweathermaps" ,
39+ "data_type" : "weather" ,
40+ "measurement_type" : "ambient_temperature" ,
41+ "spatial_entity" : {
42+ "id" : "bad6cd67-638f-42d8-82b8-d4d191174dd6" ,
43+ "type" : "POI" ,
44+ "location" : {"type" : "Point" , "coordinates" : [39.1436 , 26.40518 ]},
45+ },
46+ }
5647 prediction = Prediction (** valid_prediction )
5748 assert prediction .spatial_entity .location .type == "Point"
58- assert hasattr (prediction , ' created_at' )
49+ assert hasattr (prediction , " created_at" )
5950 assert prediction .value == 32.3
6051
6152 @pytest .mark .anyio
6253 async def test_weatherdata_model_valid (self , app ):
6354 valid_weeatherdata = {
64- "spatial_entity" : {
65- "id" : "0b1b7964-8f89-465c-a8b2-3d50a53459e0" ,
66- "type" : "POI" ,
67- "location" : {
68- "type" : "Point" ,
69- "coordinates" : [ 39.1436 , 26.40518 ]
70- },
71- },
72- "data" : {}
73- }
55+ "spatial_entity" : {
56+ "id" : "0b1b7964-8f89-465c-a8b2-3d50a53459e0" ,
57+ "type" : "POI" ,
58+ "location" : {"type" : "Point" , "coordinates" : [39.1436 , 26.40518 ]},
59+ },
60+ "data" : {},
61+ }
7462 weatherdata = WeatherData (** valid_weeatherdata )
7563 assert weatherdata .spatial_entity .location .coordinates == [39.1436 , 26.40518 ]
7664 assert weatherdata .spatial_entity .location .type == "Point"
@@ -79,16 +67,12 @@ async def test_weatherdata_model_valid(self, app):
7967 @pytest .mark .anyio
8068 async def test_weatherdata_model_not_valid_point_type (self , app ):
8169 valid_weeatherdata = {
82- "spatial_entity" : {
83- "id" : "0b1b7964-8f89-465c-a8b2-3d50a53459e0" ,
84- "type" : "routa" ,
85- "location" : {
86- "type" : "Point" ,
87- "coordinates" : [ 39.1436 , 26.40518 ]
88- },
89- },
90- "data" : {}
91- }
70+ "spatial_entity" : {
71+ "id" : "0b1b7964-8f89-465c-a8b2-3d50a53459e0" ,
72+ "type" : "routa" ,
73+ "location" : {"type" : "Point" , "coordinates" : [39.1436 , 26.40518 ]},
74+ },
75+ "data" : {},
76+ }
9277 with pytest .raises (ValidationError ):
9378 WeatherData (** valid_weeatherdata )
94-
0 commit comments