当前位置: 首页>>代码示例>>Python>>正文


Python ormsession.ThreadLocalORMSession类代码示例

本文整理汇总了Python中ming.orm.ormsession.ThreadLocalORMSession的典型用法代码示例。如果您正苦于以下问题:Python ThreadLocalORMSession类的具体用法?Python ThreadLocalORMSession怎么用?Python ThreadLocalORMSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ThreadLocalORMSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_interactive

 def test_interactive(self, Request, Server):
     M.OAuthConsumerToken.consumer = mock.Mock()
     user = M.User.by_username('test-admin')
     consumer_token = M.OAuthConsumerToken(
         api_key='api_key',
         user_id=user._id,
         description='ctok_desc',
     )
     ThreadLocalORMSession.flush_all()
     req = Request.from_request.return_value = {
         'oauth_consumer_key': 'api_key',
         'oauth_callback': 'http://my.domain.com/callback',
     }
     r = self.app.post('/rest/oauth/request_token', params={})
     rtok = parse_qs(r.body)['oauth_token'][0]
     r = self.app.post('/rest/oauth/authorize',
                       params={'oauth_token': rtok})
     r = r.forms[0].submit('yes')
     assert r.location.startswith('http://my.domain.com/callback')
     pin = parse_qs(urlparse(r.location).query)['oauth_verifier'][0]
     #pin = r.html.find(text=re.compile('^PIN: ')).split()[1]
     req = Request.from_request.return_value = {
         'oauth_consumer_key': 'api_key',
         'oauth_token': rtok,
         'oauth_verifier': pin,
     }
     r = self.app.get('/rest/oauth/access_token')
     atok = parse_qs(r.body)
     assert_equal(len(atok['oauth_token']), 1)
     assert_equal(len(atok['oauth_token_secret']), 1)
开发者ID:apache,项目名称:incubator-allura,代码行数:30,代码来源:test_auth.py

示例2: test_milestone_rename

 def test_milestone_rename(self):
     self.new_ticket(summary='test milestone rename')
     self.app.post('/bugs/1/update_ticket',{
         'summary':'test milestone rename',
         'description':'',
         'status':'',
         '_milestone':'1.0',
         'assigned_to':'',
         'labels':'',
         'labels_old':'',
         'comment': ''
     })
     ThreadLocalORMSession.flush_all()
     M.MonQTask.run_ready()
     ThreadLocalORMSession.flush_all()
     ticket_view = self.app.get('/p/test/bugs/1/')
     assert 'Milestone' in ticket_view
     assert '1.0' in ticket_view
     assert 'zzzé' not in ticket_view
     r = self.app.post('/bugs/update_milestones',{
         'field_name':'_milestone',
         'milestones-0.old_name':'1.0',
         'milestones-0.new_name':'zzzé',
         'milestones-0.description':'',
         'milestones-0.complete':'Open',
         'milestones-0.due_date':''
     })
     ticket_view = self.app.get('/p/test/bugs/1/')
     assert '1.0' not in ticket_view
     assert 'zzzé' in ticket_view
开发者ID:Bitergia,项目名称:allura,代码行数:30,代码来源:test_root.py

示例3: test_prefs

 def test_prefs(self):
     r = self.app.get('/auth/preferences/', extra_environ=dict(username='test-admin'))
     assert '[email protected]' not in r
     r = self.app.post('/auth/preferences/update', params={
              'preferences.display_name':'Test Admin',
              'new_addr.addr':'[email protected]',
              'new_addr.claim':'Claim Address',
              'primary_addr':'[email protected]',
              'preferences.email_format':'plain'},
             extra_environ=dict(username='test-admin'))
     r = self.app.get('/auth/preferences/')
     assert '[email protected]' in r
     r = self.app.post('/auth/preferences/update', params={
              'preferences.display_name':'Test Admin',
              'addr-1.ord':'1',
              'addr-2.ord':'1',
              'addr-2.delete':'on',
              'new_addr.addr':'',
              'primary_addr':'[email protected]',
              'preferences.email_format':'plain'},
             extra_environ=dict(username='test-admin'))
     r = self.app.get('/auth/preferences/')
     assert '[email protected]' not in r
     ea = M.EmailAddress.query.get(_id='[email protected]')
     ea.confirmed = True
     ThreadLocalORMSession.flush_all()
     r = self.app.post('/auth/preferences/update', params={
              'preferences.display_name':'Test Admin',
              'new_addr.addr':'[email protected]',
              'new_addr.claim':'Claim Address',
              'primary_addr':'[email protected]',
              'preferences.email_format':'plain'},
             extra_environ=dict(username='test-admin'))
开发者ID:johnsca,项目名称:incubator-allura,代码行数:33,代码来源:test_auth.py

