當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。