コード例 #1
0
 def test_masquerade_delete(self):
     canvas = Canvas(as_user='******')
     try:
         r = canvas._delete_resource('/fake_api')
     except DataFailureException as ex:
         self.assertEquals(ex.url,
                           '/fake_api?as_user_id=sis_user_id%3AABCDEF')
コード例 #2
0
    def test_has_masquerade(self, user='******'):
        canvas = Canvas(as_user=user)
        self.assertEquals(canvas._as_user, user)

        params = {}
        canvas._set_as_user(params)
        self.assertEquals(params, {'as_user_id': 'sis_user_id:%s' % user})
コード例 #3
0
    def test_no_masquerade(self):
        canvas = Canvas()
        self.assertEquals(canvas._as_user, None)

        params = {}
        canvas._set_as_user(params)
        self.assertEquals(len(params), 0)
コード例 #4
0
    def handle(self, *args, **options):
        self._canvas = Canvas()
        self._tools = ExternalTools()
        self._accounts = Accounts()
        self._courses = Courses()
        self._options = options

        csv.register_dialect("unix_newline", lineterminator="\n")
        self._writer = csv.writer(sys.stdout, dialect="unix_newline")

        self._headers = [
            'tool_name', 'tool_id', 'tool_type', 'account_name', 'account_id'
        ]

        if self._options['courses']:
            self._headers.append('course_name')
            self._headers.append('course_id')
            self._headers.append('term')

        if options['sessionless']:
            self._headers.append('sessionless url')

        if re.match(r'^\d+$', options['account_id']):
            account = self._accounts.get_account(options['account_id'])
        else:
            account = self._accounts.get_account_by_sis_id(
                options['account_id'])

        try:
            self.report_external_tools(account)

        except DataFailureException as err:
            if err.status == 404:
                print('Unknown Sub-Account \"%s\"' % (options['account_id']),
                      file=sys.stderr)
コード例 #5
0
 def test_valid_canvas_id(self):
     canvas = Canvas()
     self.assertEquals(canvas.valid_canvas_id(11), True)
     self.assertEquals(canvas.valid_canvas_id(111111111111), True)
     self.assertEquals(canvas.valid_canvas_id(1), False)
     self.assertEquals(canvas.valid_canvas_id('ab'), False)
     self.assertEquals(canvas.valid_canvas_id('11111'), True)
コード例 #6
0
    def test_params(self):
        canvas = Canvas()

        self.assertEquals(canvas._params(None), '')
        self.assertEquals(canvas._params({}), '')

        params = {'per_page': 100}
        self.assertEquals(canvas._params(params), '?per_page=100')

        params = {'per_page': 100, 'terms': ['2013-autumn', '2014-winter']}
        self.assertEquals(
            canvas._params(params),
            '?per_page=100&terms[]=2013-autumn&terms[]=2014-winter')

        params = {'per_page': 100, 'search_term': '19th Century Poets'}
        self.assertEquals(canvas._params(params),
                          '?per_page=100&search_term=19th%20Century%20Poets')
コード例 #7
0
 def test_sis_login_id(self):
     canvas = Canvas()
     self.assertEquals(canvas.sis_login_id('javerage'),
                       'sis_login_id%3Ajaverage')
コード例 #8
0
 def test_sis_user_id(self):
     canvas = Canvas()
     self.assertEquals(
         canvas.sis_user_id('123456ABCDEF123456ABCDEF123456AB'),
         'sis_user_id%3A123456ABCDEF123456ABCDEF123456AB')
コード例 #9
0
 def test_sis_section_id(self):
     canvas = Canvas()
     self.assertEquals(canvas.sis_section_id('2013-spring-ESS-101-AB'),
                       'sis_section_id%3A2013-spring-ESS-101-AB')
コード例 #10
0
 def test_sis_course_id(self):
     canvas = Canvas()
     self.assertEquals(canvas.sis_course_id('2013-spring-ESS-101-A'),
                       'sis_course_id%3A2013-spring-ESS-101-A')
コード例 #11
0
 def test_sis_account_id(self):
     canvas = Canvas()
     self.assertEquals(canvas.sis_account_id('abc:def'),
                       'sis_account_id%3Aabc%3Adef')
