Source code for api.reputation.v1.test_helpers.observation.add_observations


[docs]def success(function): """Mock https://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation, 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://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation", status_code=200, json=fake_response({'newCount': {'type': 'int', 'name': 'newCount'}, 'continueCount': {'type': 'int', 'name': 'continueCount'}, 'awakenCount': {'type': 'int', 'name': 'awakenCount'}, 'rejectedObservations': {'type': 'list', 'items': {'roleAlias': {'type': 'str', 'position': 0, 'description': 'Role alias '}, 'address': {'host': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'maskBits': {'type': 'int'}, 'ipv6': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'multicast': {'type': 'bool', 'default': False}, 'public': {'type': 'bool', 'default': False}, 'address': {'type': 'str', 'xml': {'attribute': True}, 'readOnly': True}}, 'domainName': {'fqdn': {'type': 'str'}}, 'firstSeen': {'type': 'int'}, 'lastSeen': {'type': 'int'}, 'observationCount': {'type': 'int'}, 'comment': {'type': 'str'}, 'rejectReasons': {'type': 'list', 'items': {'type': 'str'}}}, 'name': 'rejectedObservations'}, 'whitelistedObservations': {'type': 'list', 'items': {'roleAlias': {'type': 'str', 'position': 0, 'description': 'Role alias '}, 'address': {'host': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'maskBits': {'type': 'int'}, 'ipv6': {'type': 'bool', 'xml': {'attribute': True}, 'readOnly': True, 'default': False}, 'multicast': {'type': 'bool', 'default': False}, 'public': {'type': 'bool', 'default': False}, 'address': {'type': 'str', 'xml': {'attribute': True}, 'readOnly': True}}, 'domainName': {'fqdn': {'type': 'str'}}, 'firstSeen': {'type': 'int'}, 'lastSeen': {'type': 'int'}, 'observationCount': {'type': 'int'}, 'comment': {'type': 'str'}, 'rejectReasons': {'type': 'list', 'items': {'type': 'str'}}}, 'name': 'whitelistedObservations'}}) ) return function(*args, **kwargs) return mock_response return decorator
[docs]def unauthorized(function): """Mock https://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation, 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://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation", status_code=401, json=None ) return function(*args, **kwargs) return mock_response return decorator
[docs]def forbidden(function): """Mock https://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation, 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://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation", status_code=403, json=None ) return function(*args, **kwargs) return mock_response return decorator
[docs]def not_found(function): """Mock https://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation, 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://osl-argus-trunk-web1.mnemonic.no/web/api/reputation/v1/observation", status_code=404, json=None ) return function(*args, **kwargs) return mock_response return decorator