Пример #1
0
    def test_retries_on_5xx(self):
        self.mock_get.side_effect = HTTPError(response=FakeResponse(503))

        api = CanvasAPI("test token", "mst.instructure.com")
        with self.assertRaises(HTTPError):
            api.get_instructor_courses()

        self.assertEqual(5, self.mock_get.call_count)
Пример #2
0
    def test_failed_dns(self):
        self.mock_get.side_effect = HTTPError("Name or service not known")

        api = CanvasAPI("test token", "mst.instructure.com")

        with self.assertRaises(NameResolutionFailed):
            api.get_instructor_courses()

        with self.assertRaises(NameResolutionFailed):
            api.get_course_students(420)
Пример #3
0
def print_canvas_courses(conf, _):
    """Show a list of current teacher's courses from Canvas via the API.
    """
    if 'canvas-token' not in conf:
        logger.error(
            "canvas-token configuration is missing! Please set the Canvas API access "
            "token before attempting to use Canvas API functionality")
        print("Canvas course listing failed: missing Canvas API access token.")
        return

    canvas = CanvasAPI(conf["canvas-token"], conf["canvas-host"])

    try:
        courses = canvas.get_instructor_courses()
    except AuthenticationFailed as e:
        logger.debug(e)
        logger.error(
            "Canvas authentication failed. Is your token missing or expired?")
        return

    if not courses:
        print("No courses found where current user is a teacher.")
        return

    output = PrettyTable(["#", "ID", "Name"])
    output.align["Name"] = "l"

    for ix, c in enumerate(sorted(courses, key=lambda c: c['id'],
                                  reverse=True)):
        output.add_row((ix + 1, c['id'], c['name']))

    print(output)
Пример #4
0
def print_canvas_courses(args):
    """Show a list of current teacher's courses from Canvas via the API.
    """

    g = Grader(args.path)
    if 'canvas-token' not in g.config:
        logger.error(
            "canvas-token configuration is missing! Please set the Canvas API access "
            "token before attempting to use Canvas API functionality")
        print("Canvas course listing failed: missing Canvas API access token.")
        return

    canvas = CanvasAPI(g.config["canvas-token"], g.config["canvas-host"])

    courses = canvas.get_instructor_courses()

    if not courses:
        print("No courses found where current user is a teacher.")
        return

    output = PrettyTable(["#", "ID", "Name"])
    output.align["Name"] = "l"

    for ix, c in enumerate(sorted(courses, key=lambda c: c['id'],
                                  reverse=True)):
        output.add_row((ix + 1, c['id'], c['name']))

    print(output)
Пример #5
0
    def test_courses_auth_failure(self):
        self.mock_get.side_effect = HTTPError(response=FakeResponse(401))

        api = CanvasAPI("test token", "mst.instructure.com")
        with self.assertRaises(AuthenticationFailed):
            api.get_instructor_courses()