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


Python Environment.get_known_users方法代码示例

本文整理汇总了Python中trac.env.Environment.get_known_users方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get_known_users方法的具体用法?Python Environment.get_known_users怎么用?Python Environment.get_known_users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.env.Environment的用法示例。


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

示例1: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_known_users [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
        self.env = Environment(env_path, create=True)
        self.db = self.env.get_db_cnx()

    def tearDown(self):
        self.db.close()
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_get_version(self):
        """Testing env.get_version"""
        assert self.env.get_version() == db_default.db_version

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO session VALUES (%s,%s,0)",
                           [('123', 0),('tom', 1), ('joe', 1), ('jane', 1)])
        cursor.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                           [('123', 0, 'email', '[email protected]'),
                            ('tom', 1, 'name', 'Tom'),
                            ('tom', 1, 'email', '[email protected]'),
                            ('joe', 1, 'email', '[email protected]'),
                            ('jane', 1, 'name', 'Jane')])
        users = {}
        for username,name,email in self.env.get_known_users(self.db):
            users[username] = (name, email)

        assert not users.has_key('anonymous')
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:37,代码来源:env.py

示例2: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_known_users [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_abs_href(self):
        self.assertEqual('http://trac.edgewall.org/some/path', self.env.abs_href())

    def test_href(self):
        self.assertEqual('/some/path', self.env.href())

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        with self.env.db_transaction as db:
            db.executemany("INSERT INTO session VALUES (%s,%s,0)",
                [('123', 0), ('tom', 1), ('joe', 1), ('jane', 1)])
            db.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                [('123', 0, 'email', '[email protected]'),
                 ('tom', 1, 'name', 'Tom'),
                 ('tom', 1, 'email', '[email protected]'),
                 ('joe', 1, 'email', '[email protected]'),
                 ('jane', 1, 'name', 'Jane')])
        users = {}
        for username, name, email in self.env.get_known_users():
            users[username] = (name, email)

        self.assertTrue('anonymous' not in users)
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])
开发者ID:dafrito,项目名称:trac-mirror,代码行数:44,代码来源:env.py

示例3: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_known_users [as 别名]
class EnvironmentTestCase(unittest.TestCase):
    def setUp(self):
        env_path = os.path.join(tempfile.gettempdir(), "trac-tempenv")
        self.env = Environment(env_path, create=True)
        self.db = self.env.get_db_cnx()

    def tearDown(self):
        self.db.close()
        self.env.shutdown()  # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_get_version(self):
        """Testing env.get_version"""
        assert self.env.get_version() == db_default.db_version

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO session VALUES (%s,%s,0)", [("123", 0), ("tom", 1), ("joe", 1), ("jane", 1)])
        cursor.executemany(
            "INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
            [
                ("123", 0, "email", "[email protected]"),
                ("tom", 1, "name", "Tom"),
                ("tom", 1, "email", "[email protected]"),
                ("joe", 1, "email", "[email protected]"),
                ("jane", 1, "name", "Jane"),
            ],
        )
        users = {}
        for username, name, email in self.env.get_known_users(self.db):
            users[username] = (name, email)

        assert not users.has_key("anonymous")
        self.assertEqual(("Tom", "[email protected]"), users["tom"])
        self.assertEqual((None, "[email protected]"), users["joe"])
        self.assertEqual(("Jane", None), users["jane"])
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:39,代码来源:env.py