示例4: test_that_label_counts_are_local_to_tool

    def test_that_label_counts_are_local_to_tool(self):
        """Test that label queries return only artifacts from the specified
        tool.
        """
        # create a ticket in two different tools, with the same label
        from allura.tests import decorators as td

        @td.with_tool('test', 'Tickets', 'bugs', username='test-user')
        def _test_ticket():
            return Ticket(ticket_num=1, summary="ticket1", labels=["mylabel"])

        @td.with_tool('test', 'Tickets', 'bugs2', username='test-user')
        def _test_ticket2():
            return Ticket(ticket_num=2, summary="ticket2", labels=["mylabel"])

        # create and save the tickets
        t1 = _test_ticket()
        t2 = _test_ticket2()
        ThreadLocalORMSession.flush_all()

        # test label query results
        label_count1 = t1.artifacts_labeled_with(
            "mylabel", t1.app_config).count()
        label_count2 = t2.artifacts_labeled_with(
            "mylabel", t2.app_config).count()
        assert 1 == label_count1 == label_count2
开发者ID:joequant,项目名称:allura,代码行数:26,代码来源:test_ticket_model.py

示例5: test_disable_user

 def test_disable_user(self):
     user = Mock(disabled=False, __ming__=Mock(), is_anonymous=lambda: False, _id=ObjectId())
     c.user = Mock(username='test-admin')
     with audits('Account disabled', user=True, actor='test-admin'):
         self.provider.disable_user(user)
         ThreadLocalORMSession.flush_all()
     assert_equal(user.disabled, True)
开发者ID:dastanforever,项目名称:allura,代码行数:7,代码来源:test_plugin.py

示例6: test_ticket_move_with_different_custom_fields

    def test_ticket_move_with_different_custom_fields(self):
        app1 = c.project.app_instance('bugs')
        app2 = c.project.app_instance('bugs2')
        app1.globals.custom_fields.extend([
            {'name': '_test', 'type': 'string', 'label': 'Test field'},
            {'name': '_test2', 'type': 'string', 'label': 'Test field 2'}])
        app2.globals.custom_fields.append(
            {'name': '_test', 'type': 'string', 'label': 'Test field'})
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
        with h.push_context(c.project._id, app_config_id=app1.config._id):
            ticket = Ticket.new()
            ticket.summary = 'test ticket'
            ticket.description = 'test description'
            ticket.custom_fields['_test'] = 'test val'
            ticket.custom_fields['_test2'] = 'test val 2'

        t = ticket.move(app2.config)
        assert_equal(t.summary, 'test ticket')
        assert_equal(t.description, 'test description')
        assert_equal(t.custom_fields['_test'], 'test val')
        post = Post.query.find(dict(thread_id=ticket.discussion_thread._id)).first()
        assert post is not None, 'No comment about ticket moving'
        message = 'Ticket moved from /p/test/bugs/1/'
        message += '\n\nCan\'t be converted:\n'
        message += '\n- **_test2**: test val 2'
        assert_equal(post.text, message)
开发者ID:johnsca,项目名称:incubator-allura,代码行数:27,代码来源:test_ticket_model.py

示例7: make_artifact

    def make_artifact(self, ticket_dict):
        remapped = {}
        for f, v in ticket_dict.iteritems():
            transform = self.FIELD_MAP.get(f, ())
            if transform is None:
                continue
            elif transform is True:
                remapped[f] = v
            elif callable(transform):
                transform(remapped, f, v)
            elif transform is ():
                self.custom(remapped, f, v)
            else:
                new_f, conv = transform
                remapped[new_f] = conv(v)

        ticket_num = ticket_dict['id']
        existing_ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
                                          ticket_num=ticket_num)
        if existing_ticket:
            ticket_num = c.app.globals.next_ticket_num()
            self.warnings.append('Ticket #%s: Ticket with this id already exists, using next available id: %s' % (ticket_dict['id'], ticket_num))
        else:
            if c.app.globals.last_ticket_num < ticket_num:
                c.app.globals.last_ticket_num = ticket_num
                ThreadLocalORMSession.flush_all()

        ticket = TM.Ticket(
            app_config_id=c.app.config._id,
            custom_fields=dict(),
            ticket_num=ticket_num,
            import_id=c.api_token.api_key)
        ticket.update(remapped)
        return ticket
开发者ID:Bitergia,项目名称:allura,代码行数:34,代码来源:import_support.py

