コード例 #1
0
 def test_saas_public(self):
     drop_db_list = [
         build for build in db.list_dbs()
         if build.startswith('test-fast-build')
     ]
     self.drop_dbs(drop_db_list)
     self.env['saas.template.operator'].preparing_template_next()
     params = urllib.parse.urlencode({
         'mail_message': 'mail.message',
     })
     url_1 = '/saas_public/{template_id}/create-fast-build?{params}'.format(
         template_id=self.public_template.id, params=params)
     public_template_response = self.url_open(url_1)
     self.assertIn(public_template_response.status_code, [200, 204],
                   'User must be redirected to the build')
     created_builds = [
         build for build in db.list_dbs()
         if build.startswith('test-fast-build')
     ]
     self.assertTrue(created_builds)
     url_2 = '/saas_public/{}/create-fast-build'.format(
         self.private_template.id)
     private_template = self.url_open(url_2)
     self.assertIn(private_template.status_code, [404, 403],
                   'User should not have access to a private template')
コード例 #2
0
    def test_template_operator(self):
        self.drop_dbs([DB_INSTANCE_1, DB_INSTANCE_2])
        self.env['saas.template.operator'].preparing_template_next()

        # Tests that template db created correctly
        self.assertTrue(self.saas_template_operator_1.operator_db_id.name)
        self.assertEqual(self.saas_template_operator_1.operator_db_id.name,
                         DB_TEMPLATE_1)
        self.assertIn(DB_TEMPLATE_1, db.list_dbs())
        self.assert_no_error_in_db(DB_TEMPLATE_1)

        # Check that module from template_module_ids is installed
        self.assert_modules_is_installed(DB_TEMPLATE_1, MODULE_TO_INSTALL)
        self.assert_record_is_created(
            DB_TEMPLATE_1, 'mail.message',
            [('subject', '=', TEMPLATE_TEST_SUBJECT)])

        # Actually second template is done by calling preparing_template_next first time but that call
        # is needed to emulate calling by crone every few minutes. This is done to make sure that the repeated method
        # call does not cause errors.
        self.env['saas.template.operator'].preparing_template_next()

        # Tests that template db created correctly
        self.assertTrue(self.saas_template_operator_2.operator_db_id.name)
        self.assertEqual(self.saas_template_operator_2.operator_db_id.name,
                         DB_TEMPLATE_2)
        self.assertIn(DB_TEMPLATE_2, db.list_dbs())
        self.assert_no_error_in_db(DB_TEMPLATE_2)

        # Check that module from template_module_ids is installed
        self.assert_modules_is_installed(DB_TEMPLATE_2, MODULE_TO_INSTALL)
        self.assert_record_is_created(
            DB_TEMPLATE_2, 'mail.message',
            [('subject', '=', TEMPLATE_TEST_SUBJECT)])

        # Check that database instance created correctly
        self.saas_template_operator_1.create_db(KEY_VALUES, DB_INSTANCE_1)
        self.assertIn(DB_INSTANCE_1, db.list_dbs())
        self.assert_no_error_in_db(DB_INSTANCE_1)
        self.assert_record_is_created(DB_INSTANCE_1, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.master')])
        self.assert_record_is_created(DB_INSTANCE_1, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.build')])
        self.assert_record_is_created(DB_INSTANCE_1, 'mail.message',
                                      [('subject', '=', BUILD_TEST_SUBJECT)])

        self.saas_template_operator_2.create_db({}, DB_INSTANCE_2)
        self.assertIn(DB_INSTANCE_2, db.list_dbs())
        self.assert_no_error_in_db(DB_INSTANCE_2)
        self.assert_record_is_created(DB_INSTANCE_2, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.master')])
        self.assert_record_is_created(DB_INSTANCE_2, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.build')])
コード例 #3
0
 def drop_dbs(self, db_list=None):
     if not db_list:
         db_list = []
     db_list += [DB_TEMPLATE_1, DB_TEMPLATE_2, 'template_database']
     for i in db_list:
         if i in db.list_dbs():
             db.exp_drop(i)
コード例 #4
0
def resolve_db_name(ctx, param, value, exists=True):
    from odoo.service.db import list_dbs

    config = (
        ctx.obj['config']
    )

    dbs = config['db_name'].split(',') if config['db_name'] else None
    if dbs is None:
        dbs = list_dbs(True)

    if value:
        if dbs is not None:
            if exists and value not in dbs:
                raise click.BadParameter(
                    "No such db '%s'." % value
                )
            elif not exists and value in dbs:
                raise click.BadParameter(
                    "Given db already exists '%s'." % value
                )
        return value
    elif exists and dbs is not None and len(dbs) == 1:
        # Running in single db mode, safe to assume the db.
        return dbs[0]

    raise click.BadParameter(
        "No db name given."
    )
コード例 #5
0
def authenticate(request, response):
    response.result = {'status': 'denied'}
    #if getattr(request, 'query'): request.params = tools.merge(request.params, request.query);
    params = tools.parse(request.params)
    if request.params.login:
        if params.encrypted == True:
            params.login, params.password = routes.decrypt(
                params.login), routes.decrypt(params.password)
        if not params.database:
            from odoo.service.db import list_dbs
            params.database = list_dbs()[0]
        uid = http.request.session.authenticate(params.database, params.login,
                                                params.password)
        if uid:
            user_id = request.env['res.users'].browse(uid)
            if user_id:
                #request.env.context.user = user_id
                response.result = {'status': 'success'}
                if params.authentication == True:
                    response.result['login'], response.result[
                        'password'] = routes.encrypt(
                            params.login), routes.encrypt(params.password)
                    response.result['id'] = uid
                    if not params.client_js_time or params.client_js_time != routes.client_js_time:
                        response.result['client_js'] = routes.client_js
                        response.result[
                            'client_js_time'] = routes.client_js_time
    return response.result
コード例 #6
0
ファイル: runner.py プロジェクト: sdaexpertise/facturation
 def _run_next(self):
     db_names = list_dbs(True)
     if len(db_names):
         db_name = db_names[self.db_index]
         self._acquire_job(db_name)
         self.db_index = (self.db_index + 1) % len(db_names)
     else:
         self.db_index = 0
コード例 #7
0
    def create_database(self, template_db=None, demo=False, lang='en_US'):
        self.ensure_one()
        new_db = self.db_name
        res = {}
        if new_db in database.list_dbs():
            raise UserError(_('Database Already Exist!'))
        if template_db:
            database._drop_conn(self.env.cr, template_db)
            database.exp_duplicate_database(template_db, new_db)
        else:
            # password = random_password()
            # res.update({'superuser_password': password})
            database.exp_create_database(new_db, demo, lang)
        if not self.is_template_db:
            self.upgrade_database({'params': True})
        _logger.info('Database created Successfully')

        return res
コード例 #8
0
ファイル: api.py プロジェクト: HafeezRai/odooapi
 def restful(self, **post):
     filecontent = {}
     if post.get('login') and post.get('password'):
         if not post.get(
                 'database'
         ):  #If no database is passed on the ajax post, get one random database
             from odoo.service.db import list_dbs
             post['database'] = list_dbs()[0]
         login = request.session.authenticate(post['database'],
                                              post['login'],
                                              post['password'])
         if not login:  #If login doesn't return uid, return json with status denied
             filecontent['status'] = 'denied'
             return request.make_response(
                 json(filecontent), [('Access-Control-Allow-Origin', '*')])
         filecontent = request.env['res.users'].search([]).read(
         )  #If login successful, you can execute functions and access datas
     if not filecontent:  #If no data filled in the dict, return error
         filecontent = {'status': 'error'}
     return request.make_response(json(filecontent),
                                  [('Access-Control-Allow-Origin', '*')])
コード例 #9
0
def resolve_db_name_multiple(ctx, param, value):
    from odoo.service.db import list_dbs

    config = (
        ctx.obj['config']
    )

    dbs = config['db_name'].split(',') if config['db_name'] else None
    if dbs is None:
        dbs = list_dbs(True)

    if value:
        invalid = [db for db in value if db not in dbs]
        if invalid:
            raise click.BadParameter(
                "No such db '%s'." % invalid[0]
            )

        return value

    return dbs
コード例 #10
0
ファイル: runner.py プロジェクト: sdaexpertise/facturation
 def run_once(self):
     for db_name in list_dbs(True):
         self._acquire_job(db_name, cleanup=True)
コード例 #11
0
 def client_db_list(self, **params):
     # TODO: do not use force here. Server have to be adapted
     databases = service_db.list_dbs(force=True)
     return Response(json.dumps(databases), status=200)
コード例 #12
0
    def test_template_operator(self):
        # FIXME: that check needed when last tests didn't pass, not sure that it is correct way to drop db
        if DB_TEMPLATE_1 in db.list_dbs():
            db.exp_drop(DB_TEMPLATE_1)
        if DB_TEMPLATE_2 in db.list_dbs():
            db.exp_drop(DB_TEMPLATE_2)
        if 'template_database' in db.list_dbs():
            db.exp_drop('template_database')
        # Template 1
        self.saas_template_operator_1.preparing_template_next()
        # Tests that template db created correctly
        self.assertTrue(self.saas_template_operator_1.operator_db_id.name)
        self.assertEqual(self.saas_template_operator_1.operator_db_id.name,
                         DB_TEMPLATE_1)
        self.assertIn(DB_TEMPLATE_1, db.list_dbs())
        self.assert_no_error_in_db(DB_TEMPLATE_1)

        # Check that module from template_module_ids is installed
        self.assert_modules_is_installed(DB_TEMPLATE_1, MODULE_TO_INSTALL)
        self.assert_record_is_created(
            DB_TEMPLATE_1, 'mail.message',
            [('subject', '=', TEMPLATE_TEST_SUBJECT)])

        # Template 2. Actually second template is done by calling preparing_template_next first time but that call
        # is needed to emulate calling by crone every few minutes. This is done to make sure that the repeated method
        # call does not cause errors.
        self.saas_template_operator_2.preparing_template_next()

        # Tests that template db created correctly
        self.assertTrue(self.saas_template_operator_2.operator_db_id.name)
        self.assertEqual(self.saas_template_operator_2.operator_db_id.name,
                         DB_TEMPLATE_2)
        self.assertIn(DB_TEMPLATE_2, db.list_dbs())
        self.assert_no_error_in_db(DB_TEMPLATE_2)

        # Check that module from template_module_ids is installed
        self.assert_modules_is_installed(DB_TEMPLATE_2, MODULE_TO_INSTALL)
        self.assert_record_is_created(
            DB_TEMPLATE_2, 'mail.message',
            [('subject', '=', TEMPLATE_TEST_SUBJECT)])

        # Check that database instance created correctly
        if DB_INSTANCE_1 in db.list_dbs():
            db.exp_drop(DB_INSTANCE_1)
        if DB_INSTANCE_2 in db.list_dbs():
            db.exp_drop(DB_INSTANCE_2)

        self.saas_template_operator_1.create_db(DB_INSTANCE_1,
                                                self.build_post_init_line_1)
        self.assertIn(DB_INSTANCE_1, db.list_dbs())
        self.assert_no_error_in_db(DB_INSTANCE_1)
        self.assert_record_is_created(DB_INSTANCE_1, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.master')])
        self.assert_record_is_created(DB_INSTANCE_1, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.build')])
        self.assert_record_is_created(DB_INSTANCE_1, 'mail.message',
                                      [('subject', '=', BUILD_TEST_SUBJECT)])

        self.saas_template_operator_2.create_db(DB_INSTANCE_2,
                                                self.build_post_init_line_2)
        self.assertIn(DB_INSTANCE_2, db.list_dbs())
        self.assert_no_error_in_db(DB_INSTANCE_2)
        self.assert_record_is_created(DB_INSTANCE_2, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.master')])
        self.assert_record_is_created(DB_INSTANCE_2, 'ir.config_parameter',
                                      [('key', '=', 'auth_quick.build')])