示例#1
0
    async def post(self, param=None):
        if param is not None:
            raise web.HTTPError(400, reason=UNEXPECTED_PARAM_MESSAGE)

        file = self._get_request_file()
        create_db = self._get_db_option()

        validation_rules = get_validation_rules(create_db)

        if not file:
            raise web.HTTPError(400, reason=FILE_EXPECTED_MESSAGE)

        validate_package(file, validation_rules)

        await self.notify_client('Creating application environment')

        self.app_uid = create_application_environment(file)
        environment_variables = get_app_environment_data(self.app_uid)

        app_meta = {}

        if create_db:
            db_data = get_db_data(environment_variables)

            await self.notify_client('Creating db instance')

            container_id = create_db_instance(self.docker, db_data)
            app_meta.update(db_container_id=container_id)

        await self.notify_client('Registering app configuration')

        result_data = await self.configurator.register_app(
            self.app_uid, environment_variables)
        app_meta.update(**(result_data or {}))

        app_name = environment_variables.get(APP_NAME_VARIABLE_NAME)
        app_description = environment_variables.get(
            APP_DESCRIPTION_VARIABLE_NAME)

        app = Application(uid=self.app_uid,
                          name=app_name,
                          description=app_description,
                          **app_meta)
        app_id = await self.repository.add(app)

        await self.notify_client('done')

        app_data = {'id': app_id, **app.dict()}

        self.set_status(201)
        self.write(app_data)
示例#2
0
def test_environment_creation(get_package, validation_rules):
    package = get_package('valid_app')
    validate_package(package, validation_rules)

    app_id = create_application_environment(package)
    app_dirpath = os.path.join(settings.apps_path, app_id)
    assert os.path.exists(app_dirpath)

    extracted_files = os.listdir(app_dirpath)
    assert len(extracted_files) != 0

    venv_path = os.path.join(app_dirpath, 'venv')
    assert os.path.exists(venv_path)

    bin_path = os.path.join(venv_path, 'bin')
    assert 'flask' in os.listdir(bin_path)
示例#3
0
def test_package_with_invalid_size(get_package, validation_rules):
    package = get_package('heavy_app')
    with pytest.raises(errors.InvalidPackageSizeError):
        validate_package(package, validation_rules)
示例#4
0
def test_package_validation_with_empty_required_file(get_package, validation_rules):
    package = get_package('app_with_empty_file')
    with pytest.raises(errors.EmptyRequiredFileError):
        validate_package(package, validation_rules)
示例#5
0
def test_package_validation_with_missing_required_file(get_package, validation_rules):
    package = get_package('app_with_missing_file')
    with pytest.raises(errors.RequiredFileNotFoundError):
        validate_package(package, validation_rules)
示例#6
0
def test_valid_package(get_package, validation_rules):
    package = get_package('valid_app')
    validate_package(package, validation_rules)
    assert True