示例#1
0
class Module03Test(unittest.TestCase):
    """
	Use this to setup your tests. This is where you may want to load configuration
	information (if needed), initialize class-scoped variables, create class-scoped
	instances of complex objects, initialize any requisite connections, etc.
	"""
    def setUp(self):
        self.config = ConfigUtil()
        self.config.loadConfig('../../../config/ConnectedDevicesConfig.props')
        self.tempsensor = TempSensorAdaptorTask()
        self.sensordata = SensorData()
        self.actuatordata = ActuatorData()
        self.sensordata.addValue(10)
        self.sensordata.addValue(15)
        self.sensordata.addValue(20)
        self.sensordata.addValue(25)
        self.sensordata.setName('Temperature')
        self.actuatordata.setCommand('Increasing')
        self.actuatordata.setName('SenseHat')
        self.sdmanager = SensorDataManager()

    """
	Use this to tear down any allocated resources after your tests are complete. This
	is where you may want to release connections, zero out any long-term data, etc.
	"""

    def tearDown(self):
        pass

    """
	Place your comments describing the test here.
	"""

    def testloadConfig(self):
        self.assertTrue(
            self.config.loadConfig(
                '../../../config/ConnectedDevicesConfig.props'))

    def testhasConfigData(self):
        self.assertTrue(self.config.hasConfigData())

    def testgetValue(self):
        self.assertEqual(self.config.getValue("smtp.cloud", "port"), '465')

    def testgetSensorData(self):
        assert self.tempsensor.getTemperature(
        ) > 0 and self.tempsensor.getTemperature() < 30

    def testgetAverageValue(self):
        assert self.sensordata.getAverageValue(
        ) > 0 and self.sensordata.getAverageValue() < 30

    def testgetCount(self):
        self.assertEqual(self.sensordata.getCount(), 4)

    def testgetCurrentValue(self):
        assert self.sensordata.getCurrentValue(
        ) > 0 and self.sensordata.getCurrentValue() < 30

    def testMinValue(self):
        assert self.sensordata.getMinValue(
        ) >= 0 and self.sensordata.getMinValue() < 30

    def testMaxValue(self):
        assert self.sensordata.getMaxValue(
        ) > 0 and self.sensordata.getMaxValue() < 30

    def testName(self):
        self.assertEqual(self.sensordata.getName(), 'Temperature')

    def testgetCommand(self):
        self.assertEqual(self.actuatordata.getCommand(), 'Increasing')

    def testName2(self):
        self.assertEqual(self.actuatordata.getName(), 'SenseHat')

    def testhandleSenseData(self):
        assert self.sdmanager.handleSensorData(self.sensordata) is not None
示例#2
0
class ConfigUtilTest(unittest.TestCase):

	"""
	Use this to setup your tests. This is where you may want to load configuration
	information (if needed), initialize class-scoped variables, create class-scoped
	instances of complex objects, initialize any requisite connections, etc.
	"""
	def setUp(self):
		self.configUtil = ConfigUtil()
		self.configUtil.loadConfig("../../../config/ConnectedDevicesConfig.props")
		pass

	"""
	Use this to tear down any allocated resources after your tests are complete. This
	is where you may want to release connections, zero out any long-term data, etc.
	"""
	def tearDown(self):
		pass
	
	"""
	Tests retrieval of a boolean property.
	"""
	def testGetBooleanProperty(self):
		# TODO: implement this
		pass
	
	"""
	Tests retrieval of an integer property.
	"""
	def testGetIntegerProperty(self):
		# TODO: implement this
		self.assertTrue(isint(int(self.configUtil.getValue("smtp.cloud", "port"))),"Returned "+ str(type(self.configUtil.getValue("smtp.cloud", "port"))) )
		pass
	
	"""
	Tests retrieval of a string property.
	"""
	def testGetProperty(self):
		# TODO: implement this
		self.assertEqual("smtp.gmail.com",self.configUtil.getValue("smtp.cloud", "host"),"No value returned")
		pass
	
	"""
	Tests if a property exists.
	"""
	def testHasProperty(self):
		# TODO: implement this
		
		self.assertTrue(self.configUtil.cp.has_option("smtp.cloud", "host"),"No value returned")
		pass

	"""
	Tests if a section exists.
	"""
	def testHasSection(self):
		self.assertTrue(self.configUtil.cp.has_section("smtp.cloud"),"No sections present")
		# TODO: implement this
		pass
	
	"""
	Tests if the configuration is loaded.
	"""
	def testIsConfigDataLoaded(self):
		if self.configUtil.hasConfigData():
			pass
		else:
			self.fail("Configuration data not loaded.")
		pass