def METHOD_NAME(
        mock_bq_client: mock.MagicMock,
        mock_query_df: mock.MagicMock,
        mock_prepare_bucket: mock.MagicMock,
        mock_prepare_blob: mock.MagicMock,
        mock_export: mock.MagicMock,
        client: FlaskClient
):
    mock_bq_instance = mock_bq_client.return_value
    mock_bq_instance.list_tables.return_value = TEST_TABLES
    payload = {
        'dataset_name': 'my-dataset',
        'demographic': 'age'
    }
    client.post('/', json=payload)
    # ensure initial call to bq client and county-level calls per state/terr
    assert mock_bq_client.call_count == 1
    assert mock_query_df.call_count == NUM_STATES_AND_TERRITORIES
    assert mock_prepare_blob.call_count == NUM_STATES_AND_TERRITORIES
    assert mock_export.call_count == NUM_STATES_AND_TERRITORIES
    # ensure generated ndjson for bq.storage matches expected ndjson
    generated_nd_json = mock_export.call_args[0][1]
    assert (sorted(generated_nd_json) ==
            sorted(_test_query_results_df.to_json(orient="records",
                                                  lines=True)))
    bucket_name = mock_prepare_bucket.call_args[0][0]
    assert bucket_name == os.environ['EXPORT_BUCKET']
    # for each state/terr
    for i, fips in enumerate(STATE_LEVEL_FIPS_LIST):
        generated_query_string = mock_query_df.call_args_list[i][0][1]
        table_names = [get_table_name(x) for x in TEST_TABLES]
        expected_query_string = f"""
            SELECT *
            FROM {table_names[3]}
            WHERE county_fips LIKE '{fips}___'
            """
        # ensure query string is generated correctly only for county dataset
        assert generated_query_string == expected_query_string
        # ensure county level files are named as expected
        state_file_name = mock_prepare_blob.call_args_list[i][0][1]
        table = TEST_TABLES[3]
        expected_file_name = f'{table.dataset_id}-{table.table_id}-{fips}.json'
        assert state_file_name == expected_file_name