Пример #1
0
 def test_get_ip_details_reserved_range(self):
     ip = "127.0.0.1"
     info("Requested ip - {}".format(ip))
     details = get_ip_details(ip)
     assert_type(details, dict, "Check if returned results are of type dict")
     assert_not_empty(details, "Check if returned results are not empty")
     field = 'status'
     expected = 'reserved_range'
     assert_equal(details[field], expected, "Check if returned status is equal to expected one")
     field = 'ip'
     expected = ip
     assert_equal(details[field], expected, "Check if returned ip is equal to expected one")
Пример #2
0
def get_ip_details_by_url(url_body): 
    try:
        jsonschema.validate(url_body, details_url_schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise BadRequest(exc.message)

    domain = url_to_domain(url_body.get('url'))
    ip = ip_module.get_ip(domain)
    if ip:
        details = ip_module.get_ip_details(ip)
    else:
        return _no_data_response()

    response_text = {
        "details": details
    }
    return Response(json.dumps(
            response_text,
            default=_default_json_model
            ), 200, mimetype="application/json")
Пример #3
0
def get_ip_details(ip_body): 
    try:
        jsonschema.validate(ip_body, details_ip_schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise BadRequest(exc.message)
    
    ip = ip_body.get('ip')
    if not ip or ip == "":
        raise BadRequest('Wrong IP')

    details = ip_module.get_ip_details(ip)
    if not details:
        raise BadRequest('Wrong IP')

    response_text = {
        "details": details
    }
    return Response(json.dumps(
            response_text,
            default=_default_json_model
            ), 200, mimetype="application/json")
Пример #4
0
def add_ip(domain):
    """

    Returns:
        True if successfully added ip + add id
        False if not successful and None

    """
    try:
        ip = get_ip(domain)
        success = True
    except Exception as e:
        log.error(e)
        success = False
    if success and ip:
        details = get_ip_details(ip)
    else:
        return False, -1
    ip_id = IP.add_ip(ip, details.get('country', None),
                      details.get('asn', None))
    if ip_id:
        return True, ip_id
    else:
        return False, -1
Пример #5
0
 def test_get_ip_details_wrong_ip(self):
     ip = "abc"
     info("Requested ip - {}".format(ip))
     details = get_ip_details(ip)
     assert_none(details, "Check if returned results are empty/None")
Пример #6
0
 def test_get_ip_details(self):
     ip = "8.8.8.8"
     info("Requested ip - {}".format(ip))
     details = get_ip_details(ip)
     assert_type(details, dict, "Check if returned results are of type dict")
     assert_not_empty(details, "Check if returned results are not empty")