Exemple #1
0
 def test_download_file(self, m):
     register_uris({"file": ["file_download"]}, m)
     try:
         self.file.download("canvasapi_file_download_test.txt")
         self.assertTrue(isfile("canvasapi_file_download_test.txt"))
         with open("canvasapi_file_download_test.txt") as downloaded_file:
             self.assertEqual(downloaded_file.read(), '"file contents are here"')
     finally:
         cleanup_file("canvasapi_file_download_test.txt")
Exemple #2
0
 def test_download_file(self, m):
     register_uris({'file': ['file_download']}, m)
     try:
         self.file.download('canvasapi_file_download_test.txt')
         self.assertTrue(isfile('canvasapi_file_download_test.txt'))
         with open('canvasapi_file_download_test.txt') as downloaded_file:
             self.assertEqual(downloaded_file.read(),
                              '"file contents are here"')
     finally:
         cleanup_file('canvasapi_file_download_test.txt')
Exemple #3
0
    def test_file_or_path_file(self, m):
        filename = "testfile_file_or_path_file_{}".format(uuid.uuid4().hex)

        try:
            # create file and pass it in directly
            with open(filename, "w+") as file:
                handler, is_path = file_or_path(file)

                self.assertFalse(is_path)
        finally:
            cleanup_file(filename)
Exemple #4
0
    def test_upload(self, m):
        register_uris({'group': ['upload', 'upload_final']}, m)

        filename = 'testfile_group_%s' % uuid.uuid4().hex
        with open(filename, 'w+') as file:
            response = self.group.upload(file)
        self.assertTrue(response[0])
        self.assertIsInstance(response[1], dict)
        self.assertIn('url', response[1])

        cleanup_file(filename)
Exemple #5
0
    def test_upload(self, m):
        register_uris({"group": ["upload", "upload_final"]}, m)

        filename = "testfile_group_{}".format(uuid.uuid4().hex)
        try:
            with open(filename, "w+") as file:
                response = self.group.upload(file)
            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn("url", response[1])
        finally:
            cleanup_file(filename)
Exemple #6
0
    def test_upload_comment(self, m):
        register_uris(
            {'submission': ['upload_comment', 'upload_comment_final']}, m)

        filename = 'testfile_submission_%s' % uuid.uuid4().hex
        with open(filename, 'w+') as file:
            response = self.submission_course.upload_comment(file)

        self.assertTrue(response[0])
        self.assertIsInstance(response[1], dict)
        self.assertIn('url', response[1])

        cleanup_file(filename)
Exemple #7
0
    def test_submit_file_upload_failure(self, m):
        register_uris({"assignment": ["submit", "upload", "upload_fail"]}, m)

        filename = "testfile_assignment_{}".format(uuid.uuid4().hex)

        try:
            with open(filename, "w+") as file:
                sub_type = "online_upload"
                sub_dict = {"submission_type": sub_type}
                with self.assertRaises(CanvasException):
                    self.assignment.submit(sub_dict, file)
        finally:
            cleanup_file(filename)
    def test_submit_file_upload_failure(self, m):
        register_uris({'assignment': ['submit', 'upload', 'upload_fail']}, m)

        filename = 'testfile_assignment_{}'.format(uuid.uuid4().hex)

        try:
            with open(filename, 'w+') as file:
                sub_type = "online_upload"
                sub_dict = {'submission_type': sub_type}
                with self.assertRaises(CanvasException):
                    self.assignment.submit(sub_dict, file)
        finally:
            cleanup_file(filename)
Exemple #9
0
    def test_upload(self, m):
        register_uris({'folder': ['upload', 'upload_final']}, m)

        filename = 'testfile_course_{}'.format(uuid.uuid4().hex)

        try:
            with open(filename, 'w+') as file:
                response = self.folder.upload(file)
            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn('url', response[1])
        finally:
            cleanup_file(filename)
