Пример #1
0
    def test_upload_start_new_files(self):
        """ Tests upload_start on new files """
        import os

        request = self.factory.post(
            '/plupload/',
            {'model': 'test.IssueSubmission', 'pk': 2, 'name': 'test.png'}
        )

        with mock.patch('os.makedirs', mock.MagicMock(spec=os.makedirs)):

            upload_file(request)

            resumable_file_count = ResumableFile.objects.filter(
                path=path_for_upload(
                    "test.IssueSubmission",
                    "2",
                    "test.png",
                ),
                status=ResumableFileStatus.NEW
            ).count()

            self.assertEquals(
                resumable_file_count,
                1,
                "A ResumableFile should have been created"
            )
Пример #2
0
    def test_upload_error(self):
        """ Test that posting to upload_error update the model """
        import os

        request = self.factory.post(
            '/plupload/',
            {'model': 'test.IssueSubmission', 'pk': 1, 'name': 'test.png'}
        )

        with mock.patch('os.makedirs', mock.MagicMock(spec=os.makedirs)):
            upload_file(request)

        request = self.factory.post(
            'plupload/upload_error',
            {'model': 'test.IssueSubmission', 'pk': 1, 'name': 'test.png'}
        )

        response = upload_error(request)
        resumable_file_count = ResumableFile.objects.filter(
            path=path_for_upload(
                "test.IssueSubmission",
                "1",
                "test.png",
            ),
            status=ResumableFileStatus.ERROR
        ).count()

        self.assertEquals(
            resumable_file_count,
            1,
            "The ResumableFile should have failed"
        )
Пример #3
0
 def test_path_for_upload(self):
     """ Test that the upload paths are set properly """
     self.assertEquals(
         path_for_upload(
             'test.IssueSubmission',
             '1',
             'david.png'
         ),
         '/tmp/test.IssueSubmission/1/david.png'
     )
Пример #4
0
    def setUp(self):

        # self.sample_model.save()

        self.factory = RequestFactory()

        self.sample_file = ResumableFile(
            pk=2,
            path=path_for_upload(
                "IssueSubmission",
                "2",
                "test.png"
            ),
            status=ResumableFileStatus.NEW
        ).save()
Пример #5
0
    def test_create_file(self):
        """ Test that files are created when no chunk is sent """
        request = self.factory.post(
            '/plupload/',
            {
                'model': 'test.IssueSubmission',
                'pk': 1,
                'name': 'test.png',
                "chunk": 0
            }
        )

        request.FILES['file'] = mock.MagicMock(spec=UploadedFile)

        with mock.patch("builtins.open", mock.MagicMock()) as mock_file:
            upload_file(request)

        mock_file.assert_called_once_with(
            path_for_upload('test.IssueSubmission', '1', 'test.png'),
            'wb'
        )