예제 #1
0
 def test_main_task_upload_file_and_folder_failed(self, get_files_mock,
                                                  upload_mock):
     get_files_mock.return_value = subprocess.Popen(['exit 0'], shell=True)
     upload_mock.return_value = {'fail_file': 5, 'fail_folder': 2}
     tmp_path = 'tmp/restfulapi/%s_12345' % self.user._id
     osf_cookie = 'chocolate_cookie'
     data = {
         'url': VALID_URL,
         'recursive': True,
         'interval': True,
         'intervalValue': '30',
         'pid': self.project._id,
         'folderId': '1234567890abcdef'
     }
     request_info = {
         'node_id': self.project._id,
         'pid': self.project._id,
         'uid': self.user._id,
     }
     with pytest.raises(RuntimeError) as ex:
         return_value = views.main_task(osf_cookie, data, request_info)
     get_files_mock.delay.assert_called()
     upload_mock.delay.assert_called()
     assert 'Failed to upload 5 file(s) and 2 folder(s) to storage.' in str(
         ex)
예제 #2
0
 def test_main_task_create_tmp_folder_failed(self, create_tmp_folder_mock):
     create_tmp_folder_mock.return_value = 0
     tmp_path = 'tmp/restfulapi/%s_12345' % self.user._id
     osf_cookie = 'chocolate_cookie'
     data = {
         'url': VALID_URL,
         'recursive': True,
         'interval': True,
         'intervalValue': '30',
         'pid': self.project._id,
         'folderId': '1234567890abcdef'
     }
     request_info = {
         'node_id': self.project._id,
         'pid': self.project._id,
         'uid': self.user._id,
     }
     with pytest.raises(OSError) as ex:
         return_value = views.main_task(osf_cookie, data, request_info)
     create_tmp_folder_mock.delay.assert_called()
     assert 'Could not create temporary folder.' in str(ex)
예제 #3
0
    def test_succeed_task_with_options(self, get_files_mock):
        tmp_path = 'tmp/restfulapi/%s_12345' % self.user._id
        osf_cookie = 'chocolate_cookie'
        data = {
            'url': VALID_URL,
            'recursive': True,
            'interval': True,
            'intervalValue': '30',
            'pid': self.project._id,
            'folderId': '1234567890abcdef'
        }
        get_files_mock.return_value = subprocess.Popen(['exit 0'], shell=True)
        request_info = {
            'node_id': self.project._id,
            'pid': self.project._id,
            'uid': self.user._id,
        }
        return_value = views.main_task(osf_cookie, data, request_info)

        get_files_mock.delay.assert_called()
        assert return_value
예제 #4
0
    def test_main_task_wget_failed(self, get_files_mock):
        tmp_path = 'tmp/restfulapi/%s_12345' % self.user._id
        osf_cookie = 'chocolate_cookie'
        data = {
            'url': VALID_URL,
            'recursive': True,
            'interval': True,
            'intervalValue': '30',
            'pid': self.project._id,
            'folderId': '1234567890abcdef'
        }
        get_files_mock.return_value = subprocess.Popen(['exit 1'], shell=True)
        request_info = {
            'node_id': self.project._id,
            'pid': self.project._id,
            'uid': self.user._id,
        }
        with pytest.raises(RuntimeError) as ex:
            return_value = views.main_task(osf_cookie, data, request_info)

        get_files_mock.delay.assert_called()
        assert 'wget command returned a non-success code.' in str(ex)