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


Python ldap3.MOCK_SYNC属性代码示例

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


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

示例1: test_init

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def test_init(self):
        """Tests init logic."""
        admin_obj = admin.Admin(None, 'dc=test,dc=com')
        admin_obj.write_ldap = ldap3.Connection(
            ldap3.Server('fake'), client_strategy=ldap3.MOCK_SYNC
        )

        admin_obj.init()

        dn_list = [
            arg[0][0] for arg in admin_obj.write_ldap.add.call_args_list
        ]

        self.assertTrue('dc=test,dc=com' in dn_list)
        self.assertTrue('ou=treadmill,dc=test,dc=com' in dn_list)
        self.assertTrue('ou=apps,ou=treadmill,dc=test,dc=com' in dn_list) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:18,代码来源:admin_test.py

示例2: test_add

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def test_add(self):
        """Tests add logic."""
        admin_obj = admin.Admin(None, 'dc=test,dc=com')
        admin_obj.write_ldap = ldap3.Connection(
            ldap3.Server('fake'), client_strategy=ldap3.MOCK_SYNC
        )

        admin_obj.add(
            'ou=example,dc=test,dc=com',
            'testClass',
            {
                'foo': 1,
                'bar': ['z', 'a'],
                'lot': 2,
                'exp': [3, 4]
            }
        )

        call = admin_obj.write_ldap.add.call_args_list[0][0]
        self.assertEqual(call[0], 'ou=example,dc=test,dc=com')
        self.assertEqual(call[1], 'testClass')
        self.assertEqual(
            [attr for attr in six.iteritems(call[2])],
            [('bar', ['z', 'a']), ('exp', [3, 4]), ('foo', 1), ('lot', 2)]
        ) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:27,代码来源:admin_test.py

示例3: mocked_connection

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def mocked_connection():
    """Mock ldap3 connection.
    :return: Return mocked connection object
    """
    # Create a MockSyncStrategy connection to the fake server
    mocked_connection = Connection(fake_server, user='cn=my_user,ou=test,o=lab', password='my_password',
                                     client_strategy=MOCK_SYNC)
    # Populate the DIT of the fake server with mock entries
    mocked_connection.strategy.entries_from_json('mock_server_entries.json')

    connection = Mock(return_value=mocked_connection)
    return connection 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:14,代码来源:test_ldap_search.py

示例4: mocked_connection

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def mocked_connection(self):
    """Mock ldap3 connection.
    :return: Return mocked connection object
    """
    # Create a MockSyncStrategy connection to the fake server
    mocked_connection = Connection(self.FAKE_SERVER, user='cn=my_user,ou=test,o=lab', password='my_password', client_strategy=MOCK_SYNC)
    
    # Populate the DIT of the fake server with mock entries
    mocked_connection.strategy.entries_from_json(self.MOCK_DATA_PATH + 'mock_server_entries.json')

    connection = Mock(return_value=mocked_connection)
    return connection 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:14,代码来源:helper.py

示例5: mocked_connection

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def mocked_connection():
    """Mock ldap3 connection.
    :return: Return mocked connection object
    """
    # Create a MockSyncStrategy connection to the fake server
    mocked_connection = Connection(fake_server, user='cn=my_user,ou=test,o=lab', password='my_password',
                                     client_strategy=MOCK_SYNC)
    # Populate the DIT of the fake server with mock entries
    mocked_connection.strategy.entries_from_json(MOCK_DATA_PATH + 'mock_server_entries.json')

    connection = Mock(return_value=mocked_connection)
    return connection 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:14,代码来源:test_ldap_search.py

示例6: test_schema

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def test_schema(self):
        """Test schema parsing."""
        # Disable W0212: Test access protected members of admin module.
        # pylint: disable=W0212
        attrs = [
            '{0}( %s NAME x1 DESC \'x x\''
            ' ORDERING integerOrderingMatch'
            ' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27'
            ' )' % (admin._TREADMILL_ATTR_OID_PREFIX + '11'),
            '{1}( %s NAME x2 DESC \'x x\''
            ' SUBSTR caseIgnoreSubstringsMatch'
            ' EQUALITY caseIgnoreMatch'
            ' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15'
            ' )' % (admin._TREADMILL_ATTR_OID_PREFIX + '22'),
        ]

        obj_classes = [
            '{0}( %s NAME o1 DESC \'x x\''
            ' SUP top STRUCTURAL'
            ' MUST ( xxx ) MAY ( a $ b )'
            ' )' % (admin._TREADMILL_OBJCLS_OID_PREFIX + '33'),
        ]

        admin_obj = admin.Admin(None, None)
        admin_obj.ldap = ldap3.Connection(ldap3.Server('fake'),
                                          client_strategy=ldap3.MOCK_SYNC)

        admin_obj.ldap.strategy.add_entry(
            'cn={1}treadmill,cn=schema,cn=config',
            {'olcAttributeTypes': attrs, 'olcObjectClasses': obj_classes}
        )

        admin_obj.ldap.bind()

        self.assertEqual(
            {
                'dn': 'cn={1}treadmill,cn=schema,cn=config',
                'objectClasses': {
                    'o1': {
                        'idx': 33,
                        'desc': 'x x',
                        'must': ['xxx'],
                        'may': ['a', 'b'],
                    },
                },
                'attributeTypes': {
                    'x1': {
                        'idx': 11,
                        'desc': 'x x',
                        'type': 'int'
                    },
                    'x2': {
                        'idx': 22,
                        'desc': 'x x',
                        'type': 'str',
                        'ignore_case': True
                    },
                }
            },
            admin_obj.schema()
        ) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:63,代码来源:admin_test.py

