diff --git a/pyros.py b/pyros.py index 706ed29..d863b26 100755 --- a/pyros.py +++ b/pyros.py @@ -149,17 +149,16 @@ class AManager(Utils): ''' self.replacePatternInFile("CELERY_TEST = "+str(not set_it), "CELERY_TEST = "+str(set_it), file_path) if simulator: self.replacePatternInFile("SIMULATOR = "+str(not set_it), "SIMULATOR = "+str(set_it), file_path) - #TODO: check that replacement has been done or ERROR !!! - # check that pattern STARTING WITH "^CELERY_TEST = "+str(set_it)$ is in the file - ''' - try: - with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: - for line in file: - print(line.replace(pattern, replace), end='') - except: - return 1 - return 0 - ''' + # Now, check that replacement has been done or ERROR !!! + pattern = "CELERY_TEST = "+str(set_it) + FOUND=False + with fileinput.FileInput(file_path) as file: + for line in file: + if pattern in line: + FOUND = True + break + if FOUND: print("pattern "+pattern+" found in file "+file_path) + if not FOUND: raise(Exception("pattern "+pattern+" not found in file "+file_path)) def signal_handler(self, signal, frame): diff --git a/src/majordome/majordome_test.py b/src/majordome/majordome_test.py index 53916f8..79be003 100755 --- a/src/majordome/majordome_test.py +++ b/src/majordome/majordome_test.py @@ -8,6 +8,7 @@ import fileinput import time from django.shortcuts import get_object_or_404 from django.conf import settings as djangosettings +import datetime DEBUG=True @@ -32,13 +33,21 @@ def tearDown(self): def replacePatternInFile(pattern, replace, file_path): - try: - with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: - for line in file: - print(line.replace(pattern, replace), end='') - except: - return 1 - return 0 + with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: + for line in file: + print(line.replace(pattern, replace), end='') + # Now, check that replacement has been done or ERROR !!! + FOUND=False + with fileinput.FileInput(file_path) as file: + for line in file: + if replace in line: + FOUND = True + break + if FOUND: print("pattern "+replace+" found in file "+file_path) + if not FOUND: raise(Exception("pattern "+replace+" not found in file "+file_path)) + + + def execProcessAsync(command): #self.printFullTerm(Colors.BLUE, "Executing command [" + command + "]") @@ -156,7 +165,9 @@ assert_majordome_is("PASSIVE_NO_PLC") # Let's pretend that PLC is now OK (via DB) # ==> check that it goes to state "PASSIVE" (waiting for PLC "AUTO") -plcstatus.created = "2018-07-24 11:49:49" +#plcstatus.created = "2018-07-24 11:49:49" +# ex: '2018-07-27T10:12:38.875112' +plcstatus.created = datetime.datetime.now().isoformat() plcstatus.save() time.sleep(5) assert_majordome_is("PASSIVE") @@ -165,7 +176,7 @@ assert_majordome_is("PASSIVE") # ==> check that it goes to state "STANDBY" plcstatus.plc_mode = "AUTO" plcstatus.save() -time.sleep(10) +time.sleep(15) assert_majordome_is("Standby") # Let's pretend that we are going REMOTE mode diff --git a/src/pyros/settings.py b/src/pyros/settings.py index a811c29..0a9b335 100644 --- a/src/pyros/settings.py +++ b/src/pyros/settings.py @@ -20,7 +20,7 @@ SIMULATOR = False CELERY_TEST = False # For src/majordome/majordome_test -MAJORDOME_TEST = False +MAJORDOME_TEST = True -- libgit2 0.21.2