[docs]def success(function):
"""Mock https://portal.mnemonic.no/web/api/pdns/v3/\w+, 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(
"GET",
r"https://portal.mnemonic.no/web/api/pdns/v3/\w+",
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': {'createdTimestamp': {'type': 'int'}, 'lastUpdatedTimestamp': {'type': 'int'}, 'times': {'type': 'int'}, 'tlp': {'type': 'str', 'enum': ['white', 'green', 'amber', 'red']}, 'query': {'type': 'str'}, 'answer': {'type': 'str'}, 'minTtl': {'type': 'int'}, 'maxTtl': {'type': 'int'}, 'customer': {'id': {'type': 'int'}, 'name': {'type': 'str'}, 'shortName': {'type': 'str'}, 'domain': {'$ref': '#/definitions/DomainInfo'}}, 'lastSeenTimestamp': {'type': 'int', 'readOnly': True}, 'firstSeenTimestamp': {'type': 'int', 'readOnly': True}, 'rrclass': {'type': 'str', 'readOnly': True, 'enum': ['in']}, 'rrtype': {'type': 'str', 'readOnly': True, 'enum': ['a', 'aaaa', 'cname', 'dname', 'mx', 'naptr', 'ns', 'ptr', 'rp', 'soa', 'srv', 'txt']}}, '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
[docs]def unauthorized(function):
"""Mock https://portal.mnemonic.no/web/api/pdns/v3/\w+, 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(
"GET",
r"https://portal.mnemonic.no/web/api/pdns/v3/\w+",
status_code=401,
json=None
)
return function(*args, **kwargs)
return mock_response
return decorator
[docs]def forbidden(function):
"""Mock https://portal.mnemonic.no/web/api/pdns/v3/\w+, 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(
"GET",
r"https://portal.mnemonic.no/web/api/pdns/v3/\w+",
status_code=403,
json=None
)
return function(*args, **kwargs)
return mock_response
return decorator
[docs]def not_found(function):
"""Mock https://portal.mnemonic.no/web/api/pdns/v3/\w+, 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(
"GET",
r"https://portal.mnemonic.no/web/api/pdns/v3/\w+",
status_code=404,
json=None
)
return function(*args, **kwargs)
return mock_response
return decorator