示例7: test_check

# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import MOCK_SYNC [as 别名]
def test_check(check, aggregator, mocker):
    server_mock = ldap3.Server("fake_server")
    conn_mock = ldap3.Connection(server_mock, client_strategy=ldap3.MOCK_SYNC, collect_usage=True)
    # usage.last_received_time is not populated when using mock connection, let's set a value
    conn_mock.usage.last_received_time = datetime.datetime.utcnow()
    conn_mock.strategy.entries_from_json(os.path.join(HERE, "fixtures", "monitor.json"))
    instance = {
        "url": "fake_server",
        "custom_queries": [
            {"name": "stats", "search_base": "cn=statistics,cn=monitor", "search_filter": "(!(cn=Statistics))"}
        ],
    }

    mocker.patch("datadog_checks.openldap.openldap.ldap3.Server", return_value=server_mock)
    mocker.patch("datadog_checks.openldap.openldap.ldap3.Connection", return_value=conn_mock)
    check.check(instance)
    tags = ["url:fake_server"]
    aggregator.assert_service_check("openldap.can_connect", check.OK, tags=tags)
    aggregator.assert_metric("openldap.bind_time", tags=tags)
    aggregator.assert_metric("openldap.connections.current", 1, tags=tags)
    aggregator.assert_metric("openldap.connections.max_file_descriptors", 1024, tags=tags)
    aggregator.assert_metric("openldap.connections.total", 3453, tags=tags)
    aggregator.assert_metric("openldap.operations.completed.total", 41398, tags=tags)
    aggregator.assert_metric("openldap.operations.initiated.total", 41399, tags=tags)
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:abandon"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:abandon"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:add"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:add"])
    aggregator.assert_metric("openldap.operations.completed", 9734, tags=tags + ["operation:bind"])
    aggregator.assert_metric("openldap.operations.initiated", 9734, tags=tags + ["operation:bind"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:compare"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:compare"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:delete"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:delete"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:extended"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:extended"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:modify"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:modify"])
    aggregator.assert_metric("openldap.operations.completed", 0, tags=tags + ["operation:modrdn"])
    aggregator.assert_metric("openldap.operations.initiated", 0, tags=tags + ["operation:modrdn"])
    aggregator.assert_metric("openldap.operations.completed", 29212, tags=tags + ["operation:search"])
    aggregator.assert_metric("openldap.operations.initiated", 29213, tags=tags + ["operation:search"])
    aggregator.assert_metric("openldap.operations.completed", 2452, tags=tags + ["operation:unbind"])
    aggregator.assert_metric("openldap.operations.initiated", 2452, tags=tags + ["operation:unbind"])
    aggregator.assert_metric("openldap.statistics.bytes", 796449497, tags=tags)
    aggregator.assert_metric("openldap.statistics.entries", 178382, tags=tags)
    aggregator.assert_metric("openldap.statistics.pdu", 217327, tags=tags)
    aggregator.assert_metric("openldap.statistics.referrals", 0, tags=tags)
    aggregator.assert_metric("openldap.threads", 1, tags=tags + ["status:active"])
    aggregator.assert_metric("openldap.threads", 1, tags=tags + ["status:backload"])
    aggregator.assert_metric("openldap.threads", 3, tags=tags + ["status:open"])
    aggregator.assert_metric("openldap.threads", 0, tags=tags + ["status:pending"])
    aggregator.assert_metric("openldap.threads", 0, tags=tags + ["status:starting"])
    aggregator.assert_metric("openldap.threads.max", 16, tags=tags)
    aggregator.assert_metric("openldap.threads.max_pending", 0, tags=tags)
    aggregator.assert_metric("openldap.uptime", 159182, tags=tags)
    aggregator.assert_metric("openldap.waiter.read", 1, tags=tags)
    aggregator.assert_metric("openldap.waiter.write", 0, tags=tags)
    aggregator.assert_metric("openldap.query.duration", tags=tags + ["query:stats"])
    aggregator.assert_metric("openldap.query.entries", 4, tags=tags + ["query:stats"])
    aggregator.assert_all_metrics_covered() 
开发者ID:DataDog,项目名称:integrations-core,代码行数:63,代码来源:test_unit.py


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