コード例 #1
0
ファイル: test_cim_operations.py プロジェクト: qinyaqi/pywbem
    def test_add_same_twice(self):  # pylint: disable=no-self-use
        """ Test addition of same recorder twice"""
        conn = WBEMConnection('http://localhost')
        conn.add_operation_recorder(LogOperationRecorder())
        # pylint: disable=protected-access
        assert len(conn._operation_recorders) == 1

        with pytest.raises(ValueError):
            conn.add_operation_recorder(LogOperationRecorder())
コード例 #2
0
ファイル: test_cim_operations.py プロジェクト: ssOleg/pywbem
 def test_add_same_twice(self):
     """ Test addition of same recorder twice"""
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder())
     # pylint: disable=protected-access
     self.assertTrue(len(conn._operation_recorders), 1)
     try:
         conn.add_operation_recorder(LogOperationRecorder())
         self.fail('Expected exception')
     except ValueError:
         pass
コード例 #3
0
ファイル: test_cim_operations.py プロジェクト: ssOleg/pywbem
 def test_add_operation_recorders(self):
     """Test addition of multiple operation recorders"""
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder())
     tcr_file = TestClientRecorder.open_file('blah.yaml', 'a')
     conn.add_operation_recorder(TestClientRecorder(tcr_file))
     # pylint: disable=protected-access
     self.assertTrue(len(conn._operation_recorders), 2)
コード例 #4
0
 def test_add_operation_recorders(self):  # pylint: disable=no-self-use
     """Test addition of multiple operation recorders"""
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder('fake_conn_id'))
     tcr_fn = 'blah.yaml'
     tcr_file = MyTestClientRecorder.open_file(tcr_fn, 'a')
     conn.add_operation_recorder(MyTestClientRecorder(tcr_file))
     # pylint: disable=protected-access
     assert len(conn._operation_recorders) == 2
     tcr_file.close()
     os.remove(tcr_fn)
コード例 #5
0
 def test_operation_recorder_enabled(self):  # pylint: disable=no-self-use
     """
     Test the property operation_recorder enabled setter
     """
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder('fake_conn_id'))
     assert conn.operation_recorder_enabled is True
     conn.operation_recorder_enabled = False
     assert conn.operation_recorder_enabled is False
     conn.operation_recorder_enabled = True
     assert conn.operation_recorder_enabled is True
コード例 #6
0
 def test_add_operation_recorder(self):  # pylint: disable=no-self-use
     """Test addition of an operation recorder"""
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder('fake_conn_id'))
     # pylint: disable=protected-access
     assert len(conn._operation_recorders) == 1
コード例 #7
0
ファイル: test_cim_operations.py プロジェクト: ssOleg/pywbem
 def test_add_operation_recorder(self):
     """Test addition of an operation recorder"""
     conn = WBEMConnection('http://localhost')
     conn.add_operation_recorder(LogOperationRecorder())
     # pylint: disable=protected-access
     self.assertTrue(len(conn._operation_recorders), 1)