コード例 #12
0
def valid_canvas_id(canvas_id):
    return Canvas().valid_canvas_id(canvas_id)
コード例 #13
0
 def get_submissions_for_sis_course_id_and_quiz_id(self, sis_course_id,
                                                   quiz_id):
     course_id = self._sis_id(sis_course_id, sis_field="course")
     url = QUIZZES_API.format(course_id) + "/{}/submissions".format(quiz_id)
     return Canvas()._get_resource(url, data_key="quiz_submissions")
コード例 #14
0
class Command(BaseCommand):
    help = "Report externals tools in account"

    def add_arguments(self, parser):
        parser.add_argument(
            '-a',
            '--account',
            action='store',
            dest='account_id',
            default=default_account,
            help=('show external tools in account by id or '
                  'sis_id (default: {})').format(default_account))
        parser.add_argument('-r',
                            '--recurse',
                            action='store_true',
                            dest='recurse',
                            default=False,
                            help='recurse through subaccounts')
        parser.add_argument('-c',
                            '--courses',
                            action='store_true',
                            dest='courses',
                            default=False,
                            help='include account courses in report')
        parser.add_argument('-t',
                            '--term',
                            action='store',
                            dest='term',
                            default='',
                            help='include only courses in given term')
        parser.add_argument(
            '-s',
            '--sessionless-url',
            action='store_true',
            dest='sessionless',
            default=False,
            help='show sessionless url with each external tool')

    def handle(self, *args, **options):
        self._canvas = Canvas()
        self._tools = ExternalTools()
        self._accounts = Accounts()
        self._courses = Courses()
        self._options = options

        csv.register_dialect("unix_newline", lineterminator="\n")
        self._writer = csv.writer(sys.stdout, dialect="unix_newline")

        self._headers = [
            'tool_name', 'tool_id', 'tool_type', 'account_name', 'account_id'
        ]

        if self._options['courses']:
            self._headers.append('course_name')
            self._headers.append('course_id')
            self._headers.append('term')

        if options['sessionless']:
            self._headers.append('sessionless url')

        if re.match(r'^\d+$', options['account_id']):
            account = self._accounts.get_account(options['account_id'])
        else:
            account = self._accounts.get_account_by_sis_id(
                options['account_id'])

        try:
            self.report_external_tools(account)

        except DataFailureException as err:
            if err.status == 404:
                print('Unknown Sub-Account \"%s\"' % (options['account_id']),
                      file=sys.stderr)

    def report_external_tools(self, account):
        tools = self._tools.get_external_tools_in_account(account.account_id)
        self._print_tools(tools, account)

        if self._options['courses']:
            params = {
                "by_subaccounts": [account.account_id],
                "include": ["term"]
            }

            if self._options['term']:
                params['enrollment_term_id'] = self._canvas.get_term_by_sis_id(
                    self._options['term']).term_id

            courses = self._courses.get_published_courses_in_account(
                account.account_id, params=params)
            for course in courses:
                tools = self._tools.get_external_tools_in_course(
                    course.course_id)
                self._print_tools(tools, account, course)

        if self._options['recurse']:
            subaccounts = self._accounts.get_sub_accounts(account.account_id)
            for account in subaccounts:
                self.report_external_tools(account)

    def _print_tools(self, tools, account, course=None):
        if len(tools):
            if self._headers:
                self._writer.writerow(self._headers)
                self._headers = None

            for tool in tools:
                tool_types = []
                for tt in ['account', 'course', 'user']:
                    if tool.get("{}_navigation".format(tt)):
                        tool_types.append(tt)

                tool_type = ' & '.join(tool_types)
                line = [
                    tool['name'], tool['id'], tool_type, account.name,
                    account.account_id
                ]

                if self._options['courses']:
                    if course:
                        line.extend([
                            course.name, course.course_id,
                            course.term.name if course.term else ''
                        ])
                    else:
                        line.extend(['', '', ''])

                if self._options['sessionless']:
                    try:
                        tools = self._tools
                        url = tools.get_sessionless_launch_url_from_account(
                            tool['id'], account.account_id)
                        line.append(url['url'])
                    except DataFailureException as ex:
                        line.append('')

                self._writer.writerow(line)