Skip to content

Commit 70e4dfa

Browse files
committed
process_tracker_python-9 Process can have more than one source
✨ Process now can have more than one source. Can also have more than one target Finished testing of multiple sources/targets for given process. Closes: #8 and #9
1 parent 6dc4106 commit 70e4dfa

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

process_tracker/process_tracker.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ def register_process_sources(self, sources):
297297
:param sources: List of source name(s)
298298
:return: List of source objects.
299299
"""
300-
if sources != list:
300+
if isinstance(sources, str):
301301
sources = [sources]
302-
303302
source_list = []
304303

305304
for source in sources:
@@ -317,19 +316,18 @@ def register_process_targets(self, targets):
317316
:param targets: List of source name(s)
318317
:return: List of source objects.
319318
"""
320-
if targets != list:
319+
if isinstance(targets, str):
321320
targets = [targets]
322-
323-
source_list = []
321+
target_list = []
324322

325323
for target in targets:
326324
source = self.data_store.get_or_create(model=Source, source_name=target)
327325

328326
self.data_store.get_or_create(model=ProcessTarget, target_source_id=source.source_id
329327
, process_id=self.process.process_id)
330328

331-
source_list.append(source)
332-
return source_list
329+
target_list.append(source)
330+
return target_list
333331

334332
def set_process_run_low_high_dates(self, low_date=None, high_date=None):
335333
"""

tests/test_process_tracker.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,24 +405,70 @@ def test_register_process_sources_one_source(self):
405405
Testing that when a new process is registered, a source registered as well.
406406
:return:
407407
"""
408+
given_result = self.session.query(ProcessSource) \
409+
.join(Process) \
410+
.filter(Process.process_name == 'Testing Process Tracking Initialization') \
411+
.count()
412+
413+
expected_result = 1
414+
415+
self.assertEqual(expected_result, given_result)
408416

409417
def test_register_process_sources_two_sources(self):
410418
"""
411419
Testing that when a new process is registered, multiple sources can be registered as well.
412420
:return:
413421
"""
422+
ProcessTracker(process_name='Multiple Source, Target Test'
423+
, process_type='Extract'
424+
, actor_name='UnitTesting'
425+
, tool_name='Spark'
426+
, sources=['Unittests', 'Unittests2']
427+
, targets=['Unittests', 'Unittests2'])
428+
429+
given_result = self.session.query(ProcessSource) \
430+
.join(Process) \
431+
.filter(Process.process_name == 'Multiple Source, Target Test') \
432+
.count()
433+
434+
expected_result = 2
435+
436+
self.assertEqual(expected_result, given_result)
414437

415438
def test_register_process_targets_one_target(self):
416439
"""
417440
Testing that when a new process is registered, a target registered as well.
418441
:return:
419442
"""
443+
given_result = self.session.query(ProcessTarget) \
444+
.join(Process) \
445+
.filter(Process.process_name == 'Testing Process Tracking Initialization') \
446+
.count()
447+
448+
expected_result = 1
449+
450+
self.assertEqual(expected_result, given_result)
420451

421452
def test_register_process_targets_two_targets(self):
422453
"""
423454
Testing that when a new process is registered, multiple targets can be registered as well.
424455
:return:
425456
"""
457+
ProcessTracker(process_name='Multiple Source, Target Test'
458+
, process_type='Extract'
459+
, actor_name='UnitTesting'
460+
, tool_name='Spark'
461+
, sources=['Unittests', 'Unittests2']
462+
, targets=['Unittests', 'Unittests2'])
463+
464+
given_result = self.session.query(ProcessTarget) \
465+
.join(Process) \
466+
.filter(Process.process_name == 'Multiple Source, Target Test') \
467+
.count()
468+
469+
expected_result = 2
470+
471+
self.assertEqual(expected_result, given_result)
426472

427473
def test_change_run_status_complete(self):
428474
"""

0 commit comments

Comments
 (0)