def test_center_to_centerdict(): center = CenterInfo( "28", "Delphine ROUSSEAU", "https://patient.avecmondoc.com/fiche/structure/delphine-rousseau-159") center.metadata = { "address": "21 Rue Nicole 28000 Chartres", "phone_number": "0033143987678", "business_hours": { "Lundi": "08:30-12:30 13:30-17:00", "Mardi": "08:30-12:30 13:30-17:00", "Mercredi": "08:30-12:30 13:30-17:00", "Jeudi": "08:30-12:30 13:30-17:00", "Vendredi": "08:30-12:30 13:30-17:00", "Samedi": "", "Dimanche": "", }, } center.location = CenterLocation(1.481373, 48.447586, "Chartres", "28000") center.internal_id = "amd159" center.type = DRUG_STORE data_file = Path("tests/fixtures/avecmondoc/centerdict.json") data = json.loads(data_file.read_text(encoding="utf8")) assert center_to_centerdict(center) == data
def convert_ordoclic_to_center_info(data: dict, center: CenterInfo) -> CenterInfo: localization = data.get("location") coordinates = localization.get("coordinates") if coordinates["lon"] or coordinates["lat"]: city = urlify(localization.get("city")) loc = CenterLocation(coordinates["lon"], coordinates["lat"], city) center.fill_localization(loc) center.metadata = dict() center.metadata["address"] = f'{localization["address"]}, {localization["zip"]} {localization["city"]}' if len(data.get("phone_number", "")) > 3: center.metadata["phone_number"] = format_phone_number(data.get("phone_number")) center.metadata["business_hours"] = None return center
def convert_ordoclic_to_center_info(data: dict, center: CenterInfo) -> CenterInfo: localization = data.get('location') coordinates = localization.get('coordinates') if coordinates['lon'] or coordinates['lat']: city = urlify(localization.get('city')) loc = CenterLocation(coordinates['lon'], coordinates['lat'], city) center.fill_localization(loc) center.metadata = dict() center.metadata['address'] = f'{localization["address"]}, {localization["zip"]} {localization["city"]}' if len(data.get('phone_number', '')) > 3: center.metadata['phone_number'] = format_phone_number(data.get('phone_number')) center.metadata['business_hours'] = None return center
def test_get_first_availability(): request = ScraperRequest( url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-?centerid=5ffc744c68dedf073a5b87a2", start_date="2021-07-17", center_info=CenterInfo( departement="42", nom="Centre de vaccination COVID - Hôpital du Gier ", url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-?centerid=5ffc744c68dedf073a5b87a2", location=CenterLocation(longitude=4.50184989506, latitude=45.4698319517, city="Saint-Chamond", cp="42400"), metadata={ "address": "19 rue victor hugo 42400 Saint-Chamond", "business_hours": { "Lundi": "08:15-17:15", "Mardi": "08:15-17:15", "Mercredi": "08:15-17:15", "Jeudi": "08:15-17:15", "Vendredi": "08:15-17:15", "Samedi": "08:15-17:15", "Dimanche": "08:15-17:15", }, }, type="vaccination-center", internal_id="5ffc744c", ), ) reasons = get_reasons("5ffc744c68dedf073a5b87a2", limit=MAIIA_LIMIT, client=client) instance = MaiiaSlots(creneau_q=DummyQueue, client=None) fake_now = dt.datetime(2021, 4, 29, 18, 20) with mock_datetime_now(fake_now): first_availability, slots_count = instance.get_first_availability( "5ffc744c68dedf073a5b87a2", "2021-04-29", reasons, client=client, request=request) assert slots_count == 7182 assert first_availability.isoformat() == "2021-05-13T13:40:00+00:00"
def test_center_info_fill(): center = CenterInfo("Paris", "Centre 1", "https://.../centre") newloc = CenterLocation(1.122, 2.391, "Ok", "Cp") request = ScraperRequest(center.url, "2021-05-04") result = ScraperResult(request, "Doctolib", "2021-05-06") center.fill_localization(newloc) request.update_appointment_count(42) request.add_vaccine_type(Vaccine.PFIZER) request.add_vaccine_type(Vaccine.ASTRAZENECA) request.add_vaccine_type(Vaccine.MODERNA) request.update_internal_id("doctolibcentre1") request.update_practitioner_type(DRUG_STORE) request.set_appointments_only_by_phone(False) center.fill_result(result) assert center.location == newloc assert center.prochain_rdv == "2021-05-06" assert center.plateforme == "Doctolib" assert center.type == "drugstore" assert center.appointment_count == 42 assert center.internal_id == "doctolibcentre1" assert center.vaccine_type == ["Pfizer-BioNTech", "AstraZeneca", "Moderna"] assert not center.appointment_by_phone_only assert center.default() == { "departement": "Paris", "nom": "Centre 1", "url": "https://.../centre", "location": { "longitude": 1.122, "latitude": 2.391, "city": "Ok", "cp": "Cp" }, "metadata": None, "prochain_rdv": "2021-05-06", "plateforme": "Doctolib", "type": "drugstore", "appointment_count": 42, "internal_id": "doctolibcentre1", "vaccine_type": ["Pfizer-BioNTech", "AstraZeneca", "Moderna"], "appointment_by_phone_only": False, "erreur": None, "last_scan_with_availabilities": None, "appointment_schedules": None, "request_counts": None, }
def test_fetch_slots(): def app(request: httpx.Request) -> httpx.Response: if request.url.path == "/api/BusinessHours/availabilitiesPerDay": path = Path("tests/fixtures/avecmondoc/get_availabilities.json") return httpx.Response(200, json=json.loads( path.read_text(encoding="utf8"))) if request.url.path == "/api/Organizations/slug/delphine-rousseau-159": path = Path("tests/fixtures/avecmondoc/get_organization_slug.json") return httpx.Response(200, json=json.loads( path.read_text(encoding="utf8"))) return httpx.Response(404) center_info = CenterInfo( departement="69", nom="Pharmacie AVENUE (Picard)", url= "https://patient.avecmondoc.com/fiche/structure/pharmacie-avenue-picard-583", location=CenterLocation(longitude=4.77231, latitude=45.742216, city="Francheville", cp="69340"), metadata={ "address": "29 avenue du Chater, 69340 Francheville", "business_hours": { "Lundi": "08:45-12:15 15:00-19:15", "Mardi": "08:45-12:15 15:00-19:15", "Mercredi": "08:45-12:15 15:00-19:15", "Jeudi": "08:45-12:15 15:00-19:15", "Vendredi": "08:45-12:15 15:00-19:15", "Samedi": "08:45-12:15", "Dimanche": "", }, "phone_number": "+33478342931", }, plateforme="Avecmondoc", type="drugstore", internal_id="amd583", ) client = httpx.Client(transport=httpx.MockTransport(app)) url = "https://patient.avecmondoc.com/fiche/structure/delphine-rousseau-159" request = ScraperRequest(url, "2021-05-20", center_info=center_info) first_availability = fetch_slots(request, client=client) assert first_availability == "2021-05-20T09:00:00+00:00" assert request.vaccine_type == ["Pfizer-BioNTech", "Janssen"]
def test_center_info_fill(): center = CenterInfo("Paris", "Centre 1", "https://.../centre") newloc = CenterLocation(1.122, 2.391, "Ok") request = ScraperRequest(center.url, "2021-05-04") result = ScraperResult(request, "Doctolib", "2021-05-06") center.fill_localization(newloc) request.update_appointment_count(42) request.add_vaccine_type(Vaccine.PFIZER) request.add_vaccine_type(Vaccine.ASTRAZENECA) request.add_vaccine_type(Vaccine.MODERNA) request.update_internal_id("doctolibcentre1") request.update_practitioner_type(DRUG_STORE) request.set_appointments_only_by_phone(False) center.fill_result(result) assert center.location == newloc assert center.prochain_rdv == "2021-05-06" assert center.plateforme == "Doctolib" assert center.type == "drugstore" assert center.appointment_count == 42 assert center.internal_id == "doctolibcentre1" assert center.vaccine_type == ["Pfizer-BioNTech", "AstraZeneca", "Moderna"] assert not center.appointment_by_phone_only assert center.default() == { 'departement': 'Paris', 'nom': 'Centre 1', 'url': 'https://.../centre', 'location': { 'longitude': 1.122, 'latitude': 2.391, 'city': 'Ok' }, 'metadata': None, 'prochain_rdv': '2021-05-06', 'plateforme': 'Doctolib', 'type': 'drugstore', 'appointment_count': 42, 'internal_id': 'doctolibcentre1', 'vaccine_type': ['Pfizer-BioNTech', 'AstraZeneca', 'Moderna'], 'appointment_by_phone_only': False, 'erreur': None, 'last_scan_with_availabilities': None, 'appointment_schedules': None }
def from_csv_data(cls, data: dict) -> CenterInfo: departement = "" try: departement = departementUtils.to_departement_number( data.get("com_insee")) except ValueError as e: logger.error( f"erreur lors du traitement de la ligne avec le gid {data['gid']}, com_insee={data['com_insee']} : {e}" ) center = CenterInfo( departement, data.get("nom"), data.get("rdv_site_web"), location=CenterLocation.from_csv_data(data), metadata=cls._metadata_from_csv_data(data), ) # TODO: Behaviour about particular implementations shouldln’t bubble up to the pattern. if data.get("iterator") == "ordoclic": return convert_ordoclic_to_center_info(data, center) return center
def test_organization_to_center(): data_file = Path("tests/fixtures/avecmondoc/get_organization_slug.json") data = json.loads(data_file.read_text(encoding='utf8')) center = CenterInfo( "28", "Delphine ROUSSEAU", "https://patient.avecmondoc.com/fiche/structure/delphine-rousseau-159" ) center.metadata = { "address": "21 Rue Nicole 28000 Chartres", "phone_number": "0033143987678", "business_hours": { "Lundi": "08:30-12:30 13:30-17:00", "Mardi": "08:30-12:30 13:30-17:00", "Mercredi": "08:30-12:30 13:30-17:00", "Jeudi": "08:30-12:30 13:30-17:00", "Vendredi": "08:30-12:30 13:30-17:00", "Samedi": "", "Dimanche": "", } } center.location = CenterLocation(1.481373, 48.447586, "Chartres", "28000") center.internal_id = "amd159" assert avecmondoc.organization_to_center(data).default() == center.default()
def test_fetch_slots(): # Oops I forgot centerid request = ScraperRequest( url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-", start_date="2021-04-16", center_info=CenterInfo( departement="42", nom="Centre de vaccination COVID - Hôpital du Gier ", url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-?centerid=5ffc744c68dedf073a5b87a2", location=CenterLocation(longitude=4.50184989506, latitude=45.4698319517, city="Saint-Chamond", cp="42400"), metadata={ "address": "19 rue victor hugo 42400 Saint-Chamond", "business_hours": { "Lundi": "08:15-17:15", "Mardi": "08:15-17:15", "Mercredi": "08:15-17:15", "Jeudi": "08:15-17:15", "Vendredi": "08:15-17:15", "Samedi": "08:15-17:15", "Dimanche": "08:15-17:15", }, }, type="vaccination-center", internal_id="5ffc744c", ), ) first_availability = fetch_slots(request, client=client) assert first_availability == None request = ScraperRequest( url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-?centerid=5ffc744c68dedf073a5b87a2", start_date="2021-04-16", center_info=CenterInfo( departement="42", nom="Centre de vaccination COVID - Hôpital du Gier ", url= "https://www.maiia.com/centre-de-vaccination/42400-saint-chamond/centre-de-vaccination-covid---hopital-du-gier-?centerid=5ffc744c68dedf073a5b87a2", location=CenterLocation(longitude=4.50184989506, latitude=45.4698319517, city="Saint-Chamond", cp="42400"), metadata={ "address": "19 rue victor hugo 42400 Saint-Chamond", "business_hours": { "Lundi": "08:15-17:15", "Mardi": "08:15-17:15", "Mercredi": "08:15-17:15", "Jeudi": "08:15-17:15", "Vendredi": "08:15-17:15", "Samedi": "08:15-17:15", "Dimanche": "08:15-17:15", }, }, type="vaccination-center", internal_id="5ffc744c", ), ) print(request.center_info) first_availability = fetch_slots(request, client=client) assert first_availability == "2021-05-13T13:40:00+00:00"
now=now)) # Then assert actual.asdict( )["centres_disponibles"] == expected["centres_disponibles"] centre_lamastre = Lieu( departement="07", nom="CENTRE DE VACCINATION COVID - LAMASTRE", url= "https://www.maiia.com/centre-de-vaccination/07270-lamastre/centre-de-vaccination-covid---lamastre?centerid=5fff1f61b1a1aa1cc204f203", lieu_type="vaccination-center", internal_id="maiia5fff1f61b1a1aa1cc204f203", location=CenterLocation( longitude=4.5, latitude=45.0, city="Lamastre", cp="07270", ), metadata=None, plateforme=Plateforme.MAIIA, ) centre_perigueux = Lieu( departement="24", nom="CENTRE DE VACCINATION COVID - PERIGUEUX", url= "https://www.doctolib.com/centre-de-vaccination/24000-perigueux/centre-de-vaccination-covid---lamastre?centerid=5fff1f61b1a1aa1cc204f205", lieu_type="vaccination-center", internal_id="doctolibfaaaaa1b1a1aa1cc204f203", location=CenterLocation( longitude=4.5,
now=now, tags=tags)) # Then assert actual.asdict() == expected centre_lamastre = Lieu( departement="07", nom="CENTRE DE VACCINATION COVID - LAMASTRE", url= "https://www.maiia.com/centre-de-vaccination/07270-lamastre/centre-de-vaccination-covid---lamastre?centerid=5fff1f61b1a1aa1cc204f203", lieu_type="vaccination-center", internal_id="maiia5fff1f61b1a1aa1cc204f203", location=CenterLocation( longitude=4.5, latitude=45.0, city="Lamastre", cp="07270", ), metadata=None, plateforme=Plateforme.MAIIA, ) centre_saint_andeol = Lieu( departement="07", nom= "CENTRE DE VACCINATION COVID 19 TERRITORIAL ET HOSPITALIER DE BOURG DU SAINT-ANDÉOL VIVIERS", url= "https://www.doctolib.fr/vaccination-covid-19/bourg-saint-andeol/centre-de-vaccination-territorial-bourg-saint-andeol?pid=practice-166627", lieu_type="vaccination-center", internal_id="doctolib245141pid166627", location=CenterLocation(