Skip to content
Snippets Groups Projects
Select Git revision
  • 894c82ee686a08385bb25d83520bf46b8a77c343
  • develop default
  • master protected
  • feature/frontend-tests
  • 0.99
  • 0.98
  • 0.97
  • 0.96
  • 0.95
  • 0.94
  • 0.93
  • 0.92
  • 0.91
  • 0.90
  • 0.89
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
24 results

bundle.js

Blame
  • test_worker_utils.py 1.46 KiB
    """
    tests of a few worker utilities
    """
    import json
    import re
    
    import jsonschema
    
    from inventory_provider.tasks import worker
    from inventory_provider.tasks import common
    
    
    def backend_db():
        return common._get_redis({
            'redis': {
                'hostname': None,
                'port': None
            },
            'redis-databases': [0, 7]
        }).db
    
    
    def test_build_subnet_db(mocked_worker_module):
        """
        checks that valid reverse subnet objects are created
        :param mocked_worker_module: fixture
        :return:
        """
    
        address_schema = {
            '$schema': 'http://json-schema.org/draft-07/schema#',
    
            'type': 'object',
            'properties': {
                'name': {'type': 'string'},
                'interface address': {'type': 'string'},
                'interface name': {'type': 'string'},
                'router': {'type': 'string'}
            },
            'required': ['name', 'interface address', 'interface name', 'router'],
            'additionalProperties': False
        }
    
        db = backend_db()  # also forces initialization
        worker._build_subnet_db()
    
        found_record = False
        for key, value in db.items():
    
            if not key.startswith('reverse_interface_addresses:'):
                continue
    
            found_record = True
    
            m = re.match('^reverse_interface_addresses:(.+)', key)
            assert m
            address = m.group(1)
    
            value = json.loads(value)
            jsonschema.validate(value, address_schema)
            assert value['name'] == address
    
        assert found_record