Ejemplo n.º 1
0
class DeviceStateDALTestCase(TestCase):
    def setUp(self):
        super(DeviceStateDALTestCase, self).setUp()
        self.useFixture(DBConnectionFixture())
        self.dbfixture = self.useFixture(DBFixture())
        self.session = self.dbfixture.session
        self.dal = DeviceStateDal()

    def tearDown(self):
        super(DeviceStateDALTestCase, self).tearDown()
        self.session.execute('delete from dt_device_state')

    def test_get_all_device_state(self):
        ret = self.dal.get_all_device_state()
        self.assertEqual(len(ret), 2)

    def test_add_device_state(self):
        ret = self.dal.add_device_state('abc')
        self.assertEqual(ret, True)
        self.assertEqual(len(self.dal.get_all_device_state()), 3)

    def test_del_device_state(self):
        ret = self.dal.add_device_state('abc')
        self.assertEqual(ret, True)
        self.assertEqual(len(self.dal.get_all_device_state()), 3)
        ret = self.dal.del_device_state('abc')
        self.assertTrue(ret)

    def test_update_device_state(self):
        ret = self.dal.add_device_state('abc')
        self.assertEqual(ret, True)
        self.assertEqual(len(self.dal.get_all_device_state()), 3)
        ret = self.dal.del_device_state('abc1')
        self.assertTrue(ret)

    def test_get_device_state_id_by_ch_name(self):
        ret = self.dal.get_device_state_id_by_ch_name('ch_name_1')
        self.assertEqual(ret.ch_name, 'ch_name_1')

    def test_get_device_state_name_by_id(self):
        ret = self.dal.get_device_state_id_by_ch_name('ch_name_2')
        id = ret.id
        device_state = self.dal.get_device_state_name_by_id(id)
        self.assertEqual(device_state.ch_name, 'ch_name_2')
Ejemplo n.º 2
0
 def test_add_device_state(self):
     dal = DeviceStateDal()
     new_type = u'啦啦啦'
     dal.add_device_state(new_type)
     self.assertEqual(len(dal.get_all_device_state()), 5)
     dal.del_device_state(new_type)