示例#1
0
def test_export_reserved_centers(tmp_path):
    centres_cherchés_dict = [{
        "departement": "01",
        "nom": "Bugey Sud - Réservé aux médecins du groupe hospitalier",
        "url": "https://example.com/bugey-sud",
        "plateforme": "Doctolib",
        "prochain_rdv": "2021-04-10T00:00:00",
        "location": None,
        "metadata": None,
        "type": None,
        "appointment_by_phone_only": False,
        "appointment_count": 1,
        "internal_id": None,
    }]
    centres_cherchés = [
        CenterInfo.from_dict(center) for center in centres_cherchés_dict
    ]

    out_dir = tmp_path / "out"
    out_dir.mkdir()
    outpath_format = str(out_dir / "{}.json")

    fake_now = dt.datetime(2021, 4, 4)
    get_start_date()
    with mock_datetime_now(fake_now):
        export_data(centres_cherchés, [], outpath_format=outpath_format)

    # Departements 01 and 59 should contain expected data.

    content = json.loads((out_dir / "01.json").read_text())
    assert content == {
        "version": 1,
        "centres_disponibles": [],
        "centres_indisponibles": [],
        "last_scrap": [],
        "last_updated": "2021-04-04T00:00:00",
    }
示例#2
0
def test_export_data(tmp_path):
    centres_cherchés_dict = [
        {
            "departement": "01",
            "nom": "Bugey Sud",
            "url": "https://example.com/bugey-sud",
            "plateforme": "Doctolib",
            "prochain_rdv": "2021-04-10T00:00:00",
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 1,
            "internal_id": None,
        },
        {
            "departement": "59",
            "nom": "CH Armentières",
            "url": "https://example.com/ch-armentieres",
            "plateforme": "Keldoc",
            "prochain_rdv": "2021-04-11:00:00",
            "erreur": None,
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 1,
            "internal_id": None,
        },
        {
            "departement": "59",
            "nom": "Clinique du Cambresis",
            "url": "https://example.com/clinique-du-cambresis",
            "plateforme": "Maiia",
            "prochain_rdv": None,
            "erreur": None,
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 1,
            "internal_id": None,
        },
        {
            "departement": "92",
            "nom": "Médiathèque Jacques GAUTIER",
            "url": "https://example.com/mediatheque-jacques-gautier",
            "plateforme": "Maiia",
            "prochain_rdv": "2021-04-11:00:00",
            "erreur": None,
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 0,
            "internal_id": None,
        },
        {
            # Unknown departement (edge case) => should be skipped w/o failing
            "departement": "1234",
            "nom": "Hôpital magique",
            "url": "https://example.com/hopital-magique",
            "plateforme": "Doctolib",
            "prochain_rdv": "2021-04-12:00:00",
            "erreur": None,
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 1,
            "internal_id": None,
        },
        {
            # Not technically a department, should be in om.json
            "departement": "975",
            "nom": "Exemple Saint Pierre et Miquelon",
            "url": "https://example.com/st-pierre-miquelon",
            "plateforme": "Doctolib",
            "prochain_rdv": "2021-05-10T00:00:00",
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_by_phone_only": False,
            "appointment_count": 1,
            "internal_id": None,
        },
    ]
    centres_cherchés = [
        CenterInfo.from_dict(center) for center in centres_cherchés_dict
    ]

    for center in centres_cherchés:
        if center.nom != "Médiathèque Jacques GAUTIER":
            center.appointment_count = 1

    out_dir = tmp_path / "out"
    out_dir.mkdir()
    outpath_format = str(out_dir / "{}.json")

    fake_now = dt.datetime(2021, 4, 4)
    get_start_date()
    with mock_datetime_now(fake_now):
        export_data(centres_cherchés, [], outpath_format=outpath_format)

    # All departements for which we don't have data should be empty.
    for departement in departementUtils.import_departements():
        if departement in ("01", "59", "92"):
            continue
        content = json.loads((out_dir / f"{departement}.json").read_text())
        assert content == {
            "version": 1,
            "last_scrap": [],
            "centres_disponibles": [],
            "centres_indisponibles": [],
            "last_updated": "2021-04-04T00:00:00",
        }

    # Departements 01 and 59 should contain expected data.

    content = json.loads((out_dir / "01.json").read_text())
    assert content == {
        "version":
        1,
        "centres_disponibles": [
            {
                "departement": "01",
                "nom": "Bugey Sud",
                "url": "https://example.com/bugey-sud",
                "plateforme": "Doctolib",
                "prochain_rdv": "2021-04-10T00:00:00",
                "location": None,
                "metadata": None,
                "type": None,
                "appointment_by_phone_only": False,
                "appointment_count": 1,
                "internal_id": None,
                "appointment_by_phone_only": False,
                "vaccine_type": None,
                "erreur": None,
                "last_scan_with_availabilities": None,
                "request_counts": None,
            },
        ],
        "centres_indisponibles": [],
        "last_scrap": [],
        "last_updated":
        "2021-04-04T00:00:00",
    }

    content = json.loads((out_dir / "59.json").read_text())
    assert content == {
        "version":
        1,
        "centres_disponibles": [
            {
                "departement": "59",
                "nom": "CH Armentières",
                "url": "https://example.com/ch-armentieres",
                "plateforme": "Keldoc",
                "prochain_rdv": "2021-04-11:00:00",
                "location": None,
                "metadata": None,
                "appointment_by_phone_only": False,
                "type": None,
                "appointment_count": 1,
                "internal_id": None,
                "vaccine_type": None,
                "erreur": None,
                "last_scan_with_availabilities": None,
                "request_counts": None,
            },
        ],
        "centres_indisponibles": [{
            "departement": "59",
            "nom": "Clinique du Cambresis",
            "url": "https://example.com/clinique-du-cambresis",
            "plateforme": "Maiia",
            "prochain_rdv": None,
            "location": None,
            "metadata": None,
            "type": None,
            "appointment_count": 1,
            "internal_id": None,
            "appointment_by_phone_only": False,
            "vaccine_type": None,
            "erreur": None,
            "last_scan_with_availabilities": None,
            "request_counts": None,
        }],
        "last_scrap": [],
        "last_updated":
        "2021-04-04T00:00:00",
    }

    content = json.loads((out_dir / "92.json").read_text())
    assert content == {
        "version":
        1,
        "centres_disponibles": [],
        "centres_indisponibles": [
            {
                "departement": "92",
                "nom": "Médiathèque Jacques GAUTIER",
                "url": "https://example.com/mediatheque-jacques-gautier",
                "location": None,
                "metadata": None,
                "prochain_rdv": "2021-04-11:00:00",
                "plateforme": "Maiia",
                "type": None,
                "appointment_by_phone_only": False,
                "appointment_count": 0,
                "internal_id": None,
                "vaccine_type": None,
                "erreur": None,
                "last_scan_with_availabilities": None,
                "request_counts": None,
            },
        ],
        "last_scrap": [],
        "last_updated":
        "2021-04-04T00:00:00",
    }

    # outre-mer file should contain St Pierre et Miquelon data
    content = json.loads((out_dir / "om.json").read_text())
    assert content == {
        "version":
        1,
        "centres_disponibles": [
            {
                "departement": "om",
                "nom": "Exemple Saint Pierre et Miquelon",
                "url": "https://example.com/st-pierre-miquelon",
                "plateforme": "Doctolib",
                "prochain_rdv": "2021-05-10T00:00:00",
                "location": None,
                "metadata": None,
                "type": None,
                "appointment_by_phone_only": False,
                "appointment_count": 1,
                "internal_id": None,
                "vaccine_type": None,
                "erreur": None,
                "last_scan_with_availabilities": None,
                "request_counts": None,
            },
        ],
        "centres_indisponibles": [],
        "last_scrap": [],
        "last_updated":
        "2021-04-04T00:00:00",
    }

    # On test l'export vers le format inscrit sur la plateforme data.gouv.fr
    content = json.loads((out_dir / "centres_open_data.json").read_text())
    assert content == [
        {
            "departement": "01",
            "nom": "Bugey Sud",
            "url": "https://example.com/bugey-sud",
            "plateforme": "Doctolib"
        },
        {
            "departement": "59",
            "nom": "CH Armentières",
            "url": "https://example.com/ch-armentieres",
            "plateforme": "Keldoc",
        },
        {
            "departement": "59",
            "nom": "Clinique du Cambresis",
            "url": "https://example.com/clinique-du-cambresis",
            "plateforme": "Maiia",
        },
        {
            "departement": "92",
            "nom": "Médiathèque Jacques GAUTIER",
            "url": "https://example.com/mediatheque-jacques-gautier",
            "plateforme": "Maiia",
        },
        {
            "departement": "om",
            "nom": "Exemple Saint Pierre et Miquelon",
            "plateforme": "Doctolib",
            "url": "https://example.com/st-pierre-miquelon",
        },
    ]