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")
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
def test_get_ip_unexisting(self): domain = "." info("Requested domain - {}".format(domain)) ip = get_ip(domain) info("Returned ip: {}".format(ip)) assert_none(ip, "Check if result for get_ip is None")
def test_get_ip(self): domain = "google.com" info("Requested domain - {}".format(domain)) ip = get_ip(domain) info("Returned ip: {}".format(ip)) assert_true(ip.count('.') == 3, "Check if returned ip is correct ip")