示例8: private_project

    def private_project(self):
        '''
        Returns the personal user-project for the user
        '''
        if self.disabled or self.pending:
            return None

        from allura import model as M

        n = self.neighborhood
        auth_provider = plugin.AuthenticationProvider.get(request)
        project_shortname = auth_provider.user_project_shortname(self)
        p = M.Project.query.get(
            shortname=project_shortname, neighborhood_id=n._id)
        if p and p.deleted:
            # really delete it, since registering a new project would conflict
            # with the "deleted" one
            log.info(
                'completely deleting user project (was already flagged as deleted) %s',
                project_shortname)
            p.delete()
            ThreadLocalORMSession.flush_all()
            p = None
        if not p and not self.is_anonymous():
            # create user-project on demand if it is missing
            p = n.register_project(
                project_shortname, user=self, user_project=True)
        return p
开发者ID:abhinavthomas,项目名称:allura,代码行数:28,代码来源:auth.py

示例9: test_ticket_move_with_users_not_in_project

    def test_ticket_move_with_users_not_in_project(self):
        app1 = c.project.app_instance('bugs')
        app2 = c.project.app_instance('bugs2')
        app1.globals.custom_fields.extend([
            {'name': '_user_field', 'type': 'user', 'label': 'User field'},
            {'name': '_user_field_2', 'type': 'user', 'label': 'User field 2'}])
        app2.globals.custom_fields.extend([
            {'name': '_user_field', 'type': 'user', 'label': 'User field'},
            {'name': '_user_field_2', 'type': 'user', 'label': 'User field 2'}])
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()
        from allura.websetup import bootstrap
        bootstrap.create_user('test-user-0')
        with h.push_context(c.project._id, app_config_id=app1.config._id):
            ticket = Ticket.new()
            ticket.summary = 'test ticket'
            ticket.description = 'test description'
            ticket.custom_fields['_user_field'] = 'test-user'  # in project
            ticket.custom_fields['_user_field_2'] = 'test-user-0'  # not in project
            ticket.assigned_to_id = User.by_username('test-user-0')._id  # not in project

        t = ticket.move(app2.config)
        assert_equal(t.assigned_to_id, None)
        assert_equal(t.custom_fields['_user_field'], 'test-user')
        assert_equal(t.custom_fields['_user_field_2'], '')
        post = Post.query.find(dict(thread_id=ticket.discussion_thread._id)).first()
        assert post is not None, 'No comment about ticket moving'
        message = 'Ticket moved from /p/test/bugs/1/'
        message += '\n\nCan\'t be converted:\n'
        message += '\n- **_user_field_2**: test-user-0 (user not in project)'
        message += '\n- **assigned_to**: test-user-0 (user not in project)'
        assert_equal(post.text, message)
开发者ID:johnsca,项目名称:incubator-allura,代码行数:32,代码来源:test_ticket_model.py

示例10: test_artifactlink

def test_artifactlink():
    pg = WM.Page(title='TestPage2')
    q = M.Shortlink.query.find(dict(
            project_id=c.project._id,
            app_config_id=c.app.config._id,
            link=pg.shorthand_id()))
    assert q.count() == 0
    ThreadLocalORMSession.flush_all()
    M.MonQTask.run_ready()
    ThreadLocalORMSession.flush_all()
    assert q.count() == 1
    assert M.Shortlink.lookup('[TestPage2]')
    assert M.Shortlink.lookup('[wiki:TestPage2]')
    assert M.Shortlink.lookup('[test:wiki:TestPage2]')
    assert not M.Shortlink.lookup('[test:wiki:TestPage2:foo]')
    assert not M.Shortlink.lookup('[Wiki:TestPage2]')
    assert not M.Shortlink.lookup('[TestPage2_no_such_page]')
    c.project.uninstall_app('wiki')
    ThreadLocalORMSession.flush_all()
    assert not M.Shortlink.lookup('[wiki:TestPage2]')
    pg.delete()
    ThreadLocalORMSession.flush_all()
    M.MonQTask.run_ready()
    ThreadLocalORMSession.flush_all()
    assert q.count() == 0
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:25,代码来源:test_artifact.py

示例11: test_user_project_does_not_create_on_demand_for_openid_user

def test_user_project_does_not_create_on_demand_for_openid_user():
    u = M.User.register({'username': ''}, make_project=False)
    ThreadLocalORMSession.flush_all()
    assert not u.private_project()
    assert not M.Project.query.get(shortname='u/')
    assert not M.Project.query.get(shortname='u/anonymous')
    assert not M.Project.query.get(shortname='u/*anonymous')
开发者ID:pombredanne,项目名称:incubator-allura,代码行数:7,代码来源:test_auth.py

示例12: test_user

