예제 #1
0
    def test_download_file(self, logger_patch, is_file_patch,
                           get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {
            "user_id": self.dummy_uid,
            "file_path": self.dummy_file_path,
            "file_name": self.dummy_file_name
        }
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '1234'
        self.__request.registry.settings['mode'] = 'prod'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 200)

        headers = response.headers

        self.assertEqual(len(headers), 3)
        self.assertEqual(headers['X-Sendfile'], self.dummy_file_path)
        self.assertEqual(headers['Content-Type'], '')
        self.assertEqual(headers['Content-Disposition'],
                         'attachment; filename=ActualName.zip')
        logger_patch.assert_called_once_with(
            'File %s was successfully downloaded', 'tmp/filename.zip')
    def test_download_file_not_registered(self, logger_patch, is_file_patch, get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = None
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with('No file record is registered with requested id %s', '12345')
    def test_download_file_still_processing(self, logger_patch, is_file_patch, get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {"user_id": self.dummy_uid, "file_path": None, "file_name": None}
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with('File with registration id %s is not yet available', '12345')
    def test_download_file_not_on_disk(self, logger_patch, is_file_patch, get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {"user_id": self.dummy_uid, "file_path": self.dummy_file_path,
                                           "file_name": self.dummy_file_name}
        is_file_patch.return_value = False
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with('File %s is registered, but does not exist on disk', 'tmp/filename.zip')
    def test_download_file_not_owner(self, logger_patch, is_file_patch, get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        reg_user_id = 'dduck'
        get_reg_info_patch.return_value = {"user_id": reg_user_id, "file_path": self.dummy_file_path,
                                           "file_name": self.dummy_file_name}
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with('User %s is not owner of the file with registration id %s', 'bbunny', '12345')
예제 #6
0
    def test_download_file_not_registered(self, logger_patch, is_file_patch,
                                          get_reg_info_patch,
                                          auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = None
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with(
            'No file record is registered with requested id %s', '12345')
예제 #7
0
    def test_download_file_not_on_disk(self, logger_patch, is_file_patch,
                                       get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {
            "user_id": self.dummy_uid,
            "file_path": self.dummy_file_path,
            "file_name": self.dummy_file_name
        }
        is_file_patch.return_value = False
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with(
            'File %s is registered, but does not exist on disk',
            'tmp/filename.zip')
예제 #8
0
    def test_download_file_still_processing(self, logger_patch, is_file_patch,
                                            get_reg_info_patch,
                                            auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {
            "user_id": self.dummy_uid,
            "file_path": None,
            "file_name": None
        }
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with(
            'File with registration id %s is not yet available', '12345')
예제 #9
0
    def test_download_file_not_owner(self, logger_patch, is_file_patch,
                                     get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        reg_user_id = 'dduck'
        get_reg_info_patch.return_value = {
            "user_id": reg_user_id,
            "file_path": self.dummy_file_path,
            "file_name": self.dummy_file_name
        }
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '12345'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 404)
        logger_patch.assert_called_once_with(
            'User %s is not owner of the file with registration id %s',
            'bbunny', '12345')
    def test_download_file(self, logger_patch, is_file_patch, get_reg_info_patch, auth_userid_patch):
        auth_userid_patch.return_value = self.dummy_user
        get_reg_info_patch.return_value = {"user_id": self.dummy_uid, "file_path": self.dummy_file_path,
                                           "file_name": self.dummy_file_name}
        is_file_patch.return_value = True
        logger_patch.return_value = None

        self.__request.method = 'GET'
        self.__request.matchdict['reg_id'] = '1234'
        self.__request.registry.settings['mode'] = 'prod'

        response = download_file(None, self.__request)

        self.assertEqual(response.status_code, 200)

        headers = response.headers

        self.assertEqual(len(headers), 3)
        self.assertEqual(headers['X-Sendfile'], self.dummy_file_path)
        self.assertEqual(headers['Content-Type'], '')
        self.assertEqual(headers['Content-Disposition'], 'attachment; filename=ActualName.zip')
        logger_patch.assert_called_once_with('File %s was successfully downloaded', 'tmp/filename.zip')