api.datastores.v1.test_helpers.descriptor.search_descriptors — Argus-Toolbelt 1.0 documentation

# Source code for api.datastores.v1.test_helpers.descriptor.search_descriptors

    def success(function):
        """Mock https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search, respond with HTTP 200"""
        import requests_mock
        from argus_api.helpers.tests import fake_response
        def mock_response(*args, **kwargs):
            with requests_mock.Mocker(real_http=True) as mock:
                mock.register_uri(
                    "POST",
                    r"https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search",
                    status_code=200,
                    json=fake_response({'offset': {'type': 'int', 'name': 'offset'}, 'limit': {'type': 'int', 'name': 'limit'}, 'responseCode': {'type': 'int', 'name': 'responseCode'}, 'count': {'type': 'int', 'name': 'count'}, 'data': {'type': 'list', 'items': {'name': {'type': 'str', 'position': 0, 'description': 'Datastore name (identifier) '}, 'description': {'type': 'str', 'position': 0, 'description': 'Datastore description '}, 'dataType': {'type': 'str', 'position': 0, 'description': 'Data type (MAP or LIST). Maps have keys with values, lists only have keys. ', 'enum': ['MAP', 'LIST']}, 'behaviourType': {'type': 'str', 'position': 0, 'description': 'Datastore behaviour. CENTRAL datastores define their data in the central Argus application. LOCAL and DISTRIBUTED datastores are used to control expiry and format for stores used in distributed processing. ', 'enum': ['LOCAL', 'DISTRIBUTED', 'CENTRAL']}, 'lastUpdatedTimestamp': {'type': 'int', 'position': 0, 'description': 'The timestamp for the last update of this datastore descriptor. '}, 'lastUpdatedByUser': {'id': {'type': 'int'}, 'customerID': {'type': 'int'}, 'domain': {'$ref': '#/definitions/DomainInfo'}, 'userName': {'type': 'str'}, 'name': {'type': 'str'}, 'type': 'str', 'options': ['user', 'group']}, 'lifeTime': {'type': 'int', 'position': 0, 'description': 'For datastores with expireData, the lifeTime defines the time period (in milliseconds) the data will live after last put before being expired. '}, 'deleted': {'type': 'bool', 'default': False}, 'globalData': {'type': 'bool', 'position': 0, 'description': 'Datastores with globalData do not accept data per customer, but only to a common global store. ', 'default': False}, 'expireData': {'type': 'bool', 'position': 0, 'description': 'Datastores with expireData will automatically expire data which is older than lifeTime millis. ', 'default': False}}, 'name': 'data'}, 'metaData': {'type': 'dict', 'additionalProperties': {'type': 'dict'}, 'name': 'metaData'}, 'messages': {'type': 'list', 'items': {'message': {'type': 'str'}, 'messageTemplate': {'type': 'str'}, 'type': 'str', 'field': {'type': 'str'}, 'parameter': {'type': 'dict'}, 'timestamp': {'type': 'int'}, 'options': ['FIELD_ERROR', 'ACTION_ERROR', 'WARNING', 'NOTIFICATION', 'INFO']}, 'name': 'messages'}, 'currentPage': {'type': 'int', 'name': 'currentPage'}, 'size': {'type': 'int', 'name': 'size'}})
                )
                return function(*args, **kwargs)
            return mock_response
        return decorator

    def unauthorized(function):
        """Mock https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search, respond with HTTP 401"""
        import requests_mock
        from argus_api.helpers.tests import fake_response
        def mock_response(*args, **kwargs):
            with requests_mock.Mocker(real_http=True) as mock:
                mock.register_uri(
                    "POST",
                    r"https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search",
                    status_code=401,
                    json=None
                )
                return function(*args, **kwargs)
            return mock_response
        return decorator

    def forbidden(function):
        """Mock https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search, respond with HTTP 403"""
        import requests_mock
        from argus_api.helpers.tests import fake_response
        def mock_response(*args, **kwargs):
            with requests_mock.Mocker(real_http=True) as mock:
                mock.register_uri(
                    "POST",
                    r"https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search",
                    status_code=403,
                    json=None
                )
                return function(*args, **kwargs)
            return mock_response
        return decorator

    def not_found(function):
        """Mock https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search, respond with HTTP 404"""
        import requests_mock
        from argus_api.helpers.tests import fake_response
        def mock_response(*args, **kwargs):
            with requests_mock.Mocker(real_http=True) as mock:
                mock.register_uri(
                    "POST",
                    r"https://portal.mnemonic.no/web/api/datastores/v1/descriptor/search",
                    status_code=404,
                    json=None
                )
                return function(*args, **kwargs)
            return mock_response
        return decorator