def test_is_url(self): """ Test Check.is_url() for the case that the URL is valid. """ expected = True for domain in self.valid_domain: to_test = "http://{0}/helloworld".format(domain) actual = Check(to_test).is_url() self.assertEqual(expected, actual, to_test) to_test = "http://{0}:8080/helloworld".format(domain) actual = Check(to_test).is_url() self.assertEqual(expected, actual)
def __init__(self, **args): # We initiate our list of optional arguments with their default values. optional_arguments = { "domain_or_ip_to_test": None, "file_path": None, "url_to_test": None, "url_file": None, "modulo_test": False, "link_to_test": None, } # We initiate our optional_arguments in order to be usable all over the # class. for (arg, default) in optional_arguments.items(): setattr(self, arg, args.get(arg, default)) # We initiate a variable in order to avoid having to recall/declare # Status() over and over. self.status = Status() # We initiate a variable in order to avoid having to recall/declare # Check() over and over. self.checker = Check() # We initiate a variable in order to avoid having to recall/declare # Percentage() over and over. self.percentage = Percentage() # We initiate a variable in order to avoid having to recall/declare # URL() over and over. self.url_status = URL() # We initiate a variable in order to avoid having to recall/declare # Mining() over and over. self.mining = Mining() # We initiate a variable in order to avoid having to recall/declare # AutoContinue() over and over. self.auto_continue = None # We initiate a variable in order to avoid having to recall/declare # Syntax() over and over. self.syntax_status = Syntax() # We initiate a variable in order to avoid having to recall/declare # Inactive() over and over. self.inactive_database = Inactive() # We manage the entries. self._entry_management()
def test_is_domain_valid_not_valid(self): """ Test Check().is_domain_valid() for the case that we meet invalid domains. """ expected = False for domain in self.not_valid_domain: PyFunceble.INTERN["to_test"] = domain actual = Check().is_domain_valid() self.assertEqual(expected, actual, msg="%s is valid." % domain) actual = Check(PyFunceble.INTERN["to_test"]).is_domain_valid() self.assertEqual(expected, actual, msg="%s is valid." % domain) del PyFunceble.INTERN["to_test"]
def test_is_domain_valid(self): """ Test Check().is_domain_valid() for the case that domains are valid. """ expected = True for domain in self.valid_domain: PyFunceble.INTERN["to_test"] = domain actual = Check().is_domain_valid() self.assertEqual(expected, actual, msg="%s is invalid." % domain) actual = Check(PyFunceble.INTERN["to_test"]).is_domain_valid() self.assertEqual(expected, actual, msg="%s is invalid." % domain) del PyFunceble.INTERN["to_test"]
def test_is_url_valid(self): """ Test URL.is_url_valid() for the case that the URL is valid. """ expected = True for domain in self.valid_domain: PyFunceble.INTERN["to_test"] = "http://%s/helloworld" % domain actual = Check().is_url_valid() self.assertEqual(expected, actual) actual = Check(PyFunceble.INTERN["to_test"]).is_url_valid() self.assertEqual(expected, actual) del PyFunceble.INTERN["to_test"]
def get(cls): # pragma: no cover """ Execute the logic behind the URL handling. :return: The status of the URL. :rtype: str """ if Check().is_url_valid() or PyFunceble.CONFIGURATION["local"]: # * The url is valid. # or # * We are testing in/for a local or private network. if "current_test_data" in PyFunceble.INTERN: PyFunceble.INTERN["current_test_data"][ "url_syntax_validation"] = True # We initiate the HTTP status code. PyFunceble.INTERN.update({"http_code": HTTPCode().get()}) # We initiate the list of active status code. active_list = [] active_list.extend(PyFunceble.HTTP_CODE["list"]["potentially_up"]) active_list.extend(PyFunceble.HTTP_CODE["list"]["up"]) # We initiate the list of inactive status code. inactive_list = [] inactive_list.extend( PyFunceble.HTTP_CODE["list"]["potentially_down"]) inactive_list.append("*" * 3) if PyFunceble.INTERN["http_code"] in active_list: # The extracted HTTP status code is in the list of active list. # We handle and return the up status. return URLStatus(PyFunceble.STATUS["official"]["up"]).handle() if PyFunceble.INTERN["http_code"] in inactive_list: # The extracted HTTP status code is in the list of inactive list. # We handle and return the down status. return URLStatus( PyFunceble.STATUS["official"]["down"]).handle() # The extracted HTTP status code is not in the list of active nor invalid list. if "current_test_data" in PyFunceble.INTERN: # The end-user want more information whith his test. # We update the url_syntax_validation index. PyFunceble.INTERN["current_test_data"][ "url_syntax_validation"] = False # We handle and return the invalid down status. return URLStatus(PyFunceble.STATUS["official"]["invalid"]).handle()
def test_is_subdomain_valid(self): """ Test Check().is_subdomain() for the case subdomains are valid. """ valid = [ "hello_world.world.com", "hello_world.world.hello.com", "hello.world_hello.world.com", "hello.world.hello.com", "hello_.world.eu.com", "_world.hello.eu.com", "_world_.hello.eu.com", "_hello-beautiful-world_.wold.eu.com", "_hello_world_.hello.eu.com", "_hello.abuse.co.za", "_hello_.abuse.co.za", "_hello._world.abuse.co.za", "_hello-world.abuse.co.za", "_hello_world_.abuse.co.za", "hello_world.abuse.co.za", "hello-.abuse.co.za", ] expected = True for domain in valid: PyFunceble.INTERN["to_test"] = domain actual = Check().is_subdomain() self.assertEqual(expected, actual, msg="%s is not a subdomain." % domain) actual = Check(PyFunceble.INTERN["to_test"]).is_subdomain() self.assertEqual(expected, actual, msg="%s is not a subdomain." % domain) actual = Check().is_subdomain(PyFunceble.INTERN["to_test"]) self.assertEqual(expected, actual, msg="%s is not a subdomain." % domain) del PyFunceble.INTERN["to_test"]
def test_is_reserved_ipv4_wrong_input(self): """ Test Check().is_reserved_ipv4() for the case that non IP dataset is given.. """ expected = False for to_check in pyf_test_dataset.VALID_DOMAINS: actual = Check(to_check).is_reserved_ipv4() self.assertEqual(expected, actual)
def test_is_reserved_ip_domain(self): """ Test Check().is_reserved_ip() for the case that domains are given. """ expected = False for to_check in pyf_test_dataset.VALID_DOMAINS: actual = Check(to_check).is_reserved_ip() self.assertEqual(expected, actual, msg="%s is a reserved IP." % to_check)
def test_is_ip_range_not(self): """ Test Check().is_ip_range() for the case that the IP is not a range. """ expected = False valid = ["15.47.85.65", "45.66.255.240", "github.com"] for ip_to_test in valid: actual = Check().is_ip_range(ip_to_test) self.assertEqual(expected, actual, msg="%s is an IP range." % ip_to_test) actual = Check(ip_to_test).is_ip_range() self.assertEqual(expected, actual, msg="%s is an IP range." % ip_to_test)
def test_is_ip_valid_not_valid(self): """ Test Check().is_ip_valid() for the case that the IP is not valid. """ expected = False invalid = ["google.com", "287.468.45.26", "245.85.69.17:8081"] for ip_to_test in invalid: PyFunceble.INTERN["to_test"] = ip_to_test actual = Check().is_ip_valid() self.assertEqual(expected, actual, msg="%s is valid." % ip_to_test) actual = Check(PyFunceble.INTERN["to_test"]).is_ip_valid() self.assertEqual(expected, actual, msg="%s is valid." % ip_to_test) del PyFunceble.INTERN["to_test"]
def test_is_reserved_ipv4_wrong_input(self): """ Test Check().is_reserved_ipv4() for the case that non IP dataset is given.. """ expected = False for to_check in self.valid_domain: actual = Check(to_check).is_reserved_ipv4() self.assertEqual(expected, actual)
def test_is_ip_range_domain(self): """ Test Check().is_ip_range() for the case that only domains are given. """ expected = False for domain in pyf_test_dataset.VALID_DOMAINS: to_check = domain actual = Check(to_check).is_ip_range() self.assertEqual(expected, actual, "%s an IP range." % domain)
def test_is_ip_valid(self): """ Test Check().is_ip_valid() for the case that the IP is valid. """ expected = True valid = ["15.47.85.65", "45.66.255.240"] for ip_to_test in valid: actual = Check().is_ip_valid(ip_to_test) self.assertEqual(expected, actual, msg="%s is invalid." % ip_to_test) actual = Check(ip_to_test).is_ip_valid() self.assertEqual(expected, actual, msg="%s is invalid." % ip_to_test)
def test_is_ipv6(self): """ Test Check().is_ipv6() for the case that the IP is valid. """ expected = True for given_ip in pyf_test_dataset.VALID_IPV6: actual = Check(given_ip).is_ipv6() self.assertEqual(expected, actual, msg="%s is invalid." % given_ip)
def test_is_reserved_ipv4(self): """ Test Check().is_reserved_ipv4(). """ reserved = [ "0.45.23.59", "10.39.93.13", "100.64.35.85", "127.57.91.13", "169.254.98.65", "172.16.17.200", "192.0.0.145", "192.0.2.39", "192.168.21.99", "192.175.48.25", "192.31.196.176", "192.52.193.245", "192.88.99.30", "198.18.145.234", "198.51.100.212", "203.0.113.103", "224.134.13.24", "240.214.30.11", "255.255.255.255", ] not_reserved = ["hello.world", "::1", "45.34.29.15"] for subject in reserved: expected = True actual = Check(subject).is_reserved_ipv4() self.assertEqual(expected, actual, "{0} is not reserved.".format(repr(subject))) for subject in not_reserved: expected = False actual = Check(subject).is_reserved_ipv4() self.assertEqual(expected, actual, "{0} is reserved.".format(repr(subject)))
def test_is_url_not_valid(self): """ Test Check.is_url() for the case that the URL is not valid. """ expected = False for domain in self.not_valid_domain: to_check = "https://{0}/hello_world".format(domain) actual = Check(to_check).is_url() self.assertEqual(expected, actual)
def test_is_ipv4_range(self): """ Test Check().is_ipv4_range() for the case that the IP is a range. """ expected = True for given_ip in pyf_test_dataset.VALID_IPV4_RANGES: to_check = given_ip actual = Check(to_check).is_ipv4_range() self.assertEqual(expected, actual, msg="%s is not an IP range." % given_ip)
def test_is_ipv6_range_not_valid(self): """ Test Check().is_ipv6_range() for the case that the IP is not a range. """ expected = False for given_ip in pyf_test_dataset.NOT_VALID_IPV6_RANGES: to_check = given_ip actual = Check(to_check).is_ipv6_range() self.assertEqual(expected, actual, msg="%s is not an IP range." % given_ip)
def test_is_reserved_ipv6(self): """ Test Check().is_reserved_ipv6() for the case that a reserved IP is given. """ for subject in pyf_test_dataset.RESERVED_IPV6: expected = True actual = Check(subject).is_reserved_ipv6() self.assertEqual( expected, actual, "{0} is not IPv6 reserved.".format(repr(subject)) )
def test_is_not_reserved_ipv6(self): """ Test Check().is_reserved_ipv6() for the case that is not a reserved IP. """ expected = False for subject in pyf_test_dataset.NOT_RESERVED_IPV6: to_check = subject actual = Check(to_check).is_reserved_ipv6() self.assertEqual(expected, actual)
def test_is_ipv4(self): """ Test Check().is_ipv4() for the case that the IP is valid. """ expected = True valid = ["15.47.85.65", "45.66.255.240", "255.45.65.0/24"] for given_ip in valid: actual = Check(given_ip).is_ipv4() self.assertEqual(expected, actual, msg="%s is invalid." % given_ip)
def test_is_url_get_base(self): """ Test Check.is_url() for the case that we want to extract the url base. """ for domain in self.valid_domain: to_check = "http://{0}/hello_world".format(domain) expected = domain actual = Check(to_check).is_url(return_base=True) self.assertEqual(expected, actual)
def test_is_url_protocol_not_supported(self): """ Test Check.is_url() for the case that the URL protocol is not supported nor given. """ expected = False for domain in self.not_valid_domain: to_check = "{0}/hello_world".format(domain) actual = Check(to_check).is_url() self.assertEqual(expected, actual)
def test_is_not_reserved_ipv4(self): """ Test Check().is_reserved_ipv4() for the case that it is not a reserved IP. """ expected = False for subject in pyf_test_dataset.NOT_RESERVED_IPV4: actual = Check(subject).is_reserved_ipv4() self.assertEqual( expected, actual, "{0} is IPv4 reserved.".format(repr(subject)) )
def test_is_ipv6_range_not_valid(self): """ Test Check().is_ipv6_range() for the case that the IP is not a range. """ expected = False not_valid = ["2001:db8::/129", "github.com", "2001:db8:a::"] for given_ip in not_valid: to_check = given_ip actual = Check(to_check).is_ipv6_range() self.assertEqual(expected, actual, msg="%s is not an IP range." % given_ip)
def test_is_ipv4_range_not_valid(self): """ Test Check().is_ipv4_range() for the case that the IP is not a range. """ expected = False not_valid = ["15.47.85.65", "45.66.255.240", "github.com"] for given_ip in not_valid: to_check = given_ip actual = Check(to_check).is_ipv4_range() self.assertEqual(expected, actual, msg="%s is an IP range." % given_ip)
def test_is_ipv4_range(self): """ Test Check().is_ipv4_range() for the case that the IP is a range. """ expected = True valid = ["255.45.65.0/24", "255.45.65.6/18"] for given_ip in valid: to_check = given_ip actual = Check(to_check).is_ipv4_range() self.assertEqual(expected, actual, msg="%s is not an IP range." % given_ip)
def test_is_domain_not_valid(self): """ Test Check().is_domain() for the case that we meet invalid domains. """ expected = False for domain in self.not_valid_domain: to_check = domain actual = Check(to_check).is_domain() self.assertEqual(expected, actual, msg="%s is valid." % domain)
def test_is_domain(self): """ Test Check().is_domain() for the case that domains are valid. """ expected = True for domain in self.valid_domain: to_check = domain actual = Check(to_check).is_domain() self.assertEqual(expected, actual, msg="%s is invalid." % domain)