def METHOD_NAME(services, municipalities):
    METHOD_NAME = []
    max_unit_count = 5
    index = 1
    unit_id = 0
    distinct_service_muni_counts = set()
    unit_names = set()
    for municipality in municipalities:
        for service in services:
            if index % max_unit_count > 0:
                distinct_service_muni_counts.add((service.id, municipality.id))
            for i in range(0, index % max_unit_count):
                name = "unit_s{}_m{}_{}".format(service.id, municipality.id, i)
                unit = Unit.objects.create(
                    id=unit_id,
                    municipality=municipality,
                    last_modified_time=now(),
                    name=name,
                )
                unit_names.add(name)
                unit.save()
                usd = UnitServiceDetails.objects.create(unit=unit, service=service)
                usd.save()
                METHOD_NAME.append(unit)
                unit_id += 1
            index += 1
    unit_name = "unit_s0_special_case_no_muni"
    unit = Unit.objects.create(
        id=500000, municipality=None, last_modified_time=now(), name=unit_name
    )
    unit_names.add(unit_name)
    usd = UnitServiceDetails.objects.create(unit=unit, service=services[0])
    usd.save()
    METHOD_NAME.append(unit)
    # Currently generates the following units
    assert unit_names == set(
        [
            "unit_s0_mhelsinki_0",
            "unit_s0_mvantaa_0",
            "unit_s1_mhelsinki_0",
            "unit_s1_mhelsinki_1",
            "unit_s1_mvantaa_0",
            "unit_s1_mvantaa_1",
            "unit_s2_mhelsinki_0",
            "unit_s2_mhelsinki_1",
            "unit_s2_mhelsinki_2",
            "unit_s2_mvantaa_0",
            "unit_s2_mvantaa_1",
            "unit_s2_mvantaa_2",
            "unit_s3_mhelsinki_0",
            "unit_s3_mhelsinki_1",
            "unit_s3_mhelsinki_2",
            "unit_s3_mhelsinki_3",
            "unit_s3_mvantaa_0",
            "unit_s3_mvantaa_1",
            "unit_s3_mvantaa_2",
            "unit_s3_mvantaa_3",
            "unit_s0_special_case_no_muni",
        ]
    )
    return {"units": METHOD_NAME, "count_rows": len(distinct_service_muni_counts) + 1}