Esempio n. 1
0
def scan():
    transport = TransportBluepy()
    registry = SkoobotRegistry()

    rawDevices = transport.findRawDevices()
    skoobots = []
    for device in rawDevices:
        scanList = device.getScanData()
        for scanItem in scanList:
            if scanItem[0] == 9 and scanItem[2] == "Skoobot":
                skoobots.append(device)

    for skoobot in skoobots:
        # print(transport.rawDeviceInfoStr(skoobot))
        addr = skoobot.addr
        registry.addSkoobot(addr)
        name = registry.getSkoobotsByAddress(addr)[0][1]
        if registry.getDefaultName() == None:
            registry.setDefault(name)
        defaultText = " (default)" if registry.getDefaultName() == name else ""
        msg = "Added Skoobot {0:s} to registry with name {1:s}{2:s}"
        print(msg.format(addr, name, defaultText))
    print("Saving to list of Skoobots to registry {0:s}".format(
        registry.registryPath))
    registry.save()
    shutil.chown(registry.registryPath, os.getlogin())
Esempio n. 2
0
    def testBug8(self):
        """
        Tests the resolution of bug #8
        """
        badDefaultName = "gremlin"
        registry = SkoobotRegistry(self.tempPath)
        with self.subTest("Setting bad default"):
            oldDefault = registry.getDefaultName()
            with self.assertRaises(ValueError):
                registry.setDefault(badDefaultName)
            self.assertEqual(oldDefault, registry.getDefaultName())

        with self.subTest("Loading bad default"):
            self.registryDict["default"] = badDefaultName
            with open(self.tempPath, "w") as registryFile:
                json.dump(self.registryDict, registryFile, indent=4)
            registry.load()
            self.assertEqual(None, registry.getDefaultName())

        with self.subTest("Loading good default"):
            self.registryDict["default"] = self.skooName
            with open(self.tempPath, "w") as registryFile:
                json.dump(self.registryDict, registryFile, indent=4)
            registry.load()
            self.assertEqual(self.skooName, registry.getDefaultName())
Esempio n. 3
0
    def testSave(self):
        """
        Tests for the save() method

        Make sure that save() works, except when the registry is
        marked invalid.
        """
        registry = SkoobotRegistry(self.tempPath)
        altSkooAddr = "aa:aa:aa:aa:aa:aa"
        altSkooName = "Alt"
        extraSkooAddr = "ee:ee:ee:ee:ee:ee"
        extraSkooName = "Extra"

        with self.subTest("Undo alterations"):
            registry.addSkoobot(altSkooAddr, altSkooName)
            registry.setDefault(altSkooAddr)
            self.assertEqual(4, len(registry.registry))

            registry.load()

            self.assertEqual(3, len(registry.registry))
            self.assertEqual(self.skooName, registry.getDefaultName())

        with self.subTest("Alter and save"):
            registry.addSkoobot(altSkooAddr, altSkooName)
            registry.setDefault(altSkooAddr)
            self.assertEqual(4, len(registry.registry))

            # Save the state with the AltSkootbot entry
            registry.save()

            registry.addSkoobot(extraSkooAddr, extraSkooName)
            registry.setDefault(extraSkooAddr)
            self.assertEqual(5, len(registry.registry))
            self.assertEqual(extraSkooName, registry.getDefaultName())

            # Restore to the save() state
            registry.load()

            self.assertEqual(4, len(registry.registry))
            self.assertEqual(altSkooName, registry.getDefaultName())

        with self.subTest("Don't save invalid"):
            registry.addSkoobot(extraSkooAddr, altSkooName)
            registry.setDefault(extraSkooAddr)
            self.assertEqual(5, len(registry.registry))
            registry.valid = False

            # Fail to save the state with the Extra entry
            registry.save()

            # Restore to the previous save() state
            registry.load()

            self.assertEqual(4, len(registry.registry))
            self.assertEqual(altSkooName, registry.getDefaultName())
Esempio n. 4
0
    def testSetDefault(self):
        """
        Test for method setDefault()

        Method sets the default name. It takes one parameter, which is either
        the address or the name.
        """
        registry = SkoobotRegistry(self.tempPath)

        registry.setDefault(self.skooDupName)
        self.assertEqual(self.skooDupName, registry.getDefaultName())

        registry.setDefault(self.skooAddr)
        self.assertEqual(self.skooName, registry.getDefaultName())

        registry.setDefault(self.skooDupAddr1)
        self.assertEqual(self.skooDupName, registry.getDefaultName())
Esempio n. 5
0
    def testBug11(self):
        """
        Tests the resolution of bug #11

        "Registry setDefault() does strange things if given a
        list of lists as a parameter"
        Check that it raises a TypeError when called with
        something other than String or None.
        It turns out that the error only triggers with tuples.
        """
        registry = SkoobotRegistry(self.tempPath)
        with self.subTest("Valid arguments"):
            registry.setDefault(None)
            self.assertEqual(None, registry.getDefaultName())

            registry.setDefault(self.skooName)
            self.assertEqual(self.skooName, registry.getDefaultName())

        with self.subTest("Invalid arguments"):
            with self.assertRaises(TypeError):
                registry.setDefault(("test", ))