def test_ODK_briefcase_4(self): """Check mergeToPrevExport() includes all VA records from ODK BC export files.""" if os.path.isfile("ODKFiles/odkBCExportNew.csv"): os.remove("ODKFiles/odkBCExportNew.csv") if os.path.isfile("ODKFiles/odkBCExportPrev.csv"): os.remove("ODKFiles/odkBCExportPrev.csv") shutil.copy("ODKFiles/previous_bc_export.csv", "ODKFiles/odkBCExportPrev.csv") shutil.copy("ODKFiles/another_bc_export.csv", "ODKFiles/odkBCExportNew.csv") pipelineODK = odk.ODK(self.settingsODK, ".") pipelineODK.mergeToPrevExport() hasAll = True with open("ODKFiles/odkBCExportPrev.csv") as fCombined: fCombinedLines = fCombined.readlines() with open("ODKFiles/previous_bc_export.csv") as fPrevious: fPreviousLines = fPrevious.readlines() with open("ODKFiles/another_bc_export.csv") as fAnother: fAnotherLines = fAnother.readlines() for line in fPreviousLines: if line not in fCombinedLines: hasAll = False for line in fAnotherLines: if line not in fCombinedLines: hasAll = False self.assertTrue(hasAll) os.remove("ODKFiles/odkBCExportPrev.csv")
def setUpClass(cls): shutil.rmtree('ODKFiles/ODK Briefcase Storage/', ignore_errors=True) if os.path.isfile('ODKFiles/odkBCExportNew.csv'): os.remove('ODKFiles/odkBCExportNew.csv') if os.path.isfile('ODKFiles/odkBCExportPrev.csv'): os.remove('ODKFiles/odkBCExportPrev.csv') if not os.path.isfile('ODK-Briefcase-v1.12.2.jar'): downloadBriefcase() odkID = None odkURL = 'https://odk.swisstph.ch/ODKAggregateOpenVa' odkUser = '******' odkPassword = '******' odkFormID = 'va_who_2016_11_03_v1_4_1' odkLastRun = '1901-01-01_00:00:01' odkLastRunDate = datetime.datetime.strptime( odkLastRun, '%Y-%m-%d_%H:%M:%S').strftime('%Y/%m/%d') odkLastRunDatePrev = ( datetime.datetime.strptime(odkLastRunDate, '%Y/%m/%d') - datetime.timedelta(days=1)).strftime('%Y/%m/%d') odkLastRunResult = 'fail' ntODK = collections.namedtuple('ntODK', [ 'odkID', 'odkURL', 'odkUser', 'odkPassword', 'odkFormID', 'odkLastRun', 'odkLastRunResult', 'odkLastRunDate', 'odkLastRunDatePrev' ]) badSettingsODK = ntODK(odkID, odkURL, 'WRONG', odkPassword, odkFormID, odkLastRun, odkLastRunResult, odkLastRunDate, odkLastRunDatePrev) cls.pipelineODK = odk.ODK(badSettingsODK, '.')
def test_ODK_briefcase_5(self): """Check successful run with valid parameters.""" shutil.rmtree("ODKFiles/ODK Briefcase Storage/", ignore_errors=True) pipelineODK = odk.ODK(self.settingsODK, ".") odkBC = pipelineODK.briefcase() self.assertEqual(0, odkBC.returncode)
def test_ODK_briefcase_1(self): """Check mergeToPrevExport() moves odkBCExportNew.csv""" if os.path.isfile("ODKFiles/odkBCExportNew.csv"): os.remove("ODKFiles/odkBCExportNew.csv") if os.path.isfile("ODKFiles/odkBCExportPrev.csv"): os.remove("ODKFiles/odkBCExportPrev.csv") shutil.copy("ODKFiles/previous_bc_export.csv", "ODKFiles/odkBCExportNew.csv") pipelineODK = odk.ODK(self.settingsODK, ".") pipelineODK.mergeToPrevExport() self.assertTrue(os.path.isfile("ODKFiles/odkBCExportPrev.csv")) os.remove("ODKFiles/odkBCExportPrev.csv")
def setUpClass(cls): shutil.rmtree('ODKFiles/ODK Briefcase Storage/', ignore_errors=True) if os.path.isfile('ODKFiles/odkBCExportNew.csv'): os.remove('ODKFiles/odkBCExportNew.csv') if os.path.isfile('ODKFiles/odkBCExportPrev.csv'): os.remove('ODKFiles/odkBCExportPrev.csv') if not os.path.isfile('ODK-Briefcase-v1.18.0.jar'): downloadBriefcase() odkID = None odkURL = 'https://odk.swisstph.ch/ODKAggregateOpenVa' odkUser = '******' odkPassword = '******' odkFormID = 'va_who_v1_5_1' odkLastRun = '1901-01-01_00:00:01' odkLastRunDate = datetime.datetime.strptime( odkLastRun, '%Y-%m-%d_%H:%M:%S').strftime('%Y/%m/%d') odkLastRunDatePrev = ( datetime.datetime.strptime(odkLastRunDate, '%Y/%m/%d') - datetime.timedelta(days=1)).strftime('%Y/%m/%d') odkLastRunResult = 'fail' odkUseCentral = 'False' odkProjectNumber = '1' ntODK = collections.namedtuple('ntODK', [ 'odkID', 'odkURL', 'odkUser', 'odkPassword', 'odkFormID', 'odkLastRun', 'odkLastRunResult', 'odkLastRunDate', 'odkLastRunDatePrev', 'odkUseCentral', 'odkProjectNumber' ]) settingsODK = ntODK(odkID, odkURL, odkUser, odkPassword, odkFormID, odkLastRun, odkLastRunResult, odkLastRunDate, odkLastRunDatePrev, odkUseCentral, odkProjectNumber) shutil.copy('ODKFiles/previous_bc_export.csv', 'ODKFiles/odkBCExportPrev.csv') shutil.copy('ODKFiles/another_bc_export.csv', 'ODKFiles/odkBCExportNew.csv') pipelineODK = odk.ODK(settingsODK, '.') pipelineODK.mergeToPrevExport()
def test_ODK_bad_odkID(self): """Check for error if odkID parameter is invalid.""" shutil.rmtree("ODKFiles/ODK Briefcase Storage", ignore_errors=True) pipelineODK = odk.ODK(self.badSettingsODK, ".") self.assertRaises(odk.ODKError, pipelineODK.briefcase)
def test_ODK_briefcase_6(self): """Check for exported CSV file.""" shutil.rmtree("ODKFiles/ODK Briefcase Storage", ignore_errors=True) pipelineODK = odk.ODK(self.settingsODK, ".") odkBC = pipelineODK.briefcase() self.assertTrue(os.path.isfile("ODKFiles/odkBCExportNew.csv"))