def test_upload_fail(self, m): requires = {"uploader": ["upload_fail", "upload_response_fail"]} register_uris(requires, m) uploader = Uploader(self.requester, "upload_response_fail", self.file) result = uploader.start() self.assertFalse(result[0]) self.assertIsInstance(result[1], dict) self.assertNotIn("url", result[1])
def test_start_path(self, m): requires = {"uploader": ["upload_response", "upload_response_upload_url"]} register_uris(requires, m) uploader = Uploader(self.requester, "upload_response", self.filename) result = uploader.start() self.assertTrue(result[0]) self.assertIsInstance(result[1], dict) self.assertIn("url", result[1])
def test_upload_fail(self, m): requires = {'uploader': ['upload_fail', 'upload_response_fail']} register_uris(requires, m) uploader = Uploader(self.requester, 'upload_response_fail', self.file) result = uploader.start() self.assertFalse(result[0]) self.assertIsInstance(result[1], dict) self.assertNotIn('url', result[1])
def test_start_path(self, m): requires = { 'uploader': ['upload_response', 'upload_response_upload_url'] } register_uris(requires, m) uploader = Uploader(self.requester, 'upload_response', self.filename) result = uploader.start() self.assertTrue(result[0]) self.assertIsInstance(result[1], dict) self.assertIn('url', result[1])
def test_enrollment_created(self, prepare_canvas): # create file self.file = open(self.filename, "w+") uploader = Uploader(self.requester, "upload_response", self.file) result = uploader.start() assert (result[0]) assert isinstance(result[1], dict) assert "url" in result[1] # close file(s) self.file.close()
def upload_file(file_path): f = open(file_path, "rb") tmp_file = None tmp_dir = None if args.strip is not None and file_path.endswith(".java"): f = open(file_path, "r", encoding="utf-8") lines = f.readlines() i = -1 for line in lines: i += 1 if line.strip().startswith("package "): lines[i] = "" continue if line.strip().startswith("import " + args.strip): lines[i] = "" continue file_name = ntpath.basename(file_path) tmp_dir = tempfile.mkdtemp() tmp_file = tmp_dir + "/" + file_name f = open(tmp_file, "w", encoding="utf-8") f.writelines(lines) f.close() f = open(tmp_file, "r", encoding="utf-8") uploader = Uploader( requester, "/api/v1/courses/" + str(args.course) + "/assignments/" + str(args.assignment) + "/submissions/self/files", f) response = uploader.start() f.close() if tmp_file is not None and tmp_dir is not None: unlink(tmp_file) rmdir(tmp_dir) if not response[0]: eprint("😥 One of the files (" + file_path + ") could not be uploaded.") exit(1) return response[1]