@@ -34,7 +34,7 @@ def generate_regulations_data(ids, geom, entity_names, layer_names, facades, ref
34
34
@pytest .fixture
35
35
def new_regulations () -> pd .DataFrame :
36
36
return generate_regulations_data (
37
- ids = [1 , 2 , 3 , 4 ],
37
+ ids = [3 , 4 , 5 , 6 ],
38
38
geom = [
39
39
"0106000020E610000001000000010300000001000000040000001EA36CE84A6F04C028FCC"
40
40
"F619D7F47407B5A4C4F4F6904C06878344D997F4740906370C20E6A04C050111641647F47"
@@ -67,35 +67,44 @@ def new_regulations() -> pd.DataFrame:
67
67
)
68
68
69
69
@pytest .fixture
70
- def old_regulations () -> pd .DataFrame :
70
+ def regulations_to_update () -> pd .DataFrame :
71
71
return generate_regulations_data (
72
- ids = [1 , 2 , 3 , 4 ],
72
+ ids = [1 , 2 ],
73
73
geom = [
74
74
None ,
75
75
None ,
76
- None ,
77
- None ,
78
76
],
79
- entity_names = ["Zone 5" , "Zone 6" , "Zone 7" , "Zone 8" ],
80
- layer_names = ["Layer 5" , "Layer 6" , "Layer 7" , "Layer 8" ],
81
- facades = ["IDF" , "IDF" , "NORD" , "NORD" ],
82
- ref_regs = ["arrêté 5" , "arrêté 6" , "arrêté 7" , "arrêté 8" ],
83
- urls = ["https://dummy_url_5" , "https://dummy_url_6" , "https://dummy_url_7" , "https://dummy_url_8" ],
84
- row_hashes = ["cacem_row_hash_5" , "cacem_row_hash_6" , "cacem_row_hash_7" , "cacem_row_hash_8" ],
85
- editions = ["2021-10-15" , "2021-10-16" , "2021-10-17" , "2021-10-18" ],
86
- editeurs = ["Claire Dagan" , "Maxime Perrault" , "Vincent Chery" , "Mike Data" ],
87
- sources = ["Source 5" , "Source 6" , "Source 7" , "Source 8" ],
88
- observations = ["Obs5" , "Obs6" , "Obs7" , "Obs8" ],
89
- thematiques = ["Mouillage" , "Dragage" , "Mouillage" , "Extraction" ],
90
- dates = ["2021-09-05" , "2021-09-06" , "2021-09-07" , "2021-09-08" ],
91
- duree_validites = ["permanent" , "permanent" , "permanent" , None ],
92
- temporalites = ["permanent" , "permanent" , "permanent" , "temporaire" ],
93
- types = ["Arrêté préfectoral" , "Décret" , "Arrêté inter-préfectoral" , None ]
77
+ entity_names = ["Zone 5" , "Zone 6" ,],
78
+ layer_names = ["Layer 5" , "Layer 6" ,],
79
+ facades = ["IDF" , "IDF" ],
80
+ ref_regs = ["arrêté 5" , "arrêté 6" ],
81
+ urls = ["https://dummy_url_5" , "https://dummy_url_6" ],
82
+ row_hashes = ["cacem_row_hash_5" , "cacem_row_hash_6" ],
83
+ editions = ["2021-10-15" , "2021-10-16" ,],
84
+ editeurs = ["Claire Dagan" , "Maxime Perrault" ],
85
+ sources = ["Source 5" , "Source 6" ],
86
+ observations = ["Obs5" , "Obs6" ],
87
+ thematiques = ["Mouillage" , "Dragage" ],
88
+ dates = ["2021-09-05" , "2021-09-06" ],
89
+ duree_validites = ["permanent" , "permanent" ],
90
+ temporalites = ["permanent" , "permanent" ],
91
+ types = ["Arrêté préfectoral" , "Décret" ]
94
92
)
95
93
96
94
97
- def test_load_new_regulations (reset_test_data , old_regulations ):
98
- load_new_regulations .run (old_regulations )
95
+ def test_load_new_regulations (reset_test_data , new_regulations ):
96
+ old_regulations = read_query (
97
+ "monitorenv_remote" ,
98
+ """SELECT
99
+ id, geom, entity_name, layer_name, facade,
100
+ ref_reg, url, row_hash, edition, editeur,
101
+ source, observation, thematique, date,
102
+ duree_validite, temporalite, type
103
+ FROM public.regulations_cacem
104
+ ORDER BY id"""
105
+ )
106
+ expectedRegulations = pd .concat ([old_regulations , new_regulations ], ignore_index = True )
107
+ load_new_regulations .run (new_regulations )
99
108
loaded_regulations = read_query (
100
109
"monitorenv_remote" ,
101
110
"""SELECT
@@ -106,19 +115,11 @@ def test_load_new_regulations(reset_test_data, old_regulations):
106
115
FROM public.regulations_cacem
107
116
ORDER BY id"""
108
117
)
109
- pd .testing .assert_frame_equal (loaded_regulations , old_regulations )
118
+ pd .testing .assert_frame_equal (loaded_regulations , expectedRegulations )
110
119
111
120
112
- def test_update_new_regulations (reset_test_data , new_regulations , old_regulations ):
113
- load (
114
- old_regulations ,
115
- table_name = "regulations_cacem" ,
116
- schema = "public" ,
117
- db_name = "monitorenv_remote" ,
118
- logger = prefect .context .get ("logger" ),
119
- how = "append" ,
120
- )
121
- update_regulations .run (new_regulations )
121
+ def test_update_new_regulations (reset_test_data , regulations_to_update ):
122
+ update_regulations .run (regulations_to_update )
122
123
updated_regulations = read_query (
123
124
"monitorenv_remote" ,
124
125
"""SELECT
@@ -129,4 +130,4 @@ def test_update_new_regulations(reset_test_data, new_regulations, old_regulation
129
130
FROM public.regulations_cacem
130
131
ORDER BY id"""
131
132
)
132
- pd .testing .assert_frame_equal (updated_regulations , new_regulations )
133
+ pd .testing .assert_frame_equal (updated_regulations , regulations_to_update )
0 commit comments