示例#1
0
def test_s3_server_post_unicode_bucket_key():
    # Make sure that we can deal with non-ascii characters in request URLs (e.g., S3 object names)
    dispatcher = server.DomainDispatcherApplication(server.create_backend_app)
    backend_app = dispatcher.get_application({
        'HTTP_HOST': 's3.amazonaws.com',
        'PATH_INFO': '/test-bucket/test-object-てすと'
    })
    assert backend_app
    backend_app = dispatcher.get_application({
        'HTTP_HOST': 's3.amazonaws.com',
        'PATH_INFO': '/test-bucket/test-object-てすと'.encode('utf-8')
    })
    assert backend_app
    def setUp(self):
        fake_s3_port = random.randint(10000, 65535)
        main_app = moto_server.DomainDispatcherApplication(
            moto_server.create_backend_app, service='s3')
        main_app.debug = True
        self.__thread = multiprocessing.Process(target=moto_server.run_simple,
                                                args=(
                                                    '127.0.0.1',
                                                    fake_s3_port,
                                                    main_app,
                                                ),
                                                kwargs={
                                                    'threaded': False,
                                                    'use_reloader': False,
                                                    'ssl_context': None
                                                })
        self.__thread.start()

        super(TestDjango_sftpserver_sftpserver_command_s3storage, self).setUp()
        self.start_server()

        # conn = boto.resource('s3', region_name='127.0.0.1')
        # conn.create_bucket(Bucket='testxxxx')

        kwargs = {
            # 'access_key': 'AKIAAAAAAAAAAAAAAAAA',
            # 'secret_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            'bucket_name': 'testxxxx',
            # 'proxy': b'127.0.0.1',
            # 'proxy_port': fake_s3_port,
            # 'host': '127.0.0.1',
            # 'port': fake_s3_port,
            # 'default_acl': 'private',
            'location': 'test_sftp',
            'url_protocol': 'http',
            'secure_urls': False,
            # 'endpoint_url': '127.0.0.1:{}'.format(fake_s3_port),
            'endpoint_url': 'http://localhost:{}'.format(fake_s3_port),
            'auto_create_bucket': True,
        }

        sai = models.StorageAccessInfo.objects.create(
            name=self.storage_name_0,
            storage_class="storages.backends.s3boto3.S3Boto3Storage",
            kwargs=yaml.dump(kwargs))
        sai.users.add(self.user)

        storage = sai.get_storage()
        print(storage.listdir('.'))
示例#3
0
def configure(config_file):
    config = load_config(config_file)

    # Setup logging.
    logging.basicConfig(level=config.get('shoobx:mocks3', 'log-level'))

    directory = config.get('shoobx:mocks3', 'directory')
    models.s3_sbx_backend.directory = directory
    if not os.path.exists(directory):
        os.makedirs(directory)

    def create_backend_app(service):
        app = server.create_backend_app(service)
        CORS(app)
        return app

    app = server.DomainDispatcherApplication(
        create_backend_app, service='s3-sbx')

    return app.get_application({
        'HTTP_HOST': config.get('shoobx:mocks3', 'hostname'),
    })