def test_lti_auth3(self): """ Test LTI access to courseware """ path = "/_lti/course/%s/structure" % self.cname host = "localhost:6010" url = "http://%s%s" % (host, path) ltic = lti.LTI_Consumer(lti_url=url, consumer_key=self.ckey, secret=self.secret) def retform(): return ltic.lti_context cgi.FieldStorage = retform # monkey patch env = { "PATH_INFO": path, "wsgi.url_scheme": "http", "HTTP_HOST": host, "REQUEST_URI": path, "REQUEST_METHOD": "POST", } status, retinfo, msg = dispatch.main(env) assert status[0] == "200" assert "Page Specification and Loading" in msg.decode("utf8")
def application(environ, start_response): """ WSGI application interface for CAT-SOOP, as specified in [PEP 3333](http://www.python.org/dev/peps/pep-3333/). """ status, headers, content = dispatch.main(environ) start_response("%s %s" % (status[0], status[1]), list(headers.items())) if isinstance(content, (str, bytes)): return [_ensure_bytes(content)] else: return (_ensure_bytes(i) for i in content)
def test_lti_auth2(self): """ Test successful authentication with LTI protocol """ path = "/_lti/foo" host = "localhost:6010" url = "http://%s%s" % (host, path) ltic = lti.LTI_Consumer( lti_url=url, consumer_key=self.ckey, secret=self.secret, username="******", ) def retform(): return ltic.lti_context cgi.FieldStorage = retform # monkey patch env = { "PATH_INFO": path, "wsgi.url_scheme": "http", "HTTP_HOST": host, "REQUEST_URI": path, "REQUEST_METHOD": "POST", } status, retinfo, msg = dispatch.main(env) assert status[0] == "200" assert "Hello LTI" in msg context = dispatch.main(env, return_context=True) cui = context["cs_user_info"] assert cui["username"] == "lti_anltiuser" # ensure lti_username_prefix can be set to empty string self.cs_lti_config["lti_username_prefix"] = "" context = dispatch.main(env, return_context=True) cui = context["cs_user_info"] assert cui["username"] == "anltiuser"
def test_lti_auth2(self): """ Test successful authentication with LTI protocol """ path = "/_lti/foo" host = "localhost:6010" url = "http://%s%s" % (host, path) ltic = lti.LTI_Consumer(lti_url=url, consumer_key=self.ckey, secret=self.secret) def retform(): return ltic.lti_context cgi.FieldStorage = retform # monkey patch env = { "PATH_INFO": path, "wsgi.url_scheme": "http", "HTTP_HOST": host, "REQUEST_URI": path, "REQUEST_METHOD": "POST", } status, retinfo, msg = dispatch.main(env) assert status[0] == "200" assert "Hello LTI" in msg
def test_context1(self): env = {"PATH_INFO": "/%s/structure" % self.cname} context = dispatch.main(env, return_context=True) cui = context["cs_user_info"] print("cs_user_info=%s" % context['cs_user_info']) assert cui["role"] == "Guest"
def test_static1(self): env = {"PATH_INFO": "/%s/structure" % self.cname} status, retinfo, msg = dispatch.main(env) msg = msg.decode("utf8") assert status[0] == "200" assert "6.SAMP" in msg
def test_question_submit(self): ''' Test submission to an asynchronousely graded problem, and the grading of that problem via the queue. The checker is explicitly called after submission. ''' print("") print("") print( "-----------------------------------------------------------------------------" ) print("Starting test_question_submit test") # csqueue.clear_all_queues(self.context) old_gliu = dispatch.auth.get_logged_in_user dispatch.auth.get_logged_in_user = self.get_logged_in_user api_token = '123' the_path = "/%s/questions" % self.cname qid = "q000005" form_data = { 'action': 'submit', 'names': json.dumps([qid]), 'api_token': api_token, 'data': json.dumps({"q000005": "[1,2,3,4]"}), } env = { "PATH_INFO": the_path, 'REMOTE_ADDR': 'dummy_ip', } status, retinfo, msg = dispatch.main(env, form_data=form_data) # print("msg=", msg) try: ret = json.loads(msg) except Exception as err: print("Failed to parse result, err=%s" % str(err)) raise qret = ret[qid] print("qret=%s" % qret) assert "error_msg " not in qret assert 'message' in qret # get queued entry and run checker on it job = csqueue.get_oldest_from_queue(self.context) print("job=%s" % job) assert 'path' in job assert 'username' in job assert job['names'] assert job['action'] == 'submit' assert job is not None id_ = job['magic'] print("Job-id=%s" % id_) grader.do_check(job) # check for result result = csqueue.get_results(id_) print("result=%s" % json.dumps(result, indent=4)) assert result assert 'All of the numbers must be in the range' in result['response'] assert result['score'] == 0.0 # check problemstate log logpath = (job["username"], job["path"], "problemstate") print("logpath=", logpath) data = cslog.most_recent(*logpath, {}, lock=False) print("problemstate=", data) assert data assert "timestamp" in data assert "last_submit_time" in data assert data['checker_ids'][qid] == id_ dispatch.auth.get_logged_in_user = old_gliu
def test_question_submit_and_lti_grade(self): ''' Test submission to an asynchronousely graded problem, and the submission of the grade to LTI ''' print("") print("") print( "-----------------------------------------------------------------------------" ) print("Starting LTI grade submission test") old_gliu = dispatch.auth.get_logged_in_user dispatch.auth.get_logged_in_user = self.get_logged_in_user class lti_handler: def __init__(self, parent): self.parent = parent self.have_data = True self.lti_data = "foo" def send_outcome(self, aggregate_score_fract): print("LTI.send_outcome: set aggregate_score_fract=%s" % aggregate_score_fract) self.parent.aggregate_score_fract = aggregate_score_fract self.context['cs_lti_config'] = {'foo': 1} def lti4cs_response(context, lti_data): return lti_handler(self) gll = grader.lti.lti4cs_response grader.lti.lti4cs_response = lti4cs_response api_token = '123' the_path = "/%s/questions" % self.cname qid = "q000005" form_data = { 'action': 'submit', 'names': json.dumps([qid]), 'api_token': api_token, 'data': json.dumps({"q000005": "[0.11, 0.2, 0.3, 0.4, 0.5]"}), } env = { "PATH_INFO": the_path, 'REMOTE_ADDR': 'dummy_ip', } status, retinfo, msg = dispatch.main(env, form_data=form_data) job = csqueue.get_oldest_from_queue(self.context) job['lti_data'] = {'lis_outcome_service_url': 'dummy_url'} id_ = job['magic'] print("Job-id=%s" % id_) grader.do_check(job) # check for result result = csqueue.get_results(id_) print("result=%s" % json.dumps(result, indent=4)) assert result assert self.aggregate_score_fract == 0 grader.lti.lti4cs_response = gll self.context.pop("cs_lti_config") dispatch.auth.get_logged_in_user = old_gliu
def test_lti_auth1(self): env = {"PATH_INFO": "/_lti/%s/structure" % self.cname} status, retinfo, msg = dispatch.main(env) assert status[0] == "200" assert "LTI verification failed" in msg