コード例 #8
0
ファイル: test_cim_operations.py プロジェクト: pywbem/pywbem
def test_copy_conn(testcase, files, init_kwargs, set_debug, add_recorder,
                   enable_recorder, enable_statistics, perform_operation):
    """Test WBEMConnection.copy()"""

    try:
        for fname in files:
            # create empty file
            with io.open(fname, 'a', encoding='utf-8'):
                pass

        # pylint: disable=consider-using-with
        dev_null = io.open(DEV_NULL, 'a', encoding='utf-8')

        conn = WBEMConnection(**init_kwargs)

        if set_debug:
            conn.debug = True

        if add_recorder:
            conn.add_operation_recorder(LogOperationRecorder('fake_conn_id'))
            conn.add_operation_recorder(MyTestClientRecorder(dev_null))

        if enable_recorder:
            conn.operation_recorder_enabled = True

        if enable_statistics:
            conn.stats_enabled = True

        if perform_operation:
            try:
                conn.GetQualifier('Abstract')
            except pywbem.Error:  # Should time out
                pass

        # The code to be tested
        cpy = conn.copy()

        # Ensure that exceptions raised in the remainder of this function
        # are not mistaken as expected exceptions
        assert testcase.exp_exc_types is None

        # pylint: disable=protected-access,unidiomatic-type-check

        # Verify attributes that should have been copied

        assert_copy(cpy.url, conn.url)
        assert_copy(cpy.creds, conn.creds)
        assert_copy(cpy.default_namespace, conn.default_namespace)
        assert_copy(cpy.x509, conn.x509)
        assert_copy(cpy.ca_certs, conn.ca_certs)
        assert_copy(cpy.no_verification, conn.no_verification)
        assert_copy(cpy.timeout, conn.timeout)
        assert_copy(cpy.use_pull_operations, conn.use_pull_operations)
        assert_copy(cpy.stats_enabled, conn.stats_enabled)
        assert_copy(cpy.proxies, conn.proxies)
        assert_copy(cpy._scheme, conn._scheme)
        assert_copy(cpy._host, conn._host)
        assert_copy(cpy._use_enum_inst_pull_operations,
                    conn._use_enum_inst_pull_operations)
        assert_copy(cpy._use_enum_path_pull_operations,
                    conn._use_enum_path_pull_operations)
        assert_copy(cpy._use_ref_inst_pull_operations,
                    conn._use_ref_inst_pull_operations)
        assert_copy(cpy._use_ref_path_pull_operations,
                    conn._use_ref_path_pull_operations)
        assert_copy(cpy._use_assoc_inst_pull_operations,
                    conn._use_assoc_inst_pull_operations)
        assert_copy(cpy._use_assoc_path_pull_operations,
                    conn._use_assoc_path_pull_operations)
        assert_copy(cpy._use_query_pull_operations,
                    conn._use_query_pull_operations)

        # Verify attributes that should have been reset

        assert cpy._debug is False
        assert cpy._last_raw_request is None
        assert cpy._last_raw_reply is None
        assert cpy._last_request is None
        assert cpy._last_request_xml_item is None
        assert cpy._last_reply is None
        assert cpy._last_reply_xml_item is None
        assert cpy._last_request_len == 0
        assert cpy._last_reply_len == 0
        assert cpy._last_operation_time is None
        assert cpy._last_server_response_time is None

        # Session object should be a new object
        assert type(cpy.session) is type(conn.session)  # noqa: E721
        assert id(cpy.session) != id(conn.session)
        # Check that the Session object has adapters for the same schemes
        assert len(cpy.session.adapters) == len(conn.session.adapters)
        for scheme in conn.session.adapters:
            assert scheme in cpy.session.adapters
        # Beyond that, we do not determine whether the Session object is a
        # deep copy or a new object, because that would make this test too
        # much dependent on the internal structure of requests.Session.

        # Recorder objects should be new objects, but with same enabled state
        assert len(cpy._operation_recorders) == len(conn._operation_recorders)
        for i, conn_rec in enumerate(conn._operation_recorders):
            cpy_rec = cpy._operation_recorders[i]
            assert type(cpy_rec) is type(conn_rec)  # noqa: E721
            assert id(cpy_rec) != id(conn_rec)
            assert cpy_rec._pywbem_method is None
            assert cpy_rec._pywbem_args is None
            assert cpy_rec._pywbem_result_ret is None
            assert cpy_rec._pywbem_result_exc is None
            assert cpy_rec.enabled == conn_rec.enabled

        # Statistics object should be a new object, but with same enabled state
        assert type(cpy._statistics) is type(conn._statistics)  # noqa: E721
        assert id(cpy._statistics) != id(conn._statistics)
        assert not cpy._statistics._op_stats
        assert cpy._statistics.enabled == conn._statistics.enabled

        # Verify attributes that have been treated specially

        assert cpy._conn_id != conn._conn_id  # increased

        # pylint: enable=protected-access,unidiomatic-type-check

    finally:
        for fname in files:
            os.remove(fname)
        dev_null.close()