Пример #1
0
    def test_layer1(self):
        """Testing method / function layer1."""
        # Initializing key variables
        length_in_bits = 16
        base = 16
        expected_dict = {
            199: {'lldpRemSysName': 'byte_string_1',
                  'lldpRemSysDesc': 'byte_string_1',
                  'lldpRemPortDesc': 'byte_string_1',
                  'lldpRemSysCapEnabled': 'byte_string_1'},
            299: {'lldpRemSysName': 'byte_string_2',
                  'lldpRemSysDesc': 'byte_string_2',
                  'lldpRemPortDesc': 'byte_string_2',
                  'lldpRemSysCapEnabled': 'byte_string_2'}
        }

        # Set the stage for SNMPwalk
        snmpobj = Mock(spec=Query)
        mock_spec = {'swalk.return_value': self.walk_results_string}
        snmpobj.configure_mock(**mock_spec)

        # Get results
        testobj = testimport.init_query(snmpobj)
        results = testobj.layer1()

        # Basic testing of results
        for primary in results.keys():
            for secondary in results[primary].keys():
                # Test binary results separately from string results
                if secondary != 'lldpRemSysCapEnabled':
                    self.assertEqual(
                        results[primary][secondary],
                        expected_dict[primary][secondary])
                else:
                    # Convert results to binary string
                    original_string = expected_dict[primary][secondary]
                    hex_string = ''.join(
                        [hex(ord(character))[
                            2:] for character in original_string])
                    binary_string = bin(int(
                        hex_string, base))[2:].zfill(length_in_bits)

                    # Test
                    self.assertEqual(
                        results[primary][secondary], binary_string)
Пример #2
0
    def test_lldpremportdesc(self):
        """Testing method / function lldpremportdesc."""
        # Set the stage for SNMPwalk
        snmpobj = Mock(spec=Query)
        mock_spec = {'swalk.return_value': self.walk_results_string}
        snmpobj.configure_mock(**mock_spec)

        # Get results
        testobj = testimport.init_query(snmpobj)
        results = testobj.lldpremportdesc()

        # Basic testing of results
        for key in results.keys():
            self.assertEqual(isinstance(key, int), True)

        # Test that we are getting the correct OID
        results = testobj.lldpremportdesc(oidonly=True)
        self.assertEqual(results, '.1.0.8802.1.1.2.1.4.1.1.8')
Пример #3
0
    def test_supported(self):
        """Testing method / function supported."""
        # Set the stage for oid_exists returning True
        snmpobj = Mock(spec=Query)
        mock_spec = {'oid_exists.return_value': True}
        snmpobj.configure_mock(**mock_spec)

        #####################################################################
        # Test supported fails because of mib_bridge depenency of __init__
        # Need to figure out how to fix
        #####################################################################
        # testobj = testimport.init_query(snmpobj)
        # self.assertEqual(testobj.supported(), True)
        #####################################################################

        # Set the stage for oid_exists returning False
        mock_spec = {'oid_exists.return_value': False}
        snmpobj.configure_mock(**mock_spec)

        # Test unsupported
        testobj = testimport.init_query(snmpobj)
        self.assertEqual(testobj.supported(), False)