def test_get_all_device_state(self): dal = DeviceStateDal() records = dal.get_all_device_state() device_state_list = [] for record in records: device_state_list.append(record.ch_name) self.assertEqual(len(records), 4) self.assertEqual(u'可用' in device_state_list, True) self.assertEqual(u'不可用' in device_state_list, True) self.assertEqual(u'报废中' in device_state_list, True) self.assertEqual(u'报废无' in device_state_list, True)
def setUp(self): super(DeviceStateDALTestCase, self).setUp() self.useFixture(DBConnectionFixture()) self.dbfixture = self.useFixture(DBFixture()) self.session = self.dbfixture.session self.dal = DeviceStateDal()
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')
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)
def get_device_state_id_by_ch_name(self, ch_name): dse = DeviceStateDal() device_state = dse.get_device_state_id_by_ch_name(ch_name) return self.actual_return_id_val(device_state)
def get_device_state_name_by_num(self, device_state_id): dse = DeviceStateDal() device_state = dse.get_device_state_name_by_id(device_state_id) return self.actual_return_ch_name_val(device_state)