Ejemplo n.º 1
0
    def test_create_mapping_failure(self):
        mapper = MockPortMapper(available=True)
        mapper.create_mapping = Mock(side_effect=Exception)
        manager = PortMapperManager(mappers=[mapper])

        manager._active_mapper = mapper
        assert manager.create_mapping(40102) is None
Ejemplo n.º 2
0
    def test_create_mapping(self):
        mapper = MockPortMapper(available=True)
        mapper.create_mapping = Mock(return_value=50102)
        manager = PortMapperManager(mappers=[mapper])

        manager._active_mapper = mapper
        assert manager.create_mapping(40102) == 50102
Ejemplo n.º 3
0
    def test_quit_available_no_mapping(self):
        mapper = MockPortMapper()
        manager = PortMapperManager(mappers=[mapper])
        manager.remove_mapping = Mock()
        manager._active_mapper = manager._mappers[0]

        manager.quit()
        assert not manager.remove_mapping.called
Ejemplo n.º 4
0
    def test_network(self):
        network_dict = {
            'local_ip_address': '192.168.0.10',
            'external_ip_address': '1.2.3.4',
            'connection_type': dict(),
            'status_info': dict()
        }

        mapper = MockPortMapper(network=network_dict)
        manager = PortMapperManager(mappers=[mapper])

        assert manager.network == dict()
        manager._active_mapper = mapper
        assert manager.network == network_dict
Ejemplo n.º 5
0
    def test_remove_mapping(self):
        mapper = MockPortMapper(available=True)
        mapper.remove_mapping = Mock(return_value=True)

        manager = PortMapperManager(mappers=[mapper])
        manager._active_mapper = mapper
        manager._mapping = {
            'TCP': {
                40102: 40102,
                40103: 40103,
                3282: 3282
            },
            'UDP': {},
        }
        assert manager.remove_mapping(40102, 40102) is True
Ejemplo n.º 6
0
    def test_quit(self):
        mapper = MockPortMapper()
        manager = PortMapperManager(mappers=[mapper])
        manager.remove_mapping = Mock()
        manager._active_mapper = mapper
        manager._mapping = {
            'TCP': {
                40102: 40102,
                40103: 40103,
                3282: 3282
            },
            'UDP': {
                40102: 40102,
                40103: 40103,
                3282: 3282
            },
        }

        manager.quit()
        assert manager.remove_mapping.call_count == sum(
            len(m) for m in manager._mapping.values())
Ejemplo n.º 7
0
 def test_exception(self):
     mapper = MockPortMapper()
     mapper.get_mapping = Mock(side_effect=Exception('Test exception'))
     manager = PortMapperManager(mappers=[mapper])
     manager._active_mapper = mapper
     assert not manager.get_mapping(40102)
Ejemplo n.º 8
0
 def test_available(self):
     mapper = MockPortMapper()
     manager = PortMapperManager(mappers=[mapper])
     manager._active_mapper = mapper
     assert manager.get_mapping(40102)
     assert mapper.get_mapping_calls == 1
Ejemplo n.º 9
0
 def test_available(self):
     mapper = MockPortMapper()
     manager = PortMapperManager(mappers=[mapper])
     assert not manager.available
     manager._active_mapper = Mock()
     assert manager.available