Commit cb0206d541dc7e3327ddd30a8d759d4af78783fc
1 parent
54467c54
Exists in
dev
assert that string has been replaced as awaited for CELERY_TEST,
MAJORDOME_TEST
Showing
3 changed files
with
31 additions
and
21 deletions
Show diff stats
pyros.py
@@ -149,17 +149,16 @@ class AManager(Utils): | @@ -149,17 +149,16 @@ class AManager(Utils): | ||
149 | ''' | 149 | ''' |
150 | self.replacePatternInFile("CELERY_TEST = "+str(not set_it), "CELERY_TEST = "+str(set_it), file_path) | 150 | self.replacePatternInFile("CELERY_TEST = "+str(not set_it), "CELERY_TEST = "+str(set_it), file_path) |
151 | if simulator: self.replacePatternInFile("SIMULATOR = "+str(not set_it), "SIMULATOR = "+str(set_it), file_path) | 151 | if simulator: self.replacePatternInFile("SIMULATOR = "+str(not set_it), "SIMULATOR = "+str(set_it), file_path) |
152 | - #TODO: check that replacement has been done or ERROR !!! | ||
153 | - # check that pattern STARTING WITH "^CELERY_TEST = "+str(set_it)$ is in the file | ||
154 | - ''' | ||
155 | - try: | ||
156 | - with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: | ||
157 | - for line in file: | ||
158 | - print(line.replace(pattern, replace), end='') | ||
159 | - except: | ||
160 | - return 1 | ||
161 | - return 0 | ||
162 | - ''' | 152 | + # Now, check that replacement has been done or ERROR !!! |
153 | + pattern = "CELERY_TEST = "+str(set_it) | ||
154 | + FOUND=False | ||
155 | + with fileinput.FileInput(file_path) as file: | ||
156 | + for line in file: | ||
157 | + if pattern in line: | ||
158 | + FOUND = True | ||
159 | + break | ||
160 | + if FOUND: print("pattern "+pattern+" found in file "+file_path) | ||
161 | + if not FOUND: raise(Exception("pattern "+pattern+" not found in file "+file_path)) | ||
163 | 162 | ||
164 | 163 | ||
165 | def signal_handler(self, signal, frame): | 164 | def signal_handler(self, signal, frame): |
src/majordome/majordome_test.py
@@ -8,6 +8,7 @@ import fileinput | @@ -8,6 +8,7 @@ import fileinput | ||
8 | import time | 8 | import time |
9 | from django.shortcuts import get_object_or_404 | 9 | from django.shortcuts import get_object_or_404 |
10 | from django.conf import settings as djangosettings | 10 | from django.conf import settings as djangosettings |
11 | +import datetime | ||
11 | 12 | ||
12 | 13 | ||
13 | DEBUG=True | 14 | DEBUG=True |
@@ -32,13 +33,21 @@ def tearDown(self): | @@ -32,13 +33,21 @@ def tearDown(self): | ||
32 | 33 | ||
33 | 34 | ||
34 | def replacePatternInFile(pattern, replace, file_path): | 35 | def replacePatternInFile(pattern, replace, file_path): |
35 | - try: | ||
36 | - with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: | ||
37 | - for line in file: | ||
38 | - print(line.replace(pattern, replace), end='') | ||
39 | - except: | ||
40 | - return 1 | ||
41 | - return 0 | 36 | + with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: |
37 | + for line in file: | ||
38 | + print(line.replace(pattern, replace), end='') | ||
39 | + # Now, check that replacement has been done or ERROR !!! | ||
40 | + FOUND=False | ||
41 | + with fileinput.FileInput(file_path) as file: | ||
42 | + for line in file: | ||
43 | + if replace in line: | ||
44 | + FOUND = True | ||
45 | + break | ||
46 | + if FOUND: print("pattern "+replace+" found in file "+file_path) | ||
47 | + if not FOUND: raise(Exception("pattern "+replace+" not found in file "+file_path)) | ||
48 | + | ||
49 | + | ||
50 | + | ||
42 | 51 | ||
43 | def execProcessAsync(command): | 52 | def execProcessAsync(command): |
44 | #self.printFullTerm(Colors.BLUE, "Executing command [" + command + "]") | 53 | #self.printFullTerm(Colors.BLUE, "Executing command [" + command + "]") |
@@ -156,7 +165,9 @@ assert_majordome_is("PASSIVE_NO_PLC") | @@ -156,7 +165,9 @@ assert_majordome_is("PASSIVE_NO_PLC") | ||
156 | 165 | ||
157 | # Let's pretend that PLC is now OK (via DB) | 166 | # Let's pretend that PLC is now OK (via DB) |
158 | # ==> check that it goes to state "PASSIVE" (waiting for PLC "AUTO") | 167 | # ==> check that it goes to state "PASSIVE" (waiting for PLC "AUTO") |
159 | -plcstatus.created = "2018-07-24 11:49:49" | 168 | +#plcstatus.created = "2018-07-24 11:49:49" |
169 | +# ex: '2018-07-27T10:12:38.875112' | ||
170 | +plcstatus.created = datetime.datetime.now().isoformat() | ||
160 | plcstatus.save() | 171 | plcstatus.save() |
161 | time.sleep(5) | 172 | time.sleep(5) |
162 | assert_majordome_is("PASSIVE") | 173 | assert_majordome_is("PASSIVE") |
@@ -165,7 +176,7 @@ assert_majordome_is("PASSIVE") | @@ -165,7 +176,7 @@ assert_majordome_is("PASSIVE") | ||
165 | # ==> check that it goes to state "STANDBY" | 176 | # ==> check that it goes to state "STANDBY" |
166 | plcstatus.plc_mode = "AUTO" | 177 | plcstatus.plc_mode = "AUTO" |
167 | plcstatus.save() | 178 | plcstatus.save() |
168 | -time.sleep(10) | 179 | +time.sleep(15) |
169 | assert_majordome_is("Standby") | 180 | assert_majordome_is("Standby") |
170 | 181 | ||
171 | # Let's pretend that we are going REMOTE mode | 182 | # Let's pretend that we are going REMOTE mode |
src/pyros/settings.py