Esempio n. 1
0
    def test_InitalizeSCPD(self):
        results = Discover.discover(retries=2)
        self.assertTrue(len(results) > 0, "No UPnP host found at all.")

        # setup proxies for discovery call
        proxies = {}
        if defaults.test_httpsProxy:
            proxies = {"https": defaults.test_httpsProxy}

        if defaults.test_httpProxy:
            proxies = {"http": defaults.test_httpProxy}

        # pick the best device in the result list for later loads
        bestResult = None
        for result in results:
            if Discover.rateServiceTypeInResult(
                    result) > Discover.rateServiceTypeInResult(bestResult):
                bestResult = result

        # find the device again
        result = Discover.discoverParticularHost(bestResult.locationHost,
                                                 proxies=proxies,
                                                 retries=1)
        self.assertTrue(result is not None,
                        "Failed to discover: " + bestResult.locationHost)

        box = DeviceTR64(result.locationHost, result.locationPort,
                         result.locationProtocol)
        box.username = defaults.test_user
        box.password = defaults.test_pw
        box.httpProxy = defaults.test_httpProxy
        box.httpsProxy = defaults.test_httpsProxy

        # the discovery result contains the right URL to initialize device definitions
        box.loadDeviceDefinitions(result.location)
        # load the actions
        box.loadSCPD()

        # the following calls can fail if the device found has not all the definitions needed
        #
        self.assertTrue(
            len(box.deviceServiceDefinitions.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
        self.assertTrue(
            len(box.deviceInformations.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
        self.assertTrue(
            len(box.deviceSCPD.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
Esempio n. 2
0
 def test_deviceSetup(self):
     box = DeviceTR64("some")
     self.assertEqual(len(box.deviceServiceDefinitions), 0)
     box.setupTR64Device("fritz.box")
     self.assertTrue(len(box.deviceServiceDefinitions) > 0)
Esempio n. 3
0
 def test_Defaul(self):
     box = DeviceTR64("box")
     self.assertEqual(box.host, "box")
     self.assertEqual(box.port, 49000)
     self.assertEqual(box.protocol, "http")
Esempio n. 4
0
 def test_pw(self):
     box = DeviceTR64("some")
     self.assertEqual(box.password, "")
     box.password = "******"
     self.assertEqual(box.password, "abc123")
Esempio n. 5
0
 def test_username(self):
     box = DeviceTR64("some")
     self.assertEqual(box.username, "")
     box.username = "******"
     self.assertEqual(box.username, "abc")
Esempio n. 6
0
 def test_Encryption(self):
     box = DeviceTR64("some", protocol="https")
     self.assertEqual(box.host, "some")
     self.assertEqual(box.port, 49000)
     self.assertEqual(box.protocol, "https")
Esempio n. 7
0
 def test_Port(self):
     box = DeviceTR64("box", port=1234)
     self.assertEqual(box.host, "box")
     self.assertEqual(box.port, 1234)
     self.assertEqual(box.protocol, "http")
        })

    # resort making sure we start with the important one first
    sortedResults = sorted(hostResults[host],
                           key=lambda sortit: sortit["sortKey"],
                           reverse=True)

    # load all xml file definitions for this host
    loadedXMLFile = []
    for sResult in sortedResults:
        if sResult["result"].location not in loadedXMLFile:
            loadedXMLFile.append(sResult["result"].location)

            # get instance of device
            box = DeviceTR64(sResult["result"].locationHost,
                             sResult["result"].locationPort,
                             sResult["result"].locationProtocol)
            box.username = use_user
            box.password = use_pw
            box.httpProxy = use_httpProxy
            box.httpsProxy = use_httpsProxy

            try:
                # load the device definitions from the location which was in the result
                box.loadDeviceDefinitions(sResult["result"].location,
                                          timeout=use_timeout)
            except (requests.exceptions.ConnectTimeout,
                    requests.exceptions.ConnectionError,
                    requests.exceptions.ReadTimeout) as e:
                # it failed so we will have less service types later
                pass