示例4: Client

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_known_users [as 别名]
class Client(object):
    def __init__(self, env_path):
        self.env_path = env_path
        self.env = Environment(env_path)
        self.db_cnx = self.env.get_db_cnx()
        self._registered_users_logins = []
        self._timetracking_plugins = self._get_timetracking_plugins()

    def _get_timetracking_plugins(self):
        plugins = {}
        if tracLib.SUPPORT_TIME_TRACKING == 'auto':
            for plugin in tracLib.timetracking.plugins:
                plugin_name = plugin.get_name()
                for com_name, com_enabled in self.env._component_rules.items():
                    if com_name.startswith(plugin_name) and com_enabled and plugin_name not in plugins:
                        plugins[plugin_name] = plugin(self.env)
        else:
            for plugin in tracLib.timetracking.plugins:
                plugin_name = plugin.get_name()
                if plugin_name == tracLib.SUPPORT_TIME_TRACKING:
                    plugins[plugin_name] = plugin(self.env)
                    break;
        for plugin_name in plugins.keys():
            print "Plugin '%s' will be used to get workitems." % plugin_name
        return plugins.values()

    def get_project_description(self):
        return self.env.project_description

    def get_users(self):
        result = self.env.get_known_users()
        trac_users = list([])
        for user in result:
            user_login = user[0].lower()
            if user_login in self._registered_users_logins:
                continue
            u = TracUser(user_login)
            u.email = user[2]
            trac_users.append(u)
            self._registered_users_logins.append(user_login)
        # if we accept only authorised users, we don't have any more users to return
        # all of them were returned by "get_known_users" method
        if not tracLib.ACCEPT_NON_AUTHORISED_USERS:
            return trac_users
        # here we must to get component owners, issue reporters, owners and attachment authors
        # that are not registered users
        user_fields = [("owner", "component"), ("reporter", "ticket"), ("owner", "ticket"), ("author", "attachment")]
        first = True
        request = ""
        for column_name, table_name in user_fields :
            if first:
                first = False
            else:
                request += "UNION "
            request += "SELECT DISTINCT lower(%s) FROM %s " % (column_name, table_name)
        cursor = self.db_cnx.cursor()
        cursor.execute(request)
        for row in cursor:
            if row[0] not in self._registered_users_logins:
                trac_user = self._get_non_authorised_user(row[0])
                if trac_user is not None :
                    trac_users.append(trac_user)
                    self._registered_users_logins.append(trac_user.name)
        return trac_users

    def _get_non_authorised_user(self, user_name):
        if user_name is None :
            return None
        # non authorized users in trac are stored like this "name <email_address>"
        start = user_name.find("<")
        end = user_name.rfind(">")
        # we don't accept users who didn't leave the email
        if (start > -1) and (end > start + 1):
            if user_name.find("@", start, end) > 0:
                user = TracUser(user_name[start + 1 : end].replace(" ", "_"))
                user.email = user_name[start + 1 : end].replace(" ", "_")
                return user
        return None

    def _get_user_login(self, user_name):
        if user_name is None:
            return None
        if user_name in self._registered_users_logins:
            return user_name
        if not tracLib.ACCEPT_NON_AUTHORISED_USERS:
            return None
        user = self._get_non_authorised_user(user_name)
        if (user is None) or (user.name not in self._registered_users_logins) :
            return None
        return user.name

    def get_severities(self):
        return self._get_data_from_enum("severity")

    def get_issue_types(self):
        return self._get_data_from_enum("ticket_type")

    def get_issue_priorities(self):
        return self._get_data_from_enum("priority")

#.........这里部分代码省略.........
开发者ID:IQYottabit,项目名称:youtrack-rest-python-library,代码行数:103,代码来源:client.py

示例5: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import get_known_users [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_db_exc(self):
        db_exc = self.env.db_exc
        self.assertTrue(hasattr(db_exc, 'IntegrityError'))
        self.assertIs(db_exc, self.env.db_exc)

    def test_abs_href(self):
        abs_href = self.env.abs_href
        self.assertEqual('http://trac.edgewall.org/some/path', abs_href())
        self.assertIs(abs_href, self.env.abs_href)

    def test_href(self):
        href = self.env.href
        self.assertEqual('/some/path', href())
        self.assertIs(href, self.env.href)

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())
        self.assertEqual(db_default.db_version, self.env.database_version)
        self.assertEqual(db_default.db_version, self.env.database_initial_version)

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        with self.env.db_transaction as db:
            db.executemany("INSERT INTO session VALUES (%s,%s,0)",
                [('123', 0), ('tom', 1), ('joe', 1), ('jane', 1)])
            db.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                [('123', 0, 'email', '[email protected]'),
                 ('tom', 1, 'name', 'Tom'),
                 ('tom', 1, 'email', '[email protected]'),
                 ('joe', 1, 'email', '[email protected]'),
                 ('jane', 1, 'name', 'Jane')])
        users = {}
        for username, name, email in self.env.get_known_users():
            users[username] = (name, email)

        self.assertTrue('anonymous' not in users)
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])

    def test_is_component_enabled(self):
        self.assertEqual(True, Environment.required)
        self.assertEqual(True, self.env.is_component_enabled(Environment))
        self.assertEqual(False, EnvironmentStub.required)
        self.assertEqual(None, self.env.is_component_enabled(EnvironmentStub))

    def test_dumped_values_in_tracini(self):
        parser = RawConfigParser()
        filename = self.env.config.filename
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))

    def test_dumped_values_in_tracini_sample(self):
        parser = RawConfigParser()
        filename = self.env.config.filename + '.sample'
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))
        self.assertTrue(parser.has_option('logging', 'log_format'))
        self.assertEqual('', parser.get('logging', 'log_format'))
开发者ID:exocad,项目名称:exotrac,代码行数:79,代码来源:env.py


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