Exemple #10
0
    def test_upload_to_submission_self(self, m):
        register_uris({"assignment": ["upload", "upload_final"]}, m)

        filename = "testfile_assignment_{}".format(uuid.uuid4().hex)

        try:
            with open(filename, "w+") as file:
                response = self.assignment.upload_to_submission(file)

            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn("url", response[1])
        finally:
            cleanup_file(filename)
Exemple #11
0
    def test_upload_to_submission_self(self, m):
        register_uris({'assignment': ['upload', 'upload_final']}, m)

        filename = 'testfile_assignment_{}'.format(uuid.uuid4().hex)

        try:
            with open(filename, 'w+') as file:
                response = self.assignment.upload_to_submission(file)

            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn('url', response[1])
        finally:
            cleanup_file(filename)
Exemple #12
0
    def test_file_or_path_valid_path(self, m):
        filename = "testfile_file_or_path_valid_path_{}".format(uuid.uuid4().hex)

        try:
            # create file and immediately close it
            open(filename, "w+").close()

            handler, is_path = file_or_path(filename)
            self.assertTrue(is_path)

            # close re-opened file
            handler.close()
        finally:
            cleanup_file(filename)
Exemple #13
0
    def test_upload_comment(self, m):
        register_uris(
            {"submission": ["upload_comment", "upload_comment_final", "edit"]},
            m)

        filename = "testfile_submission_{}".format(uuid.uuid4().hex)

        try:
            with open(filename, "w+") as file:
                response = self.submission_course.upload_comment(file)

            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn("url", response[1])
        finally:
            cleanup_file(filename)
Exemple #14
0
    def test_submit_file_pathlib(self, m):
        register_uris({"assignment": ["submit", "upload", "upload_final"]}, m)

        filename = Path("testfile_assignment_{}".format(uuid.uuid4().hex))
        filename.write_bytes(b"test data")

        try:
            sub_type = "online_upload"
            sub_dict = {"submission_type": sub_type}
            submission = self.assignment.submit(sub_dict, filename)

            self.assertIsInstance(submission, Submission)
            self.assertTrue(hasattr(submission, "submission_type"))
            self.assertEqual(submission.submission_type, sub_type)

        finally:
            cleanup_file(filename)
Exemple #15
0
    def test_submit_file(self, m):
        register_uris({"assignment": ["submit", "upload", "upload_final"]}, m)

        filename = "testfile_assignment_{}".format(uuid.uuid4().hex)

        try:
            with open(filename, "w+") as file:
                sub_type = "online_upload"
                sub_dict = {"submission_type": sub_type}
                submission = self.assignment.submit(sub_dict, file)

            self.assertIsInstance(submission, Submission)
            self.assertTrue(hasattr(submission, "submission_type"))
            self.assertEqual(submission.submission_type, sub_type)

        finally:
            cleanup_file(filename)
Exemple #16
0
    def test_submit_file(self, m):
        register_uris({'assignment': ['submit', 'upload', 'upload_final']}, m)

        filename = 'testfile_assignment_{}'.format(uuid.uuid4().hex)

        try:
            with open(filename, 'w+') as file:
                sub_type = "online_upload"
                sub_dict = {'submission_type': sub_type}
                submission = self.assignment.submit(sub_dict, file)

            self.assertIsInstance(submission, Submission)
            self.assertTrue(hasattr(submission, 'submission_type'))
            self.assertEqual(submission.submission_type, sub_type)

        finally:
            cleanup_file(filename)
Exemple #17
0
    def test_upload_comment_section(self, m):
        register_uris(
            {
                'submission': [
                    'upload_comment',
                    'upload_comment_final',
                    'edit',
                ]
            }, m)

        filename = 'testfile_submission_{}'.format(uuid.uuid4().hex)

        try:
            with open(filename, 'w+') as file:
                response = self.submission_section.upload_comment(file)

            self.assertTrue(response[0])
            self.assertIsInstance(response[1], dict)
            self.assertIn('url', response[1])
        finally:
            cleanup_file(filename)
Exemple #18
0
 def tearDown(self):
     self.file.close()
     cleanup_file(self.filename)