def test_unpublish_closed_erp(neufchateau, sample_record_ok, activite_cdv): fetcher = FakeJsonFetcher([sample_record_ok]) today = datetime(2021, 1, 1) mapper = VaccinationMapper Importer( "fake-id", fetcher=fetcher, mapper=mapper, activite=activite_cdv, today=today, ).process() # reimport the same record, but this time it's closed sample_closed = sample_record_ok.copy() sample_closed["properties"]["c_date_fermeture"] = "2021-01-01" fetcher = FakeJsonFetcher([sample_closed]) today = datetime(2021, 1, 2) mapper = VaccinationMapper Importer( "fake-id", fetcher=fetcher, mapper=mapper, activite=activite_cdv, today=today, ).process() erp = Erp.objects.get(source_id=sample_record_ok["properties"]["c_gid"]) assert erp.published is False
def test_intercept_sql_errors(mapper, neufchateau, sample_record_ok): long_cp_record = sample_record_ok.copy() long_cp_record["properties"]["c_com_cp"] = "12345 / 54321" with pytest.raises(DataError): erp, _ = mapper(long_cp_record).process() erp.save()
def test_handle_malformed_rdv_url(mapper, updates, neufchateau, sample_record_ok): sample_malformed_rdv_url = sample_record_ok.copy() sample_malformed_rdv_url["properties"].update(updates) erp, _ = mapper(sample_malformed_rdv_url).process() assert erp.metadata["centre_vaccination"]["url_rdv"] is None
def test_skip_importing_closed(mapper, neufchateau, sample_record_ok): sample_closed = sample_record_ok.copy() sample_closed["properties"]["c_date_fermeture"] = "2021-01-01" with pytest.raises(SkippedRecord) as err: mapper(sample_closed, today=datetime(2021, 1, 2)).process() assert "Centre fermé le 2021-01-01" in str(err.value)
def test_skip_importing_en_attente(mapper, updates, neufchateau, sample_record_ok): sample_en_attente = sample_record_ok.copy() sample_en_attente["properties"].update(updates) with pytest.raises(SkippedRecord) as err: mapper(sample_en_attente).process() assert RAISON_EN_ATTENTE in str(err.value)
def test_skip_importing_equipe_mobile(mapper, updates, neufchateau, sample_record_ok): sample_equipe_mobile = sample_record_ok.copy() sample_equipe_mobile["properties"].update(updates) with pytest.raises(SkippedRecord) as err: mapper(sample_equipe_mobile).process() assert RAISON_EQUIPE_MOBILE in str(err.value)
def test_skip_importing_reserve_public_restreint(mapper, updates, neufchateau, sample_record_ok): sample_public_restreint = sample_record_ok.copy() sample_public_restreint["properties"].update(updates) with pytest.raises(SkippedRecord) as err: mapper(sample_public_restreint).process() assert RAISON_PUBLIC_RESTREINT in str(err.value)
def test_skip_importing_reserve_pros(mapper, updates, neufchateau, sample_record_ok): sample_reserve_pros = sample_record_ok.copy() sample_reserve_pros["properties"].update(updates) with pytest.raises(SkippedRecord) as err: mapper(sample_reserve_pros).process() assert RAISON_RESERVE_PS in str(err.value)
def test_skip_importing_etablissements_penitentiares(mapper, updates, neufchateau, sample_record_ok): sample_en_attente = sample_record_ok.copy() sample_en_attente["properties"].update(updates) with pytest.raises(SkippedRecord) as err: mapper(sample_en_attente).process() assert RAISON_RESERVE_CARCERAL in str(err.value)
def test_update_existing_erp(mapper, neufchateau, sample_record_ok): m1 = mapper(sample_record_ok, today=datetime(2021, 1, 1)) erp1, _ = m1.process() erp1.accessibilite.commentaire = "user contrib" erp1.save() erp1.accessibilite.save() # import updated data for the same Erp sample_record_ok_updated = sample_record_ok.copy() sample_record_ok_updated["properties"]["c_rdv_tel"] = "1234" m2 = mapper(sample_record_ok_updated, today=datetime(2021, 1, 2)) erp2, _ = m2.process() assert erp1.id == erp2.id assert erp2.telephone == "1234" assert "user contrib" in erp2.accessibilite.commentaire
def test_source_id(mapper, neufchateau, sample_record_ok): erp, _ = mapper(sample_record_ok.copy()).process() assert erp.source_id == "219"