def test_04_ReadDerived(self): l_icd = internetUtil._read_derived(self.m_xml.internet_sect) self.assertEqual(l_icd.ExternalIPv4, convert.str_to_long(TESTING_INTERNET_IPv4)) self.assertEqual(l_icd.ExternalIPv6, convert.str_to_long(TESTING_INTERNET_IPv6)) self.assertEqual(l_icd.LastChanged, DATETIME)
def test_01_Create(self): """ Create a JSON object for Internets. """ l_internet = internetAPI().read_internet_xml(self.m_pyhouse_obj) l_json = json_tools.encode_json(l_internet) # print(PrettyFormatAny.form(l_json, 'JSON', 70)) self.assertEqual(self.jsonPair(l_json, 'ExternalIPv4'), convert.str_to_long(TESTING_INTERNET_IPv4)) self.assertEqual(self.jsonPair(l_json, 'ExternalIPv6'), convert.str_to_long(TESTING_INTERNET_IPv6))
def test_13_WriteDerived(self): """ Write out the XML file for the location section """ l_internet = self.m_api.read_internet_xml(self.m_pyhouse_obj) l_xml = ET.Element('InternetSection') internetUtil._write_derived_xml(l_internet, l_xml) self.assertEqual(int(l_xml._children[0].text), convert.str_to_long(TESTING_INTERNET_IPv4)) self.assertEqual(int(l_xml._children[1].text), convert.str_to_long(TESTING_INTERNET_IPv6)) self.assertEqual(l_xml._children[2].text, str(DATETIME))
def test_14_WriteAllInternetXml(self): """ Write out the XML file for the location section """ l_internet = internetAPI().read_internet_xml(self.m_pyhouse_obj) l_xml = internetAPI().write_internet_xml(l_internet) self.assertEqual( l_xml.find('ExternalIPv6').text, str(convert.str_to_long(TESTING_INTERNET_IPv6)))
def get_ip_from_xml(p_xml, p_name): """ Get either IPv4 or IPv6 from the xml file Return a (very) long Integer for the result """ l_field = XML.get_any_field(p_xml, p_name) l_long = convert.str_to_long(l_field) return l_long
def cb_parse_page(self, p_ip_page): """This gets the page with the IP in it and returns it. Different sites will need different page scraping to get the IP address. dotted quad IPs are converted to 4 byte addresses IP V-6 is not handled yet. @param p_ip_page: is the web page as a string """ # This is for Shawn Powers page - http://snar.co/ip l_quad = p_ip_page self.m_house_obj.Internet.ExternalIP = l_quad l_addr = convert.str_to_long(l_quad) LOG.info("Got External IP page for House:{0:}, Page:{1:}".format(self.m_house_obj.Name, p_ip_page)) callLater(self.m_house_obj.Internet.ExternalDelay, self.get_public_ip) return l_addr
def cb_parse_page(self, p_ip_page): """This gets the page with the IP in it and returns it. Different sites will need different page scraping to get the IP address. dotted quad IPs are converted to 4 byte addresses IP V-6 is not handled yet. @param p_ip_page: is the web page as a string """ # This is for Shawn Powers page - http://snar.co/ip l_quad = p_ip_page self.m_house_obj.Internet.ExternalIP = l_quad l_addr = convert.str_to_long(l_quad) LOG.info("Got External IP page for House:{0:}, Page:{1:}".format( self.m_house_obj.Name, p_ip_page)) callLater(self.m_house_obj.Internet.ExternalDelay, self.get_public_ip) return l_addr
def test_01_Config(self): l_config = self.m_api._read_xml_configuration(self.m_pyhouse_obj) self.assertEqual(l_config.ExternalIPv4, convert.str_to_long(TESTING_INTERNET_IPv4))
def _extract_ip(self, p_string): l_quad = p_string l_addr = convert.str_to_long(l_quad) return l_addr, l_quad
def test_05_RedAllInternet(self): l_obj = self.m_api.read_internet_xml(self.m_pyhouse_obj) self.assertEqual(l_obj.LocateUrls[0], TESTING_INTERNET_LOCATE_URL_1) self.assertEqual(l_obj.UpdateUrls[0], TESTING_INTERNET_UPDATE_URL_1) self.assertEqual(l_obj.ExternalIPv4, convert.str_to_long(TESTING_INTERNET_IPv4))
def test_14_WriteAllInternetXml(self): """ Write out the XML file for the location section """ l_internet = internetAPI().read_internet_xml(self.m_pyhouse_obj) l_xml = internetAPI().write_internet_xml(l_internet) self.assertEqual(l_xml.find('ExternalIPv6').text, str(convert.str_to_long(TESTING_INTERNET_IPv6)))
def test_02_GetIPv6(self): l_elem = self.m_api.get_ip_from_xml(self.m_fields, 'IPv6') self.assertEqual(l_elem, convert.str_to_long('1234:dead::beef'))
def test_01_GetIpV4(self): l_elem = self.m_api.get_ip_from_xml(self.m_fields, 'IPv4') self.assertEqual(l_elem, convert.str_to_long('98.76.45.123'))
def test_02_IPv6(self): l_ip = self.m_api.get_ip_from_xml(self.m_fields, 'IpV60') self.assertEqual(l_ip, convert.str_to_long(TESTING_XML_IPV6_0))