def test_cache_filename_sanitized():
    args = argparse.Namespace()
    args.client_id = 'client_id'
    args.client_secret = 'fake-secret'
    args.scopes = 'fake scopes'
    cfg = ConfigParser.ConfigParser()
    cfg.add_section('oauth2')
    cfg.set('oauth2', 'token_cache_base', '/tmp/cache')
    print oauth2.build_oauth2('@weird$app name', args, cfg).token_cache_file
    assert oauth2.build_oauth2('@weird$app name', args, cfg) \
        .token_cache_file == '/tmp/cache/_weird_app_name_oauth2_cache.pickle'
def authen():
    try:
        auth = oauth2.build_oauth2(
            app='manage_research_exports').build_authorizer()
    except:
        auth = ""
    return auth
def test_compute_cache_filname_path_no_double_slash():
    args = argparse.Namespace()
    args.client_id = 'client_id'
    args.client_secret = 'fake-secret'
    args.scopes = 'fake scopes'
    cfg = ConfigParser.ConfigParser()
    cfg.add_section('oauth2')
    cfg.set('oauth2', 'token_cache_base', '~/.coursera/')
    computed = oauth2.build_oauth2('my_app', args, cfg).token_cache_file
    assert '//' not in computed, 'Computed contained "//": %s' % computed
def test_compute_cache_filename():
    args = argparse.Namespace()
    args.client_id = 'client_id'
    args.client_secret = 'fake-secret'
    args.scopes = 'fake scopes'
    cfg = ConfigParser.ConfigParser()
    cfg.add_section('oauth2')
    cfg.set('oauth2', 'token_cache_base', '/tmp/cache')
    assert oauth2.build_oauth2('my_app', args, cfg)\
        .token_cache_file == '/tmp/cache/my_app_oauth2_cache.pickle'
Example #5
0
def get_clickstream_download_links(clickstream_download_links_request):
    """
    Return the download links for clickstream exports in a given scope.
    :param clickstream_download_links_request: ClickstreamDownloadLinksRequest
    """
    auth = oauth2.build_oauth2(app=RESEARCH_EXPORTS_APP).build_authorizer()
    response = requests.post(
        url=CLICKSTREAM_API,
        params=clickstream_download_links_request.to_url_params(),
        auth=auth)

    return response
Example #6
0
def post(export_request):
    """
    Creates a data export job using a formatted json request.
    :param export_request:
    :return export_request_with_metadata: [ExportRequestWithMetadata]
    """
    auth = oauth2.build_oauth2(app=RESEARCH_EXPORTS_APP).build_authorizer()
    response = requests.post(url=RESEARCH_EXPORTS_API,
                             json=export_request.to_json(),
                             auth=auth)

    return response
Example #7
0
def get_all():
    """
    Uses Coursera's Research Exports Resource to get all data export job
    requests created by a user. Limited to the 100 most recent requests.
    :return export_requests: [ExportRequestWithMetaData]
    """
    auth = oauth2.build_oauth2(app=RESEARCH_EXPORTS_APP).build_authorizer()
    response = requests.get(url=RESEARCH_EXPORTS_API,
                            auth=auth,
                            params={'q': 'my'})

    return response
def test_compute_cache_filname_expanded_path_overrides():
    args = argparse.Namespace()
    args.token_cache_file = '~/.coursera/override_cache.pickle'
    args.client_id = 'client_id'
    args.client_secret = 'fake-secret'
    args.scopes = 'fake scopes'
    cfg = ConfigParser.ConfigParser()
    cfg.add_section('oauth2')
    cfg.set('oauth2', 'token_cache_base', '~/.coursera')
    computed = oauth2.build_oauth2('my_app', args, cfg).token_cache_file
    assert '~' not in computed, 'Computed contained "~": %s' % computed
    assert 'override_cache.pickle' in computed, 'Computed was not overridden!'
Example #9
0
def get(export_job_id):
    """
    Use Coursera's Research Export Resource to get a data export job given an
    export job id.
    :param export_job_id:
    :return export_request_with_metadata: [ExportRequestWithMetaData]
    """
    auth = oauth2.build_oauth2(app=RESEARCH_EXPORTS_APP).build_authorizer()
    response = requests.get(url=requests.compat.urljoin(
        RESEARCH_EXPORTS_API, export_job_id),
                            auth=auth)

    return response
# этот скрипт отправляет запрос на формирование ссылок курсерой
import requests
from courseraoauth2client import oauth2

REQUEST_JSON = {
    "scope": {
        "typeName": "courseContext",
        "definition": {
            "courseId": "jC3H-47qEeWxTA6NLywNHw"
        }
    },
    "exportType": "RESEARCH_EVENTING",
    "schemaNames": ["course_grades"],
    "anonymityLevel": "HASHED_IDS_NO_PII",
    "statementOfPurpose": "Test",
    "interval": {
        "start": "2016-11-10",
        "end": "2016-12-10"
    }
}

url = "https://www.coursera.org/api/onDemandExports.v2"
auth = oauth2.build_oauth2(app='manage_research_exports').build_authorizer()
resp = requests.post(url, auth=auth, json=REQUEST_JSON)
print resp.json()