예제 #1
0
    def test_download_multiple_files(self, requests_mock):
        path = self.path + '/spanish.sahara'
        category = FileTransferToken.FileInfo.Category.resources
        ftt = FileTransferTokenFactory(
            files=[
                FileInfoFactory(
                    category=FileTransferToken.FileInfo.Category.results),
                FileInfoFactory(category=category),
            ],
            download=True,
        )

        request = ConcentFileRequestFactory(
            file_path=path,
            file_transfer_token=ftt,
            file_category=category,
        )

        download_address = ftt.storage_cluster_address + 'download/' + \
            ftt.files[1].get('path')  # noqa pylint:disable=unsubscriptable-object

        self.cfs.download(request)

        requests_mock.assert_called_once()
        self.assertEqual(requests_mock.call_args[0], (download_address, ))
예제 #2
0
    def test_upload_multiple_files(self, requests_mock):
        path = self._init_uploaded_file('obsta.cles')
        category = FileTransferToken.FileInfo.Category.resources

        ftt = FileTransferTokenFactory(
            files=[
                FileInfoFactory(
                    category=FileTransferToken.FileInfo.Category.results),
                FileInfoFactory(path=path, category=category),
            ],
            upload=True,
        )

        request = ConcentFileRequestFactory(
            file_path=path,
            file_transfer_token=ftt,
            file_category=category,
        )

        self.cfs.upload(request)

        requests_mock.assert_called_once()

        _, kwargs = requests_mock.call_args
        concent_upload_path = kwargs.get('headers').get('Concent-Upload-Path')
        self.assertEqual(concent_upload_path, ftt.files[1].get('path'))  # noqa pylint:disable=unsubscriptable-object
예제 #3
0
 def test_transfer(self):
     category = FileTransferToken.FileInfo.Category.resources
     ftt = FileTransferTokenFactory()
     self.cfs.transfer('/less/important.txt', ftt, file_category=category)
     request = self.cfs._transfers.get()
     self.assertIsInstance(request, filetransfers.ConcentFileRequest)
     self.assertEqual(request.file_transfer_token, ftt)
     self.assertEqual(request.file_category, category)
예제 #4
0
 def test_run(self, process_mock):
     path = '/yeta/nother.file'
     ftt = FileTransferTokenFactory()
     self.cfs.transfer(path, ftt)
     self.cfs._run()
     process_mock.assert_called_once()
     request = process_mock.call_args[0][0]
     self.assertIsInstance(request, filetransfers.ConcentFileRequest)
     self.assertEqual(request.file_path, path)
     self.assertEqual(request.file_transfer_token, ftt)
예제 #5
0
    def setUp(self):
        self.message_timestamp = get_current_utc_timestamp()
        self.public_key = '85cZzVjahnRpUBwm0zlNnqTdYom1LF1P1WNShLg17cmhN2UssnPrCjHKTi5susO3wrr/q07eswumbL82b4HgOw=='
        self.download_token = FileTransferTokenFactory(
            token_expiration_deadline=self.message_timestamp + 3600,
            storage_cluster_address='http://devel.concent.golem.network/',
            authorized_client_public_key=settings.CONCENT_PUBLIC_KEY,
            operation=FileTransferToken.Operation.download,
        )
        self.download_token.files[0][
            'path'] = 'blender/benchmark/test_task/scene-Helicopter-27-cycles.blend'
        self.download_token.files[0][
            'checksum'] = 'sha1:95a0f391c7ad86686ab1366bcd519ba5ab3cce89'

        self.header_concent_auth = self._create_client_auth_message_as_header(
            settings.CONCENT_PRIVATE_KEY,
            settings.CONCENT_PUBLIC_KEY,
        )
예제 #6
0
    def test_upload(self, requests_mock):
        path = self._init_uploaded_file('something.good')

        ftt = FileTransferTokenFactory(upload=True)

        request = ConcentFileRequestFactory(
            file_path=path,
            file_transfer_token=ftt,
        )

        upload_address = ftt.storage_cluster_address + 'upload/'
        headers = self._mock_get_auth_headers(ftt)
        headers['Concent-Upload-Path'] = ftt.files[0].get('path')  # noqa pylint:disable=unsubscriptable-object
        headers['Content-Type'] = 'application/octet-stream'

        self.cfs.upload(request)

        requests_mock.assert_called_once()

        args, kwargs = requests_mock.call_args
        self.assertEqual(args, (upload_address, ))
        self.assertIsNotNone(kwargs.get('headers').pop('Concent-Auth'))
        self.assertEqual(kwargs.get('headers'), headers)
예제 #7
0
    def test_download(self, requests_mock):
        path = self.path + '/gotwell.soon'

        ftt = FileTransferTokenFactory(download=True)

        request = ConcentFileRequestFactory(
            file_path=path,
            file_transfer_token=ftt,
        )

        download_address = ftt.storage_cluster_address + 'download/' + \
            ftt.files[0].get('path')  # noqa pylint:disable=unsubscriptable-object

        self.cfs.download(request)

        requests_mock.assert_called_once()

        args, kwargs = requests_mock.call_args
        self.assertEqual(args, (download_address, ))
        self.assertIsNotNone(kwargs.get('headers').pop('Concent-Auth'))
        self.assertEqual(
            kwargs.get('headers'),
            self._mock_get_auth_headers(ftt)
        )
예제 #8
0
 def test_transfer_category_default(self):
     ftt = FileTransferTokenFactory()
     self.cfs.transfer('/less/important.txt', ftt)
     request = self.cfs._transfers.get()
     self.assertEqual(request.file_category,
                      FileTransferToken.FileInfo.Category.results)
예제 #9
0
 def test_transfer_unstarted(self, log_mock):
     self.cfs.transfer('/crucial/file.dat', FileTransferTokenFactory())
     log_mock.assert_called_once()
     self.assertIn('not started', log_mock.call_args[0][0])
예제 #10
0
 def test_process_download(self, download_mock):
     ftt = FileTransferTokenFactory(download=True)
     request = ConcentFileRequestFactory(file_transfer_token=ftt)
     self.cfs.process(request)
     download_mock.assert_called_once_with(request)