def SQLITE_DB_TEST_SETUP(): # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) cur = conn.cursor() __sql__ = None if __sql__ is None: from pymasarsqlite.db.masarsqlite import SQL else: sqlfile = open(__sql__) SQL = sqlfile.read() if SQL is None: print('SQLite script is empty. Cannot create SQLite db.') raise IOError('SQLite script is empty. Cannot create SQLite db.') else: cur.executescript(SQL) cur.execute("PRAGMA main.page_size= 4096;") cur.execute("PRAGMA main.default_cache_size= 10000;") cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;") cur.execute("PRAGMA main.synchronous=NORMAL;") cur.execute("PRAGMA main.journal_mode=WAL;") cur.execute("PRAGMA main.temp_store = MEMORY;") cur.execute('select name from sqlite_master where type=\'table\'') masarconf = 'SR_All_20140421' servicename = 'masar' pvgname = 'masarpvgroup' pvgdesc = 'this is my new pv group for masar service with same group name' pvs = [ "masarExample0000", "masarExample0001", "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest" ] res = savePvGroup(conn, pvgname, func=pvgdesc) res = saveGroupPvs(conn, pvgname, pvs) pvgroups = retrievePvGroups(conn) saveService(conn, servicename, desc='test desc') saveServiceConfig(conn, servicename, masarconf, system='SR', status='active', configversion=20140420, configdesc='test desc') res = saveServicePvGroup(conn, masarconf, [pvgname]) pvlist = retrieveServiceConfigPVs(conn, masarconf, servicename=servicename) results = retrieveServiceConfigs(conn, servicename, masarconf) conn.commit() conn.close() except sqlite3.Error, e: print("Error %s:" % e.args[0]) raise
def SQLITE_DB_TEST_SETUP(): # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) cur = conn.cursor() __sql__ = None if __sql__ is None: from pymasarsqlite.db.masarsqlite import SQL else: sqlfile = open(__sql__) SQL = sqlfile.read() if SQL is None: print ('SQLite script is empty. Cannot create SQLite db.') raise IOError('SQLite script is empty. Cannot create SQLite db.') else: cur.executescript(SQL) cur.execute("PRAGMA main.page_size= 4096;") cur.execute("PRAGMA main.default_cache_size= 10000;") cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;") cur.execute("PRAGMA main.synchronous=NORMAL;") cur.execute("PRAGMA main.journal_mode=WAL;") cur.execute("PRAGMA main.temp_store = MEMORY;") cur.execute('select name from sqlite_master where type=\'table\'') masarconf = 'SR_All_20140421' servicename = 'masar' pvgname = 'masarpvgroup' pvgdesc = 'this is my new pv group for masar service with same group name' pvs = ["masarExample0000", "masarExample0001", "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest"] res = savePvGroup(conn, pvgname, func=pvgdesc) res = saveGroupPvs(conn, pvgname, pvs) pvgroups = retrievePvGroups(conn) saveService(conn, servicename, desc='test desc') saveServiceConfig(conn, servicename, masarconf, system='SR', status='active', configversion=20140420, configdesc='test desc') res = saveServicePvGroup(conn, masarconf, [pvgname]) pvlist = retrieveServiceConfigPVs(conn, masarconf, servicename=servicename) results = retrieveServiceConfigs(conn, servicename, masarconf) conn.commit() conn.close() except sqlite3.Error, e: print ("Error %s:" % e.args[0]) raise
def testMultiGroup(self): # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) pvgname1 = 'masarpvgroup1' pvgdesc1 = 'this is my new pv group for masar service with same group name' pvs1 = ["masarExample0000", "masarExample0001", "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExampleFloatArray", "masarExample0004"] res1 = savePvGroup(conn, pvgname1, func=pvgdesc1) res1 = saveGroupPvs(conn, pvgname1, pvs1) pvgname2 = 'masarpvgroup2' pvgdesc2 = 'this is my new pv group for masar service with same group name' pvs2 = ["masarExample0000", "masarExample0001", "masarExample0002", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest"] res2 = savePvGroup(conn, pvgname2, func=pvgdesc2) res2 = saveGroupPvs(conn, pvgname2, pvs2) pvgroups = retrievePvGroups(conn) self.assertEqual(pvgroups[0][1], "masarpvgroup") self.assertEqual(pvgroups[1][1], "masarpvgroup1") self.assertEqual(pvgroups[2][1], "masarpvgroup2") pvgroups = retrieveGroupPvs(conn, 2) self.assertEqual(pvgroups[0][0], "masarExample0000") self.assertEqual(pvgroups[1][0], "masarExample0001") self.assertEqual(pvgroups[2][0], "masarExampleBoUninit") self.assertEqual(pvgroups[3][0], "masarExampleMbboUninit") self.assertEqual(pvgroups[4][0], "masarExample0002") self.assertEqual(pvgroups[5][0], "masarExample0003") self.assertEqual(pvgroups[6][0], "masarExample0004") self.assertEqual(pvgroups[7][0], "masarExampleFloatArray") pvgroups = retrieveGroupPvs(conn, 3) self.assertEqual(pvgroups[0][0], "masarExample0000") self.assertEqual(pvgroups[1][0], "masarExample0001") self.assertEqual(pvgroups[2][0], "masarExample0002") self.assertEqual(pvgroups[3][0], "masarExample0004") self.assertEqual(pvgroups[4][0], "masarExampleCharArray") self.assertEqual(pvgroups[5][0], "masarExampleShortArray") self.assertEqual(pvgroups[6][0], "masarExampleLongArray") self.assertEqual(pvgroups[7][0], "masarExampleStringArray") self.assertEqual(pvgroups[8][0], "masarExampleFloatArray") self.assertEqual(pvgroups[9][0], "masarExampleDoubleArray") self.assertEqual(pvgroups[10][0], "masarExampleMbboUninitTest") servicename = "masar" masarconf = "testconf" saveService(conn, servicename, desc='test desc') saveServiceConfig(conn, servicename, masarconf, system='SR', status='active', configversion=20140420, configdesc='test desc') res = saveServicePvGroup(conn, masarconf, [pvgname1, pvgname2]) conn.commit() conn.close() except: raise save_params = {'configname': 'testconf', 'servicename': 'masar'} res1 = self.mc.saveSnapshot(save_params) self.assertNotEqual(res1, None) self.assertNotEqual(res1, False) event_id = res1[0] retrieve_params = {'eventid': str(event_id)} result = self.mc.retrieveSnapshot(retrieve_params) self.assertNotEqual(result, None) self.assertNotEqual(result, False) expected_results = (('masarExample0000', # ChannelName 0 'masarExample0001', # ChannelName 1 'masarExampleBoUninit', # ChannelName 2 'masarExampleMbboUninit', # ChannelName 3 'masarExample0002', # ChannelName 4 'masarExample0003', # ChannelName 5 'masarExample0004', # ChannelName 6 'masarExampleCharArray', # ChannelName 7 'masarExampleShortArray', # ChannelName 8 'masarExampleLongArray', # ChannelName 9 'masarExampleStringArray', # ChannelName 10 'masarExampleFloatArray', # ChannelName 11 'masarExampleDoubleArray', # ChannelName 12 'masarExampleMbboUninitTest'), # ChannelName 13 (10, # 0000 Value 'string value', # 0001 Value '0', # BoUninit Value (appropriately returned as string, 1, # MbboUninit Value 'zero', # 0002 Value 'one', # 0003 Value 1.9, # 0004 Value (), # CharArray Value (), # ShortArray Value (), # LongArray Value (), # StringArray Value (), # FloatArrayValue (), # DoubleArray Value 1), # MbboUninitTest Value (5, 0, 0, 5, 0, 0, 6, 4, 1, 5, 0, 2, 6, 5), # DBR type (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), # isConnected (631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000), # SecondsPastEpoch (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # NanoSeconds (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # UserTag (0, 0, 3, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 0), # Severity (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), # Status ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM')) # Message self.assertSequenceEqual(result, expected_results)
def saveServicePvGroup(conn, configname, pvgroups): """ Assign pv groups to to a service config. >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> from pymasarsqlite.service.service import (saveService, retrieveServices) >>> from pymasarsqlite.service.serviceconfig import(saveServicePvGroup, retrieveServicePvGroups) >>> from pymasarsqlite.pvgroup.pvgroup import (savePvGroup, retrievePvGroups) >>> from pymasarsqlite.db.masarsqlite import (SQL) >>> cur = conn.cursor() >>> result = cur.executescript(SQL) >>> serviceName1 = 'masar' >>> serviceDesc1 = 'masar service description example' >>> saveService(conn, serviceName1, serviceDesc1) 1 >>> serviceName2 = 'model' >>> serviceDesc2 = 'model service description example' >>> saveService(conn, serviceName2, serviceDesc2) 2 >>> masarconf1 = 'orbit C01' >>> masardesc1 = 'BPM horizontal readout for storage ring C01' >>> masarconf2 = 'orbit C02' >>> masardesc2 = 'BPM horizontal readout for storage ring C02' >>> saveServiceConfig(conn, serviceName1, masarconf1, masardesc1) 1 >>> saveServiceConfig(conn, serviceName1, masarconf2, masardesc2) 2 >>> modelconf1 = 'model conf 1' >>> modeldesc1 = 'model conf desc 1' >>> modelconf2 = 'model conf 2' >>> modeldesc2 = 'model conf desc 2' >>> saveServiceConfig(conn, serviceName2, modelconf1, modeldesc1) 3 >>> saveServiceConfig(conn, serviceName2, modelconf2, modeldesc2) 4 >>> result = retrieveServiceConfigs(conn, servicename='masar', configname='orbit C01') >>> pvgname1 = 'masar1group' >>> pvgdesc1 = 'this is my first pv group for masar service' >>> savePvGroup(conn, pvgname1, func=pvgdesc1) [1] >>> pvgname2 = 'masar2group' >>> pvgdesc2 = 'this is my new pv group for masar service with same group name' >>> savePvGroup(conn, pvgname2, func=pvgdesc2) [2] >>> pvgroups = retrievePvGroups(conn) >>> for pvgroup in pvgroups: ... print (pvgroup[0], pvgroup[1]) 1 masar1group 2 masar2group >>> pvgroups = retrievePvGroups(conn, pvgname1) >>> for pvgroup in pvgroups: ... print (pvgroup[0], pvgroup[1]) 1 masar1group >>> pvgroups = retrievePvGroups(conn, pvgname2) >>> for pvgroup in pvgroups: ... print (pvgroup[0], pvgroup[1]) 2 masar2group >>> saveServicePvGroup(conn, masarconf1, [pvgname1, pvgname2]) [1, 2] >>> conn.close() """ if configname is None or len(pvgroups) == 0: raise Exception('service config name or service name is empty.') checkConnection(conn) # get service config id serviceconfigid = retrieveServiceConfigs(conn, configname=configname)[1][0] pvg_serviceconfig_ids = [] pvg_ids = [] for pvgroup in pvgroups: pvg_id = retrievePvGroups(conn, pvgroup) if len(pvg_id) > 0: pvg_ids.append(retrievePvGroups(conn, pvgroup)[0][0]) else: print('given pv group name (%s) does not exist.' % pvgroup) raise Exception('given pv group name (%s) does not exist.' % pvgroup) try: cur = conn.cursor() sql = 'select pvgroup__serviceconfig_id from pvgroup__serviceconfig where service_config_id = ?' cur.execute(sql, (serviceconfigid, )) result = cur.fetchone() if result is None: sql = 'insert into pvgroup__serviceconfig (pvgroup__serviceconfig_id, pv_group_id, service_config_id) values (?,?,?)' for pvg_id in pvg_ids: cur.execute(sql, (None, pvg_id, serviceconfigid)) pvg_serviceconfig_ids.append(cur.lastrowid) else: #pvg_serviceconfig_ids = pvg_serviceconfig_ids[0] raise Exception('Service config has associated pv groups already.') except sqlite3.Error, e: print('Error %s', e.arg[0]) raise
def testSaveSQLiteServiceConfigs(self): # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) cur = conn.cursor() __sql__ = None if __sql__ is None: from pymasarsqlite.db.masarsqlite import SQL else: sqlfile = open(__sql__) SQL = sqlfile.read() if SQL is None: print ('SQLite script is empty. Cannot create SQLite db.') raise IOError('SQLite script is empty. Cannot create SQLite db.') else: cur.executescript(SQL) cur.execute("PRAGMA main.page_size= 4096;") cur.execute("PRAGMA main.default_cache_size= 10000;") cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;") cur.execute("PRAGMA main.synchronous=NORMAL;") cur.execute("PRAGMA main.journal_mode=WAL;") cur.execute("PRAGMA main.temp_store = MEMORY;") cur.execute('select name from sqlite_master where type=\'table\'') masarconf = 'SR_All_20140421' servicename = 'masar' pvgname = 'masarpvgroup' pvgdesc = 'this is my new pv group for masar service with same group name' pvs = ["masarExample0000", "masarExample0001", "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest"] res = savePvGroup(conn, pvgname, func=pvgdesc) res = saveGroupPvs(conn, pvgname, pvs) pvgroups = retrievePvGroups(conn) saveService(conn, servicename, desc='test desc') conn.commit() conn.close() savePvGroups(self.parsed_json['pvgroups']) saveSQLiteServiceConfig(self.parsed_json) conn = sqlite3.connect(__sqlitedb__) pvgroups = retrievePvGroups(conn) self.assertEqual('BR_MG_Set_20130419', pvgroups[1][1]) self.assertEqual('Booster magnet power supply set points', pvgroups[1][2]) self.assertEqual(3, len(pvgroups[1][3].split(':'))) # Confirms correct date format self.assertEqual(3, len(pvgroups[1][3].split('-'))) # 2016-07-28 18:18:36 self.assertEqual(None, pvgroups[1][4]) configresult = retrieveServiceConfigs(conn) self.assertEqual('BR_MG_SCR_20130419', configresult[1][1]) self.assertEqual('BR ramping PS daily SCR setpoint', configresult[1][2]) self.assertEqual(3, len(configresult[1][3].split(':'))) # Confirms correct date format self.assertEqual(3, len(configresult[1][3].split('-'))) # 2016-07-28 18:18:36 self.assertEqual(None, configresult[1][4]) self.assertEqual('active', configresult[1][5]) except sqlite3.Error, e: print ("Error %s:" % e.args[0]) raise
def testConfiguration(self): channel = 'masarService' self.mc = masarClient.client(channelname=channel) # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) cur = conn.cursor() __sql__ = None if __sql__ is None: from pymasarsqlite.db.masarsqlite import SQL else: sqlfile = open(__sql__) SQL = sqlfile.read() if SQL is None: print('SQLite script is empty. Cannot create SQLite db.') sys.exit() else: cur.executescript(SQL) cur.execute("PRAGMA main.page_size= 4096;") cur.execute("PRAGMA main.default_cache_size= 10000;") cur.execute("PRAGMA main.locking_mode=EXCLUSIVE;") cur.execute("PRAGMA main.synchronous=NORMAL;") cur.execute("PRAGMA main.journal_mode=WAL;") cur.execute("PRAGMA main.temp_store = MEMORY;") cur.execute('select name from sqlite_master where type=\'table\'') masarconf = 'SR_All_20140421' servicename = 'masar' pvgname = 'masarpvgroup' pvgdesc = 'this is my new pv group for masar service with same group name' pvs = ["masarExampleDoubleArray"] res = savePvGroup(conn, pvgname, func=pvgdesc) self.assertEqual([1], res) res2 = saveGroupPvs(conn, pvgname, pvs) with self.assertRaises(Exception) as context: saveGroupPvs(conn, "badname", pvs) self.assertEqual( context.exception.message, 'pv group name (badname) is not unique, or not exist.') self.assertEqual([1], res2) pvgroups = retrievePvGroups(conn) self.assertEqual(5, len(pvgroups[0])) self.assertEqual(1, pvgroups[0][0]) self.assertEqual(pvgname, pvgroups[0][1]) self.assertEqual(pvgdesc, pvgroups[0][2]) self.assertNotEqual(None, pvgroups[0][3]) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(pvgroups[0][3].split('-'))) self.assertEqual(3, len(pvgroups[0][3].split(':'))) self.assertEqual(None, pvgroups[0][4]) test_desc = 'test desc' test_system = 'SR' test_status = 'active' test_version = 20140420 saveService(conn, servicename, desc=test_desc) with self.assertRaises(Exception) as context: saveServiceConfig(conn, "bad servicename", masarconf, system=test_system, status=test_status, configversion=test_version, configdesc=test_desc) self.assertEqual( "service with given name (bad servicename) does not exist.", context.exception.message) with self.assertRaises(Exception) as context: saveServiceConfig(conn, servicename, masarconf, system=test_system, status="bad status", configversion=test_version, configdesc=test_desc) self.assertEqual( "Service status has to be either active, or inactive", context.exception.message) saveServiceConfig(conn, servicename, masarconf, system=test_system, status=test_status, configversion=test_version, configdesc=test_desc) with self.assertRaises(Exception) as context: saveServiceConfig(conn, servicename, masarconf, system=test_system, status=test_status, configversion=test_version, configdesc=test_desc) self.assertEqual('service config exists already.', context.exception.message) with self.assertRaises( IndexError ): # TODO: Should this be a more specific error message? saveServicePvGroup(conn, "bad config", [pvgname]) with self.assertRaises(Exception) as context: res3 = saveServicePvGroup( conn, masarconf, ["bad pvgname"]) # this test prints a message to console self.assertEqual( "given pv group name (bad pvgname) does not exist.", context.exception.message) res3 = saveServicePvGroup(conn, masarconf, [pvgname]) self.assertEqual([1], res3) with self.assertRaises(Exception) as context: pvlist = retrieveServiceConfigPVs( conn, masarconf, servicename="bad servicename") pvlist = retrieveServiceConfigPVs(conn, masarconf, servicename=servicename) self.assertEqual( context.exception.message, 'Given service (bad servicename) does not exist.') self.assertEqual(pvs, pvlist) self.expected_column_names = ('config_idx', 'config_name', 'config_desc', 'config_create_date', 'config_version', 'status') results = retrieveServiceConfigs(conn, "bad servicename", masarconf) self.assertSequenceEqual(self.expected_column_names, results[0]) self.assertEqual(1, len(results)) # IE: no data returned self.assertEqual(len(self.expected_column_names), len(results[0])) results = retrieveServiceConfigs(conn, servicename, "bad conf") self.assertSequenceEqual(self.expected_column_names, results[0]) self.assertEqual(1, len(results)) # IE: no data returned self.assertEqual(len(self.expected_column_names), len(results[0])) results = retrieveServiceConfigs(conn, servicename, masarconf) # Label tests self.assertSequenceEqual(self.expected_column_names, results[0]) self.assertEqual(2, len(results)) self.assertEqual(len(self.expected_column_names), len(results[0])) # Data tests self.assertEqual(masarconf, results[1][1]) self.assertEqual(test_desc, results[1][2]) self.assertNotEqual(None, results[1][3]) self.assertEqual(1, results[1][0]) self.assertEqual(len(self.expected_column_names), len(results[1])) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(results[1][3].split('-'))) self.assertEqual(3, len(results[1][3].split(':'))) self.assertEqual(test_version, results[1][4]) self.assertEqual(test_status, results[1][5]) conn.commit() conn.close() except sqlite3.Error, e: print("Error %s:" % e.args[0]) raise
def testMultiGroup(self): # DB SETUP __sqlitedb__ = os.environ["MASAR_SQLITE_DB"] try: conn = sqlite3.connect(__sqlitedb__) pvgname1 = 'masarpvgroup1' pvgdesc1 = 'this is my new pv group for masar service with same group name' pvs1 = [ "masarExample0000", "masarExample0001", "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExampleFloatArray", "masarExample0004" ] res1 = savePvGroup(conn, pvgname1, func=pvgdesc1) res1 = saveGroupPvs(conn, pvgname1, pvs1) pvgname2 = 'masarpvgroup2' pvgdesc2 = 'this is my new pv group for masar service with same group name' pvs2 = [ "masarExample0000", "masarExample0001", "masarExample0002", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest" ] res2 = savePvGroup(conn, pvgname2, func=pvgdesc2) res2 = saveGroupPvs(conn, pvgname2, pvs2) pvgroups = retrievePvGroups(conn) self.assertEqual(pvgroups[0][1], "masarpvgroup") self.assertEqual(pvgroups[1][1], "masarpvgroup1") self.assertEqual(pvgroups[2][1], "masarpvgroup2") pvgroups = retrieveGroupPvs(conn, 2) self.assertEqual(pvgroups[0][0], "masarExample0000") self.assertEqual(pvgroups[1][0], "masarExample0001") self.assertEqual(pvgroups[2][0], "masarExampleBoUninit") self.assertEqual(pvgroups[3][0], "masarExampleMbboUninit") self.assertEqual(pvgroups[4][0], "masarExample0002") self.assertEqual(pvgroups[5][0], "masarExample0003") self.assertEqual(pvgroups[6][0], "masarExample0004") self.assertEqual(pvgroups[7][0], "masarExampleFloatArray") pvgroups = retrieveGroupPvs(conn, 3) self.assertEqual(pvgroups[0][0], "masarExample0000") self.assertEqual(pvgroups[1][0], "masarExample0001") self.assertEqual(pvgroups[2][0], "masarExample0002") self.assertEqual(pvgroups[3][0], "masarExample0004") self.assertEqual(pvgroups[4][0], "masarExampleCharArray") self.assertEqual(pvgroups[5][0], "masarExampleShortArray") self.assertEqual(pvgroups[6][0], "masarExampleLongArray") self.assertEqual(pvgroups[7][0], "masarExampleStringArray") self.assertEqual(pvgroups[8][0], "masarExampleFloatArray") self.assertEqual(pvgroups[9][0], "masarExampleDoubleArray") self.assertEqual(pvgroups[10][0], "masarExampleMbboUninitTest") servicename = "masar" masarconf = "testconf" saveService(conn, servicename, desc='test desc') saveServiceConfig(conn, servicename, masarconf, system='SR', status='active', configversion=20140420, configdesc='test desc') res = saveServicePvGroup(conn, masarconf, [pvgname1, pvgname2]) conn.commit() conn.close() except: raise save_params = {'configname': 'testconf', 'servicename': 'masar'} res1 = self.mc.saveSnapshot(save_params) self.assertNotEqual(res1, None) self.assertNotEqual(res1, False) event_id = res1[0] retrieve_params = {'eventid': str(event_id)} result = self.mc.retrieveSnapshot(retrieve_params) self.assertNotEqual(result, None) self.assertNotEqual(result, False) expected_results = ( ( 'masarExample0000', # ChannelName 0 'masarExample0001', # ChannelName 1 'masarExampleBoUninit', # ChannelName 2 'masarExampleMbboUninit', # ChannelName 3 'masarExample0002', # ChannelName 4 'masarExample0003', # ChannelName 5 'masarExample0004', # ChannelName 6 'masarExampleCharArray', # ChannelName 7 'masarExampleShortArray', # ChannelName 8 'masarExampleLongArray', # ChannelName 9 'masarExampleStringArray', # ChannelName 10 'masarExampleFloatArray', # ChannelName 11 'masarExampleDoubleArray', # ChannelName 12 'masarExampleMbboUninitTest'), # ChannelName 13 ( 10, # 0000 Value 'string value', # 0001 Value '0', # BoUninit Value (appropriately returned as string, 1, # MbboUninit Value 'zero', # 0002 Value 'one', # 0003 Value 1.9, # 0004 Value (), # CharArray Value (), # ShortArray Value (), # LongArray Value (), # StringArray Value (), # FloatArrayValue (), # DoubleArray Value 1), # MbboUninitTest Value (5, 0, 0, 5, 0, 0, 6, 4, 1, 5, 0, 2, 6, 5), # DBR type (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), # isConnected (631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000), # SecondsPastEpoch (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # NanoSeconds (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # UserTag (0, 0, 3, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 0), # Severity (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), # Status ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM')) # Message self.assertSequenceEqual(result, expected_results)