Skip to content

Commit 559fc7b

Browse files
committed
unittest and corrections
1 parent 20c95e0 commit 559fc7b

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/bin/lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333
lifecycle_dir = '../lifecycle'
3434
raw = sys.stdin.read()
3535
content = raw.replace("\n", "")
36-
36+
config = u.read_config('../etc/config.conf')
3737
try:
3838
data = json.loads(content)
3939
before = data['payload']['before']['lifecycle']

src/lib/backend_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def returncode(code,message):
4545
return json.dumps(data)
4646

4747
def is_backend_concerned(entity):
48-
br=config('branchAttr')
4948
entry=make_entry_array(entity)
5049
if config('branchAttr') in entry:
5150
peopleType=entry[config('branchAttr')]
@@ -60,6 +59,7 @@ def is_backend_concerned(entity):
6059
for v in peopleType:
6160
if v in listBackend :
6261
return True
62+
return False
6363

6464
def make_entry_array(entity,key='before'):
6565
data = {}

unittest/files_ad_utils/lifecycle-notconcerned.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"employeeType": "TAIGA",
2424
"departmentNumber": [
25-
"esn"
25+
"xxx"
2626
],
2727
"jpegPhoto": "",
2828
"userCertificate": ""
@@ -60,7 +60,7 @@
6060
"2"
6161
],
6262
"supannTypeEntiteAffectation": [
63-
"esn"
63+
"xxx"
6464
],
6565
"supanncivilite": "M.",
6666
"supannCodeINSEEPaysDeNaissance": "",

unittest/lifecycleTest.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,41 @@ def test_stdout_captured_as_string(self):
131131

132132
class TestLifecycleBin(unittest.TestCase):
133133
"""Integration tests: invoke lifecycle.py as a subprocess."""
134-
135-
def run_backend(self, script, file):
134+
def run_backend(self,script, file= "",args=""):
135+
dir = os.getcwd()
136+
exe=dir + __PYTHONENV__
137+
execargs=[]
138+
execargs.append(exe)
139+
execargs.append(script)
140+
if args :
141+
execargs.append(args)
142+
if file == '':
143+
os.chdir('../src/bin')
144+
ret = subprocess.run(execargs,capture_output=True)
145+
else:
146+
#open file to pass to stdin
147+
fic = open(file, "r")
148+
content = fic.read()
149+
content = content.replace("\n", "")
150+
fic.close()
151+
os.chdir('../src/bin')
152+
ret = subprocess.run(execargs,input=content.encode(),capture_output=True)
153+
os.chdir(dir)
154+
return { "returncode" : ret.returncode,"stdout" : ret.stdout.decode()}
155+
156+
def run_backend1(self, script, file):
136157
dir_ = os.getcwd()
137158
exe = dir_ + __PYTHONENV__
138159
with open(file, 'r') as fic:
139160
content = fic.read().replace('\n', '')
140161
os.chdir('../src/bin')
141-
ret = subprocess.run([exe, script], input=content.encode(), capture_output=True)
162+
ret = subprocess.run([script], input=content.encode(), capture_output=True)
142163
os.chdir(dir_)
143164
return {'returncode': ret.returncode, 'stdout': ret.stdout.decode()}
144165

145166
def test_lifecycle_concerned(self):
146167
"""lifecycle.json: O→I transition, concerned backend → lifecycle script runs."""
147-
ret = self.run_backend('lifecycle.py', './files_ad_utils/lifecycle.json')
168+
ret = self.run_backend('./lifecycle.py', './files_ad_utils/lifecycle.json')
148169
self.assertEqual(ret['returncode'], 0)
149170
result = json.loads(ret['stdout'])
150171
self.assertEqual(result['status'], 0)

0 commit comments

Comments
 (0)