本文整理汇总了Python中msg_db_connector.MSGDBConnector类的典型用法代码示例。如果您正苦于以下问题:Python MSGDBConnector类的具体用法?Python MSGDBConnector怎么用?Python MSGDBConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MSGDBConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_log_successful_export
def test_log_successful_export(self):
"""
Test logging of export results to the export history table.
"""
# @REVIEWED
self.assertTrue(self.exporter.logSuccessfulExport(name = 'test_export',
url =
'http://test_url',
datetime = 0,
size = 100))
conn = MSGDBConnector().connectDB()
cursor = conn.cursor()
dbUtil = MSGDBUtil()
self.assertTrue(
dbUtil.executeSQL(cursor, 'select * from "ExportHistory" where '
'timestamp = '
'to_timestamp(0)'))
self.assertEqual(len(cursor.fetchall()), 1,
"There should only be one result row.")
self.assertTrue(
dbUtil.executeSQL(cursor, 'delete from "ExportHistory" where '
'timestamp = to_timestamp(0)'))
conn.commit()
示例2: TestMSGDBConnect
class TestMSGDBConnect(unittest.TestCase):
"""
These tests require a database connection to be available.
"""
def setUp(self):
self.connector = MSGDBConnector(True)
self.conn = self.connector.connectDB()
self.configer = MSGConfiger()
def test_init(self):
self.assertTrue(
isinstance(self.connector, msg_db_connector.MSGDBConnector),
"self.connection is an instance of MECODBConnector.")
def test_db_connection(self):
"""
DB can be connected to.
"""
self.assertIsNotNone(self.conn, 'DB connection not available.')
# Get the name of the database.
self.assertEqual(
self.configer.configOptionValue('Database', 'testing_db_name'),
self.connector.dbName, 'Testing DB name is not correct.')
def tearDown(self):
self.connector.closeDB(self.conn)
示例3: TestMECODupeChecker
class TestMECODupeChecker(unittest.TestCase):
"""
Unit tests for duplicate checking.
"""
def setUp(self):
self.dupeChecker = MECODupeChecker()
self.p = MECOXMLParser(True) # run in testing mode
self.dbConnect = MSGDBConnector(True)
self.dbUtil = MSGDBUtil()
self.conn = self.dbConnect.connectDB()
self.cur = self.conn.cursor()
def testInit(self):
self.assertEqual(self.dupeChecker.__class__.__name__, "MECODupeChecker",
"Dupe checker has been created.")
def testFindIndividualDupe(self):
"""
Find a duplicate record when only one exists.
"""
self.dbUtil.eraseTestMeco()
self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
fileObject = open(self.p.filename, "rb")
self.p.parseXML(fileObject, True)
self.assertTrue(
self.dupeChecker.readingBranchDupeExists(self.conn, '100000',
'2013-04-08 00:30:00',
'1', True),
"Record should already exist")
def testLoadOnTop(self):
"""
If the same data set is loaded in succession,
all values will be duplicated. Verify that this is true.
This is no longer possible as
duplicates are dropped before insertion.
"""
pass
def testLoadSingleMissingEntry(self):
"""
A reading will be inserted into the database where the reading does
not currently exist as determined by the
MeterName-IntervalEndTime-Channel tuple.
"""
pass
def tearDown(self):
self.dbConnect.closeDB(self.conn)
示例4: TestMECOXMLParser
class TestMECOXMLParser(unittest.TestCase):
"""
Unit tests for MECO XML Parser.
"""
def setUp(self):
self.p = MECOXMLParser(True) # run in testing mode
self.dbConnect = MSGDBConnector(True)
self.dbUtil = MSGDBUtil()
self.conn = self.dbConnect.connectDB()
self.cur = self.conn.cursor()
def testMECOXMLParserCanBeInited(self):
self.assertIsNotNone(self.p)
def testEveryElementIsVisited(self):
self.dbUtil.eraseTestMeco()
self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
fileObject = open(self.p.filename, "rb")
expectedCount = 125
self.p.parseXML(fileObject, True)
print "element count = %s" % self.p.processForInsertElementCount
self.assertEqual(self.p.processForInsertElementCount, expectedCount)
def testAllTableNamesArePresent(self):
self.dbUtil.eraseTestMeco()
self.p.filename = "../../test-data/meco_v3-energy-test-data.xml"
fileObject = open(self.p.filename, "rb")
self.p.parseXML(fileObject, True)
fail = False
for key in self.p.tableNameCount.keys():
print key + ": ",
print self.p.tableNameCount[key]
if self.p.tableNameCount[key] < 1:
if key != 'ChannelStatus' and key != 'IntervalStatus' and key \
!= 'EventData' and key != 'Event':
print "table = %s" % key
fail = True
self.assertFalse(fail,
"At least one table of each type should have been "
"encountered.")
def tearDown(self):
self.dbConnect.closeDB(self.conn)
示例5: setUp
def setUp(self):
self.dupeChecker = MECODupeChecker()
self.p = MECOXMLParser(True) # run in testing mode
self.dbConnect = MSGDBConnector(True)
self.dbUtil = MSGDBUtil()
self.conn = self.dbConnect.connectDB()
self.cur = self.conn.cursor()
示例6: __init__
def __init__(self):
"""
Constructor.
"""
warnings.simplefilter('default')
warnings.warn("This module is deprecated in favor of SEKNotifier.",
DeprecationWarning)
self.config = MSGConfiger()
self.logger = SEKLogger(__name__, 'info')
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
self.noticeTable = 'NotificationHistory'
self.notificationHeader = "This is a message from the Hawaii Smart " \
"Energy Project MSG Project notification " \
"system.\n\n"
self.noReplyNotice = '\n\nThis email account is not monitored. No ' \
'replies will originate from this ' \
'account.\n\nYou are receiving this message ' \
'because you are on the recipient list for ' \
'notifications for the Hawaii Smart Energy ' \
'Project.'
示例7: AllDataAggregator
class AllDataAggregator(object):
"""
Perform aggregation of all data for a set of predefined data types.
In this class, the raw types are left as empty to allow manual
specification.
"""
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'DEBUG')
self.aggregator = MSGDataAggregator(exitOnError = False,
commitOnEveryInsert = True)
self.notifier = MSGNotifier()
# Available types are in ['weather', 'egauge', 'circuit', 'irradiance'].
self.rawTypes = ['']
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
def aggregateAllData(self):
"""
:return: Nothing.
"""
map(self.aggregator.aggregateAllData, self.rawTypes)
示例8: MECODBReader
class MECODBReader(object):
"""
Read records from a database.
"""
def __init__(self, testing = False):
"""
Constructor.
:param testing: True if in testing mode.
"""
self.connector = MSGDBConnector()
self.conn = MSGDBConnector(testing).connectDB()
self.dbUtil = MSGDBUtil()
self.dbName = self.dbUtil.getDBName(self.connector.dictCur)
def selectRecord(self, conn, table, keyName, keyValue):
"""
Read a record in the database given a table name, primary key name,
and value for the key.
:param conn DB connection
:param table DB table name
:param keyName DB column name for primary key
:param keyValue Value to be matched
:returns: Row containing record data.
"""
print "selectRecord:"
sql = """SELECT * FROM "%s" WHERE %s = %s""" % (
table, keyName, keyValue)
dcur = conn.cursor(cursor_factory = psycopg2.extras.DictCursor)
self.dbUtil.executeSQL(dcur, sql)
row = dcur.fetchone()
return row
def readingAndMeterCounts(self):
"""
Retrieve the reading and meter counts.
:returns: Multiple lists containing the retrieved data.
"""
sql = """SELECT "Day", "Reading Count",
"Meter Count" FROM count_of_readings_and_meters_by_day"""
dcur = self.conn.cursor(cursor_factory = psycopg2.extras.DictCursor)
self.dbUtil.executeSQL(dcur, sql)
rows = dcur.fetchall()
dates = []
meterCounts = []
readingCounts = []
for row in rows:
dates.append(row[0])
readingCounts.append(row[1] / row[2])
meterCounts.append(row[2])
return dates, readingCounts, meterCounts
示例9: __init__
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'DEBUG')
self.cursor = MSGDBConnector().connectDB().cursor()
self.dbUtil = MSGDBUtil()
示例10: setUp
def setUp(self):
self.reader = MECODBReader()
self.connector = MSGDBConnector(True)
self.conn = self.connector.connectDB()
self.inserter = MECODBInserter()
self.util = MSGDBUtil()
self.lastSeqVal = None
self.tableName = 'MeterData'
self.colName = 'meter_data_id'
self.deleter = MECODBDeleter()
示例11: __init__
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__)
self.viewPVReadingsinNonMLH = ''
self.lastDateProcessed = None
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:10,代码来源:meco_pv_readings_in_nonpv_mlh_notifier.py
示例12: TestMECODBRead
class TestMECODBRead(unittest.TestCase):
def setUp(self):
self.reader = MECODBReader()
self.connector = MSGDBConnector(True)
self.conn = self.connector.connectDB()
self.inserter = MECODBInserter()
self.util = MSGDBUtil()
self.lastSeqVal = None
self.tableName = 'MeterData'
self.colName = 'meter_data_id'
self.deleter = MECODBDeleter()
def testMECODBReadCanBeInited(self):
self.assertIsNotNone(self.reader)
def testSelectRecord(self):
"""
Insert and retrieve a record to test the ability to select a record.
"""
print "testSelectRecord:"
print "self.conn = %s" % self.conn
sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001',
'MacID': '00:00:00:00:00:00:00:00'}
self.inserter.insertData(self.conn, self.tableName, sampleDict)
self.lastSeqVal = self.util.getLastSequenceID(self.conn, self.tableName,
self.colName)
print "lastSeqVal = %s" % self.lastSeqVal
row = self.reader.selectRecord(self.conn, self.tableName, self.colName,
self.lastSeqVal)
self.assertEqual(row[self.colName], self.lastSeqVal)
def tearDown(self):
# Delete the record that was inserted.
if self.lastSeqVal != None:
self.deleter.deleteRecord(self.conn, self.tableName, self.colName,
self.lastSeqVal)
self.connector.closeDB(self.conn)
示例13: __init__
def __init__(self, testing = False):
"""
Constructor.
:param testing: True if in testing mode.
"""
self.connector = MSGDBConnector()
self.conn = MSGDBConnector(testing).connectDB()
self.dbUtil = MSGDBUtil()
self.dbName = self.dbUtil.getDBName(self.connector.dictCur)
示例14: __init__
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'DEBUG', useColor = False)
self.timeUtil = MSGTimeUtil()
self.configer = MSGConfiger()
self.fileUtil = MSGFileUtil()
self.pythonUtil = MSGPythonUtil() # for debugging
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
self.notifier = SEKNotifier(connector = self.connector,
dbUtil = self.dbUtil,
user = self.configer.configOptionValue(
'Notifications', 'email_username'),
password = self.configer.configOptionValue(
'Notifications', 'email_password'),
fromaddr = self.configer.configOptionValue(
'Notifications', 'email_from_address'),
toaddr = self.configer.configOptionValue(
'Notifications', 'email_recipients'),
testing_toaddr =
self.configer.configOptionValue(
'Notifications',
'testing_email_recipients'),
smtp_server_and_port =
self.configer.configOptionValue(
'Notifications',
'smtp_server_and_port'))
# Google Drive parameters.
self.clientID = self.configer.configOptionValue('Export',
'google_api_client_id')
self.clientSecret = self.configer.configOptionValue('Export',
'google_api_client_secret')
self.oauthScope = 'https://www.googleapis.com/auth/drive'
self.oauthConsent = 'urn:ietf:wg:oauth:2.0:oob'
self.googleAPICredentials = ''
self.exportTempWorkPath = self.configer.configOptionValue('Export',
'db_export_work_path')
self.credentialPath = self.configer.configOptionValue('Export',
'google_api_credentials_path')
self.credentialStorage = Storage(
'{}/google_api_credentials'.format(self.credentialPath))
self._driveService = None
self._cloudFiles = None
self.postAgent = 'Maui Smart Grid 1.0.0 DB Exporter'
self.retryDelay = 10
self.availableFilesURL = ''
示例15: setUp
def setUp(self):
self.i = MECODBInserter()
self.util = MSGDBUtil()
self.connector = MSGDBConnector(True)
self.deleter = MECODBDeleter()
self.reader = MECODBReader()
self.lastSeqVal = None
self.conn = self.connector.connectDB()
self.sampleTableName = 'MeterData'
self.sampleDict = {'MeterName': '100001', 'UtilDeviceID': '100001',
'MacID': '00:00:00:00:00:00:00:00'}
self.keyName = 'meter_data_id'