def test_doubleNames2(self): inFolder = "input/" master_file = "act_test_dual_names.csv" slave_file = "wp_test_dual_names.csv" maPath = os.path.join(inFolder, master_file) saPath = os.path.join(inFolder, slave_file) saParser = CSVParse_User( cols = ColData_User.getWPImportCols(), defaults = ColData_User.getDefaults(), ) saParser.analyseFile(saPath) sUsr = saParser.emails['*****@*****.**'][0] maParser = CSVParse_User( cols = ColData_User.getACTImportCols(), defaults = ColData_User.getDefaults(), ) maParser.analyseFile(maPath) mUsr = maParser.emails['*****@*****.**'][0] syncUpdate = SyncUpdate(mUsr, sUsr) syncUpdate.update(ColData_User.getSyncCols()) print "master old: ", syncUpdate.oldMObject['Name'], '|', syncUpdate.oldMObject['Contact'] print "master new: ", syncUpdate.newMObject['Name'], '|', syncUpdate.newMObject['Contact'] print "slave old: ", syncUpdate.oldSObject['Name'], '|', syncUpdate.oldSObject['Contact'] print "slave new: ", syncUpdate.newSObject['Name'], '|', syncUpdate.newSObject['Contact'] print syncUpdate.tabulate(tablefmt='simple') print syncUpdate.getMasterUpdates()
def test_mDeltas(self): syncUpdate = SyncUpdate(self.usrMD1, self.usrSD1) syncUpdate.update(ColData_User.getSyncCols()) # syncUpdate.mDeltas(ColData_User.getDeltaCols()) self.assertGreater(syncUpdate.sTime, syncUpdate.mTime) self.assertFalse(syncUpdate.sDeltas) self.assertTrue(syncUpdate.mDeltas) self.assertEqual(syncUpdate.syncWarnings.get('Role')[0].get('subject'), syncUpdate.slave_name) self.assertEqual(syncUpdate.newMObject.get(ColData_User.deltaCol('Role')), 'WN')
def test_SQLWP_Analyse(self): saParser = CSVParse_User( cols = ColData_User.getImportCols(), defaults = ColData_User.getDefaults() ) with UsrSyncClient_SQL_WP( self.SSHTunnelForwarderParams, self.PyMySqlConnectParams ) as sqlClient: sqlClient.analyseRemote(saParser, since='2016-01-01 00:00:00') # CSVParse_User.printBasicColumns( list(chain( *saParser.emails.values() )) ) self.assertIn('*****@*****.**', saParser.emails)
def test_doubleNames(self): syncUpdate = SyncUpdate(self.usrMD4, self.usrSD4) syncUpdate.update(ColData_User.getSyncCols()) print "master old: ", syncUpdate.oldMObject['Name'], '|', syncUpdate.oldMObject['Contact'] print "master new: ", syncUpdate.newMObject['Name'], '|', syncUpdate.newMObject['Contact'] print "slave old: ", syncUpdate.oldSObject['Name'], '|', syncUpdate.oldSObject['Contact'] print "slave new: ", syncUpdate.newSObject['Name'], '|', syncUpdate.newSObject['Contact'] print syncUpdate.tabulate(tablefmt='simple')
def test_similarURL(self): syncUpdate = SyncUpdate(self.usrMD4, self.usrSD4) syncUpdate.update(ColData_User.getSyncCols()) # print "master old: ", syncUpdate.oldMObject['Name'], '|', syncUpdate.oldMObject['Web Site'] # print "master new: ", syncUpdate.newMObject['Name'], '|', syncUpdate.newMObject['Web Site'] # print "slave old: ", syncUpdate.oldSObject['Name'], '|', syncUpdate.oldSObject['Web Site'] # print "slave new: ", syncUpdate.newSObject['Name'], '|', syncUpdate.newSObject['Web Site'] self.assertIn('Web Site', syncUpdate.syncPasses)
def processConfig(self, config): inFolder = "../input/" outFolder = "../output/" if 'inFolder' in config.keys(): inFolder = config['inFolder'] if 'outFolder' in config.keys(): outFolder = config['outFolder'] # if 'logFolder' in config.keys(): # logFolder = config['logFolder'] ssh_user = config.get(self.optionNamePrefix+'ssh_user') ssh_pass = config.get(self.optionNamePrefix+'ssh_pass') ssh_host = config.get(self.optionNamePrefix+'ssh_host') ssh_port = config.get(self.optionNamePrefix+'ssh_port', 22) m_ssh_user = config.get(self.optionNamePrefix+'m_ssh_user') m_ssh_pass = config.get(self.optionNamePrefix+'m_ssh_pass') m_ssh_host = config.get(self.optionNamePrefix+'m_ssh_host') m_ssh_port = config.get(self.optionNamePrefix+'m_ssh_port', 22) remote_bind_host = config.get(self.optionNamePrefix+'remote_bind_host', '127.0.0.1') remote_bind_port = config.get(self.optionNamePrefix+'remote_bind_port', 3306) db_user = config.get(self.optionNamePrefix+'db_user') db_pass = config.get(self.optionNamePrefix+'db_pass') db_name = config.get(self.optionNamePrefix+'db_name') db_charset = config.get(self.optionNamePrefix+'db_charset', 'utf8mb4') wp_srv_offset = config.get(self.optionNamePrefix+'wp_srv_offset', 0) m_db_user = config.get(self.optionNamePrefix+'m_db_user') m_db_pass = config.get(self.optionNamePrefix+'m_db_pass') m_db_name = config.get(self.optionNamePrefix+'m_db_name') m_db_host = config.get(self.optionNamePrefix+'m_db_host') m_x_cmd = config.get(self.optionNamePrefix+'m_x_cmd') m_i_cmd = config.get(self.optionNamePrefix+'m_i_cmd') tbl_prefix = config.get(self.optionNamePrefix+'tbl_prefix', '') # wp_user = config.get(self.optionNamePrefix+'wp_user', '') # wp_pass = config.get(self.optionNamePrefix+'wp_pass', '') wc_api_key = config.get(self.optionNamePrefix+'wc_api_key') wc_api_secret = config.get(self.optionNamePrefix+'wc_api_secret') wp_api_key = config.get(self.optionNamePrefix+'wp_api_key') wp_api_secret = config.get(self.optionNamePrefix+'wp_api_secret') store_url = config.get(self.optionNamePrefix+'store_url', '') wp_user = config.get(self.optionNamePrefix+'wp_user') wp_pass = config.get(self.optionNamePrefix+'wp_pass') wp_callback = config.get(self.optionNamePrefix+'wp_callback') remote_export_folder = config.get(self.optionNamePrefix+'remote_export_folder', '') TimeUtils.setWpSrvOffset(wp_srv_offset) actFields = ";".join(ColData_User.getACTImportCols()) SSHTunnelForwarderAddress = (ssh_host, ssh_port) SSHTunnelForwarderBindAddress = (remote_bind_host, remote_bind_port) self.SSHTunnelForwarderParams = { 'ssh_address_or_host':SSHTunnelForwarderAddress, 'ssh_password':ssh_pass, 'ssh_username':ssh_user, 'remote_bind_address': SSHTunnelForwarderBindAddress, } self.PyMySqlConnectParams = { 'host' : 'localhost', 'user' : db_user, 'password': db_pass, 'db' : db_name, 'charset': db_charset, 'use_unicode': True, 'tbl_prefix': tbl_prefix, # 'srv_offset': wp_srv_offset, } self.wcApiParams = { 'api_key':wc_api_key, 'api_secret':wc_api_secret, 'url':store_url } self.wpApiParams = { 'api_key': wp_api_key, 'api_secret': wp_api_secret, 'url':store_url, 'wp_user':wp_user, 'wp_pass':wp_pass, 'callback':wp_callback } # json_uri = store_url + 'wp-json/wp/v2' # # self.jsonConnectParams = { # 'json_uri': json_uri, # 'wp_user': wp_user, # 'wp_pass': wp_pass # } self.actConnectParams = { 'hostname': m_ssh_host, 'port': m_ssh_port, 'username': m_ssh_user, 'password': m_ssh_pass, } self.actDbParams = { 'db_x_exe':m_x_cmd, 'db_i_exe':m_i_cmd, 'db_name': m_db_name, 'db_host': m_db_host, 'db_user': m_db_user, 'db_pass': m_db_pass, 'fields' : actFields, } self.fsParams = { 'importName': self.importName, 'remote_export_folder': remote_export_folder, 'inFolder': inFolder, 'outFolder': outFolder }
def test_sNameColUpdate(self): syncUpdate = SyncUpdate(self.usrMN2, self.usrSN2) syncUpdate.update(ColData_User.getSyncCols()) self.assertGreater(syncUpdate.mTime, syncUpdate.sTime) self.assertEqual(syncUpdate.syncWarnings.get('Name')[0].get('subject'), syncUpdate.slave_name)