def setUp(self):
        # work around logger
        self.stream_handler = logging.StreamHandler(sys.stdout)
        logger.addHandler(self.stream_handler)
        logging.getLogger().info("# set up test for dwd")
        self.plugin = BasePlugin() #plugin()

        config = configparser.ConfigParser()
        config.read_file(codecs.open(r"./test/my_config.ini", encoding="utf-8"))
        self.dwd = self.readAndCreate(config, CONFIG_SECTION_MY)

        self.plugin.dwd = self.dwd
class Test_plugin(unittest.TestCase):
    def setUp(self):
        # work around logger
        self.stream_handler = logging.StreamHandler(sys.stdout)
        logger.addHandler(self.stream_handler)
        logging.getLogger().info("# set up test for dwd")
        self.plugin = BasePlugin() #plugin()

        config = configparser.ConfigParser()
        config.read_file(codecs.open(r"./test/my_config.ini", encoding="utf-8"))
        self.dwd = self.readAndCreate(config, CONFIG_SECTION_MY)

        self.plugin.dwd = self.dwd

    def tearDown(self):
        logging.getLogger().info("# tear down: test for dwd")
        if self.plugin:
            self.plugin = None

        # remove logger
        logger.removeHandler(self.stream_handler)

    def test_A_onStart(self):
        logging.getLogger().info("#fake start of plugin")
        #TODO call:
        self.plugin.onStart()

    def test_B_onHeartbeat(self):
        logging.getLogger().info("#fake heart beat")
        #TODO call:
        self.plugin.onStart()
        self.plugin.onHeartbeat()

    def test_C_onStop(self):
        logging.getLogger().info("#fake stop")
        #TODO call:
        self.plugin.onStop()

    def readAndCreate(self, aConfig, aSection):
        """creates a dwd object based on config

        Args:
            aConfig ([type]): [configuration holding the settings]

        Returns:
            [dwd]: [dwd object]
        """
        self.assertTrue(
            aConfig.has_section(aSection),
            "we need this set up:  " + aSection,
        )
        cellId = aConfig.get(aSection, "cellId")
        region = aConfig.get(aSection, "region")
        Parameters['Mode1'] = cellId
        Parameters['Mode2'] = region
        Parameters['Mode3'] = "event"
        rT: RegionType = RegionType.getByName(region)
        aDwd = Dwd(dwdWarnCellId=cellId, regionType=rT)

        return aDwd
Пример #3
0
def runtest():

    fakeDomoticz.Start()

    plugin = BasePlugin()
    plugin.onStart()
    # plugin.onCommand(1, '', '', '')
    plugin.onHeartbeat()
    plugin.onHeartbeat()
    plugin.onStop()
 def createPlugin(self):
     plugin = BasePlugin()  #plugin()
     config = configparser.ConfigParser()
     config.read_file(codecs.open(r"./test/my_config.ini",
                                  encoding="utf-8"))
     self.assertTrue(
         config.has_section(CONFIG_SECTION),
         "we need this config to connect to fritzBox",
     )
     Parameters["Mode1"] = config.get(CONFIG_SECTION, "ip")
     Parameters["Username"] = config.get(CONFIG_SECTION, "user")
     Parameters["Password"] = config.get(CONFIG_SECTION, "pw")
     Parameters["Mode5"] = None
     Parameters["Mode6"] = 'Debug'
     return plugin
Пример #5
0
 def __init__(self, **kwargs):
     BasePlugin.__init__(self, name=__file__)
     self.kwargs = kwargs
Пример #6
0
class Test_plugin(unittest.TestCase):
    def setUp(self):
        # work around logger
        self.stream_handler = logging.StreamHandler(sys.stdout)
        logger.addHandler(self.stream_handler)
        logging.getLogger().info("# set up test for bsr")
        self.plugin = BasePlugin()  #plugin()

        config = configparser.ConfigParser()
        config.read_file(codecs.open(r"./test/my_config.ini",
                                     encoding="utf-8"))
        self.bsr = self.readAndCreate(config, CONFIG_SECTION_MY)

        self.plugin.bsr = self.bsr

    def tearDown(self):
        logging.getLogger().info("# tear down: test for bsr")
        if self.plugin:
            self.plugin = None

        # remove logger
        logger.removeHandler(self.stream_handler)

    def test_onStart(self):
        logging.getLogger().info("#fake start of plugin")
        #TODO call:
        self.plugin.onStart()

    def test_onHeartbeat(self):
        logging.getLogger().info("#fake heart beat")
        #TODO call:
        self.plugin.onHeartbeat()

    def test_onStop(self):
        logging.getLogger().info("#fake stop")
        #TODO call:
        self.plugin.onStop()

    def readAndCreate(
        self,
        aConfig,
        aSection,
        showHouseholdWaste: bool = True,
        showRecycleWaste: bool = True,
        showBioWaste: bool = True,
        showXmasWaste: bool = False,
        debugResponse: bool = False,
    ):
        """creates a bsr object based on config

        Args:
            aConfig ([type]): [configuration holding the address]

        Returns:
            [Bsr]: [bsr object]
        """
        self.assertTrue(
            aConfig.has_section(aSection),
            "we need this set up:  " + aSection,
        )
        str = aConfig.get(aSection, "street")
        zip = aConfig.get(aSection, "zip")
        nr = aConfig.get(aSection, "nr")

        aBsr = Bsr(
            street=str,
            zipCode=zip,
            houseNumber=nr,
        )
        return aBsr