@@ -41,7 +41,8 @@ def fixture_bod_dataset(bod_contact_organisation):
4141 yield BodDataset .objects .create (
4242 id = 170 ,
4343 id_dataset = "ch.bafu.auen-vegetationskarten" ,
44- fk_contactorganisation_id = bod_contact_organisation .pk_contactorganisation_id
44+ fk_contactorganisation_id = bod_contact_organisation .pk_contactorganisation_id ,
45+ staging = "prod"
4546 )
4647
4748
@@ -131,17 +132,22 @@ def test_command_imports_providers(bod_dataset):
131132 assert provider .acronym_rm == "UFAM"
132133
133134
134- def test_command_imports_attributions (bod_contact_organisation , bod_dataset ):
135- out = StringIO ()
136- call_command (
137- "bod_sync" , providers = False , attributions = True , datasets = False , verbosity = 2 , stdout = out
138- )
139- assert "skipping attribution 'ch.bafu' as no matching provider was found" in out .getvalue ()
140- assert 'nothing to be done, already in sync' in out .getvalue ()
141- assert Provider .objects .count () == 0
142- assert Attribution .objects .count () == 0
143- assert Dataset .objects .count () == 0
135+ def test_command_skips_invalid_providers (bod_contact_organisation , bod_dataset ):
136+ for attribution in ("somethingelse" , "" , None ):
137+ bod_contact_organisation .attribution = attribution
138+ bod_contact_organisation .save ()
139+
140+ out = StringIO ()
141+ call_command (
142+ "bod_sync" , providers = True , attributions = False , datasets = False , verbosity = 2 , stdout = out
143+ )
144+ assert "nothing to be done" in out .getvalue ()
145+ assert Provider .objects .count () == 0
146+ assert Attribution .objects .count () == 0
147+ assert Dataset .objects .count () == 0
144148
149+
150+ def test_command_imports_attributions (bod_contact_organisation , bod_dataset ):
145151 provider = Provider .objects .create (
146152 provider_id = "ch.bafu" ,
147153 name_de = "XXX" ,
@@ -152,6 +158,8 @@ def test_command_imports_attributions(bod_contact_organisation, bod_dataset):
152158 acronym_en = "XXX" ,
153159 _legacy_id = bod_contact_organisation .pk_contactorganisation_id
154160 )
161+
162+ out = StringIO ()
155163 call_command (
156164 "bod_sync" , providers = False , attributions = True , datasets = False , verbosity = 2 , stdout = out
157165 )
@@ -175,20 +183,24 @@ def test_command_imports_attributions(bod_contact_organisation, bod_dataset):
175183 assert attribution .description_rm == "UFAM"
176184
177185
178- def test_command_imports_datasets (bod_contact_organisation , bod_dataset ):
179- out = StringIO ()
180- call_command (
181- "bod_sync" , providers = False , attributions = False , datasets = True , verbosity = 2 , stdout = out
182- )
183- assert (
184- "skipping dataset 'ch.bafu.auen-vegetationskarten' " +
185- "as no matching attribution was found"
186- ) in out .getvalue ()
187- assert 'nothing to be done, already in sync' in out .getvalue ()
188- assert Provider .objects .count () == 0
189- assert Attribution .objects .count () == 0
190- assert Dataset .objects .count () == 0
186+ def test_command_skips_invalid_attributions (bod_contact_organisation , bod_dataset ):
187+ for attribution in (bod_contact_organisation .attribution , "" , None ):
188+ bod_contact_organisation .attribution = attribution
189+ bod_contact_organisation .save ()
190+
191+ out = StringIO ()
192+ call_command (
193+ "bod_sync" , providers = False , attributions = True , datasets = False , verbosity = 2 , stdout = out
194+ )
195+ assert (f"skipping attribution '{ attribution } ' as no matching provider was found"
196+ ) in out .getvalue ()
197+ assert 'nothing to be done, already in sync' in out .getvalue ()
198+ assert Provider .objects .count () == 0
199+ assert Attribution .objects .count () == 0
200+ assert Dataset .objects .count () == 0
201+
191202
203+ def test_command_imports_datasets (bod_contact_organisation , bod_dataset ):
192204 provider = Provider .objects .create (
193205 provider_id = "ch.bafu" ,
194206 name_de = "XXX" ,
@@ -210,6 +222,8 @@ def test_command_imports_datasets(bod_contact_organisation, bod_dataset):
210222 provider = provider ,
211223 _legacy_id = bod_contact_organisation .pk_contactorganisation_id
212224 )
225+
226+ out = StringIO ()
213227 call_command (
214228 "bod_sync" , providers = False , attributions = False , datasets = True , verbosity = 2 , stdout = out
215229 )
@@ -224,6 +238,34 @@ def test_command_imports_datasets(bod_contact_organisation, bod_dataset):
224238 assert dataset .dataset_id == "ch.bafu.auen-vegetationskarten"
225239
226240
241+ def test_command_skips_invalid_datasets (bod_dataset ):
242+ out = StringIO ()
243+ call_command (
244+ "bod_sync" , providers = False , attributions = False , datasets = True , verbosity = 2 , stdout = out
245+ )
246+ assert (
247+ "skipping dataset 'ch.bafu.auen-vegetationskarten' " +
248+ "as no matching attribution was found"
249+ ) in out .getvalue ()
250+ assert 'nothing to be done, already in sync' in out .getvalue ()
251+ assert Provider .objects .count () == 0
252+ assert Attribution .objects .count () == 0
253+ assert Dataset .objects .count () == 0
254+
255+
256+ def test_command_skips_non_prod_datasets (bod_dataset ):
257+ bod_dataset .staging = 'test'
258+
259+ out = StringIO ()
260+ call_command (
261+ "bod_sync" , providers = False , attributions = False , datasets = True , verbosity = 2 , stdout = out
262+ )
263+ assert 'nothing to be done, already in sync' in out .getvalue ()
264+ assert Provider .objects .count () == 0
265+ assert Attribution .objects .count () == 0
266+ assert Dataset .objects .count () == 0
267+
268+
227269def test_command_updates (bod_contact_organisation , bod_dataset ):
228270 # Add objects that will be updated
229271 provider = Provider .objects .create (
0 commit comments