def test_user():
    assert c.user.url() .endswith('/u/test-admin/')
    assert c.user.script_name .endswith('/u/test-admin/')
    assert_equal(set(p.shortname for p in c.user.my_projects()),
                 set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']))
    # delete one of the projects and make sure it won't appear in my_projects()
    p = M.Project.query.get(shortname='test2')
    p.deleted = True
    ThreadLocalORMSession.flush_all()
    assert_equal(set(p.shortname for p in c.user.my_projects()),
                 set(['test', 'u/test-admin', 'adobe-1', '--init--']))
    u = M.User.register(dict(
        username='nosetest-user'))
    ThreadLocalORMSession.flush_all()
    assert_equal(u.private_project().shortname, 'u/nosetest-user')
    roles = g.credentials.user_roles(
        u._id, project_id=u.private_project().root_project._id)
    assert len(roles) == 3, roles
    u.set_password('foo')
    provider = plugin.LocalAuthenticationProvider(Request.blank('/'))
    assert provider._validate_password(u, 'foo')
    assert not provider._validate_password(u, 'foobar')
    u.set_password('foobar')
    assert provider._validate_password(u, 'foobar')
    assert not provider._validate_password(u, 'foo')
开发者ID:apache,项目名称:allura,代码行数:25,代码来源:test_auth.py

示例13: install

 def install(self, project):
     '''Create repo object for this tool'''
     super(ForgeGitApp, self).install(project)
     repo = GM.Repository(
         name=self.config.options.mount_point + '.git',
         tool='git',
         status='initializing',
         fs_path=self.config.options.get('fs_path'))
     ThreadLocalORMSession.flush_all()
     cloned_from_project_id = self.config.options.get('cloned_from_project_id')
     cloned_from_repo_id = self.config.options.get('cloned_from_repo_id')
     init_from_url = self.config.options.get('init_from_url')
     init_from_path = self.config.options.get('init_from_path')
     if cloned_from_project_id is not None:
         cloned_from = GM.Repository.query.get(_id=cloned_from_repo_id)
         repo.default_branch_name = cloned_from.default_branch_name
         repo.additional_viewable_extensions = cloned_from.additional_viewable_extensions
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=cloned_from.full_fs_path,
             cloned_from_name=cloned_from.app.config.script_name(),
             cloned_from_url=cloned_from.full_fs_path)
     elif init_from_url or init_from_path:
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=init_from_path,
             cloned_from_name=None,
             cloned_from_url=init_from_url)
     else:
         allura.tasks.repo_tasks.init.post()
开发者ID:apache,项目名称:allura,代码行数:28,代码来源:git_main.py

示例14: install

 def install(self, project):
     '''Create repo object for this tool'''
     super(ForgeHgApp, self).install(project)
     HM.Repository(
         name=self.config.options.mount_point,
         tool='hg',
         status='initializing')
     ThreadLocalORMSession.flush_all()
     cloned_from_project_id = self.config.options.get('cloned_from_project_id')
     cloned_from_repo_id = self.config.options.get('cloned_from_repo_id')
     init_from_url = self.config.options.get('init_from_url')
     init_from_path = self.config.options.get('init_from_path')
     if cloned_from_project_id is not None:
         cloned_from = HM.Repository.query.get(_id=cloned_from_repo_id)
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=cloned_from.full_fs_path,
             cloned_from_name=cloned_from.app.config.script_name(),
             cloned_from_url=cloned_from.full_fs_path,
             copy_hooks=self.config.options.get('copy_hooks', False))
     elif init_from_url or init_from_path:
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=init_from_path,
             cloned_from_name=None,
             cloned_from_url=init_from_url,
             copy_hooks=self.config.options.get('copy_hooks', False))
     else:
         allura.tasks.repo_tasks.init.post()
开发者ID:Bitergia,项目名称:allura,代码行数:27,代码来源:hg_main.py

示例15: install

 def install(self, project):
     """Create repo object for this tool"""
     super(ForgeGitApp, self).install(project)
     repo = GM.Repository(name=self.config.options.mount_point + ".git", tool="git", status="initializing")
     ThreadLocalORMSession.flush_all()
     cloned_from_project_id = self.config.options.get("cloned_from_project_id")
     cloned_from_repo_id = self.config.options.get("cloned_from_repo_id")
     init_from_url = self.config.options.get("init_from_url")
     init_from_path = self.config.options.get("init_from_path")
     if cloned_from_project_id is not None:
         cloned_from = GM.Repository.query.get(_id=cloned_from_repo_id)
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=cloned_from.full_fs_path,
             cloned_from_name=cloned_from.app.config.script_name(),
             cloned_from_url=cloned_from.full_fs_path,
             copy_hooks=self.config.options.get("copy_hooks", False),
         )
     elif init_from_url or init_from_path:
         allura.tasks.repo_tasks.clone.post(
             cloned_from_path=init_from_path,
             cloned_from_name=None,
             cloned_from_url=init_from_url,
             copy_hooks=self.config.options.get("copy_hooks", False),
         )
     else:
         allura.tasks.repo_tasks.init.post()
开发者ID:Bitergia,项目名称:allura,代码行数:26,代码来源:git_main.py


注:本文中的ming.orm.ormsession.ThreadLocalORMSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。