def find_all_labs(client):
    pool = ThreadPool(20)
    records = find_suppliers(client, FRAMEWORK_SLUG)
    records = pool.imap(add_framework_info(client, FRAMEWORK_SLUG), records)
    records = filter(lambda record: record['onFramework'], records)
    records = pool.imap(add_draft_services(client, FRAMEWORK_SLUG), records)
    services = itertools.chain.from_iterable(record['services'] for record in records)
    services = filter(
        lambda record: record['lot'] == 'user-research-studios' and record['status'] == 'submitted',
        services)

    return services
def test_add_draft_services_filtered_by_lot(mock_data_client):
    mock_data_client.find_draft_services.return_value = {
        "services": [
            {"lotSlug": "good"},
            {"lotSlug": "bad"}
        ]
    }
    service_adder = export_dos_suppliers.add_draft_services(
        mock_data_client, "framework-slug",
        lot="good")
    assert service_adder({"supplier_id": 1}) == {
        "supplier_id": 1,
        "services": [
            {"lotSlug": "good"},
        ]
    }
    mock_data_client.find_draft_services.assert_has_calls([
        call(1, framework='framework-slug'),
    ])
def test_add_draft_services_filtered_by_status(mock_data_client):
    mock_data_client.find_draft_services.return_value = {
        "services": [
            {"status": "submitted"},
            {"status": "failed"}
        ]
    }
    service_adder = export_dos_suppliers.add_draft_services(
        mock_data_client, "framework-slug",
        status="submitted")
    assert service_adder({"supplier_id": 1}) == {
        "supplier_id": 1,
        "services": [
            {"status": "submitted"},
        ]
    }
    mock_data_client.find_draft_services.assert_has_calls([
        call(1, framework='framework-slug'),
    ])
def test_add_draft_services(mock_data_client):
    mock_data_client.find_draft_services.side_effect = [
        {"services": ["service1", "service2"]},
        {"services": ["service3", "service4"]},
    ]

    service_adder = export_dos_suppliers.add_draft_services(mock_data_client, 'framework-slug')
    in_records = [
        {"supplier_id": 1},
        {"supplier_id": 2},
    ]
    out_records = list(map(service_adder, in_records))

    mock_data_client.find_draft_services.assert_has_calls([
        call(1, framework='framework-slug'),
        call(2, framework='framework-slug'),
    ])
    assert out_records == [
        {"supplier_id": 1, "services": ["service1", "service2"]},
        {"supplier_id": 2, "services": ["service3", "service4"]},
    ]