def extract_tests(api_response, defined_tests):
    """
    Create and return a dict of test name to test data.

    If api_response is None, return a dict with an empty dict.

    api_response: the JSON response from the Proctor API in Python object form.
    defined_tests: an iterable of test name strings defining the tests that
        should be available to the user. Usually from Django settings.
    """
    if api_response is None:
        return {'tests': {}}

    api_audit = api_response['audit']
    api_tests = api_response['tests']
    test_dict = {}
    for test_name in defined_tests:
        if test_name in api_tests:
            test_dict[test_name] = api_tests[test_name]
        else:
            # For all valid tests, we use an empty dict.
            # For tests NOT in the settings, access is an AttributeError.
            # This helps enforce program correctness.
            test_dict[test_name] = {}

    return {'audit': api_audit, 'tests': test_dict}