예제 #1
0
    def set_url(_file,
                service,
                avoid_produce_queue=False,
                validation='success'):
        file_name = uuid.uuid4().hex

        file_path = s3_storage.write(_file, s3_storage.QUARANTINE, file_name)

        values = {
            'account': app.DUMMY_VALUES['account'],
            'principal': app.DUMMY_VALUES['principal'],
            'validation': validation,
            'payload_id': file_name,
            'size': 100,
            'service': service,
            'url': file_path
        }

        if not avoid_produce_queue:
            produce_queue_mocked.append({
                'topic': 'platform.upload.' + service,
                'msg': values
            })

        return values
예제 #2
0
    def test_write(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex

        url = s3_storage.write(local_file, s3_storage.QUARANTINE, key_name)

        assert url is not None
        assert isinstance(url, str)
        assert s3_storage.QUARANTINE in url
예제 #3
0
    def test_write(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex

        url = s3_storage.write(local_file, s3_storage.PERM, key_name,
                               config.DUMMY_VALUES['account'], 'curl/7.61.1')

        assert url is not None
        assert isinstance(url, str)
        assert s3_storage.PERM in url
예제 #4
0
    def test_ls(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex
        file_url = s3_storage.write(local_file, s3_storage.QUARANTINE,
                                    key_name)

        ls_response = s3_storage.ls(s3_storage.QUARANTINE, key_name)

        assert file_url is not None
        assert isinstance(ls_response, dict)

        assert ls_response['ContentLength'] == os.stat(local_file).st_size
        assert ls_response['ResponseMetadata']['HTTPStatusCode'] == 200
예제 #5
0
    def test_ls(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex
        file_url = s3_storage.write(local_file, s3_storage.PERM, key_name,
                                    config.DUMMY_VALUES['account'],
                                    'curl/7.61.1')

        ls_response = s3_storage.ls(s3_storage.PERM, key_name)

        assert file_url is not None
        assert isinstance(ls_response, dict)

        assert ls_response['ContentLength'] == len(local_file)
        assert ls_response['ResponseMetadata']['HTTPStatusCode'] == 200
예제 #6
0
    def test_copy(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex

        write_file_path = s3_storage.write(local_file, s3_storage.QUARANTINE,
                                           key_name)
        copy_file_path = s3_storage.copy(s3_storage.QUARANTINE,
                                         s3_storage.PERM, key_name)

        def _get_key(r):
            k = r.split('/')[3]
            return k[:k.find('?')]

        assert isinstance(write_file_path, str)
        assert s3_storage.QUARANTINE in write_file_path
        assert copy_file_path is not None
        assert s3_storage.PERM in copy_file_path
        assert copy_file_path != write_file_path

        write_key, copy_key = _get_key(write_file_path), _get_key(
            copy_file_path)
        assert write_key == copy_key
예제 #7
0
    def test_copy(self, local_file, s3_mocked):
        key_name = uuid.uuid4().hex

        write_file_path = s3_storage.write(local_file, s3_storage.PERM,
                                           key_name,
                                           config.DUMMY_VALUES['account'],
                                           'curl/7.61.1')
        copy_file_path = s3_storage.copy(s3_storage.PERM, s3_storage.REJECT,
                                         key_name,
                                         config.DUMMY_VALUES["account"])

        def _get_key(r):
            k = r.split('/')[3]
            return k[:k.find('?')]

        assert isinstance(write_file_path, str)
        assert s3_storage.PERM in write_file_path
        assert copy_file_path is not None
        assert s3_storage.REJECT in copy_file_path
        assert copy_file_path != write_file_path

        write_key, copy_key = _get_key(write_file_path), _get_key(
            copy_file_path)
        assert write_key == copy_key