Skip to content

Commit 55c458c

Browse files
committed
Increasing Coverage
Working to raise code coverage. Working: #14
1 parent 65b84d8 commit 55c458c

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

process_tracker/data_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ def topic_deleter(self, topic, name):
285285
% (topic, name)
286286
)
287287
else:
288-
ClickException("Invalid topic. Unable to delete instance.").show()
289288
self.logger.error("%s is an invalid topic. Unable to delete." % topic)
289+
raise ClickException("Invalid topic. Unable to delete instance.")
290290

291291
if item_delete:
292292
self.session.commit()
@@ -446,7 +446,7 @@ def verify_and_connect_to_data_store(self):
446446
errors.append(
447447
Exception(
448448
"Data store has not been properly configured. Please read how to set up the "
449-
"Process Tracking data store by going to: <insert read the docs url here>"
449+
"Process Tracking data store by going to: https://process-tracker.readthedocs.io/en/latest/"
450450
)
451451
)
452452

process_tracker/extract_tracker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ def add_dependency(self, dependency_type, dependency):
132132
parent_extract_id=self.extract.extract_id,
133133
)
134134
else:
135-
self.logger.error("Invalid dependency type.")
136-
raise Exception("Invalid extract dependency type.")
135+
self.logger.error("Invalid extract dependency type.")
136+
raise Exception(
137+
"%s is an invalid extract dependency type." % dependency_type
138+
)
137139

138140
self.session.add(dependency)
139141
self.session.commit()
@@ -148,7 +150,7 @@ def change_extract_status(self, new_status):
148150
status_date = datetime.now()
149151
if new_status in self.extract_status_types:
150152

151-
if new_status == self.extract_status_loading:
153+
if new_status == "loading":
152154

153155
self.extract_dependency_check()
154156

process_tracker/process_tracker.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def change_run_status(self, new_status, end_date=None):
110110
if end_date is None:
111111
end_date = datetime.now()
112112

113-
if self.process_status_types[new_status]:
113+
if new_status in self.process_status_types.keys():
114114

115115
self.process_tracking_run.process_status_id = self.process_status_types[
116116
new_status
@@ -134,10 +134,7 @@ def change_run_status(self, new_status, end_date=None):
134134
self.session.commit()
135135

136136
else:
137-
raise Exception(
138-
"%s is not a valid process status type. "
139-
"Please add the status to process_status_type_lkup" % new_status
140-
)
137+
raise Exception("The provided status type %s is invalid." % new_status)
141138

142139
def find_ready_extracts_by_filename(self, filename):
143140
"""

tests/test_cli.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ def test_create_error_type(self):
108108

109109
self.assertEqual(0, result.exit_code)
110110

111+
# def test_create_invalid_type(self):
112+
# """
113+
# Testing that when an invalid type is passed to the create option, an exception occurs.
114+
# :return:
115+
# """
116+
# given_result = self.runner.invoke(main, 'create -t blarg -n "Argle Bargle"')
117+
# given_result = given_result.exception
118+
#
119+
# expected_result = "Invalid topic type."
120+
#
121+
# return self.assertEqual(expected_result, given_result)
122+
111123
def test_create_process_type(self):
112124
"""
113125
Testing that when creating an process type record it is added.
@@ -270,6 +282,18 @@ def test_delete_error_type_protected(self):
270282
self.assertIn(expected_result, result.output)
271283
self.assertEqual(0, result.exit_code)
272284

285+
# def test_delete_invalid_type(self):
286+
# """
287+
# Testing that when an invalid type is passed to the delete option, an exception occurs.
288+
# :return:
289+
# """
290+
# given_result = self.runner.invoke(main, 'delete -t blarg -n "Argle Bargle"')
291+
# given_result = given_result.exception
292+
#
293+
# expected_result = "Invalid topic. Unable to delete instance."
294+
#
295+
# return self.assertEqual(expected_result, given_result)
296+
273297
def test_delete_process_type(self):
274298
"""
275299
Testing that when deleting an process type record not on the protected list, it is deleted.
@@ -466,6 +490,20 @@ def test_update_error_type_protected(self):
466490

467491
self.assertIn(expected_result, result.output)
468492

493+
# def test_update_invalid_type(self):
494+
# """
495+
# Testing that when an invalid type is passed to the update option, an exception occurs.
496+
# :return:
497+
# """
498+
# given_result = self.runner.invoke(
499+
# main, 'update -t blarg -i "Testing" -n "Argle Bargle"'
500+
# )
501+
# given_result = given_result.exception
502+
#
503+
# expected_result = "Invalid topic. Unable to delete instance."
504+
#
505+
# return self.assertEqual(expected_result, given_result)
506+
469507
def test_update_process_type(self):
470508
"""
471509
Testing that when updating a process type record not on the protected list, it is updated.

tests/test_extract_tracker.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ def test_add_dependency_child(self):
124124

125125
self.assertEqual(expected_result, given_result)
126126

127+
def test_add_dependency_invalid_type(self):
128+
"""
129+
Ensuring that when a dependency is added, only 'parent' and 'child' are accepted.
130+
:return:
131+
"""
132+
133+
with self.assertRaises(Exception) as context:
134+
self.extract.add_dependency(
135+
dependency_type="blarg", dependency=self.extract.extract
136+
)
137+
return self.assertTrue(
138+
"blarg is an invalid extract dependency type." in str(context.exception)
139+
)
140+
127141
def test_initialization_no_location_no_location_path(self):
128142
"""
129143
Testing that if no location or location path is set, an error is thrown.

tests/test_process_tracker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ def timestamp_converter(self, timestamp):
125125

126126
return timestamp
127127

128+
def test_change_status_invalid_type(self):
129+
"""
130+
Testing that if an invalid process status type is passed, it will trigger an exception.
131+
:return:
132+
"""
133+
with self.assertRaises(Exception) as context:
134+
self.process_tracker.change_run_status(new_status="blarg")
135+
return self.assertTrue(
136+
"The provided status type blarg is invalid." in str(context.exception)
137+
)
138+
128139
def test_find_ready_extracts_by_filename_full(self):
129140
"""
130141
Testing that for the given full filename, find the extract, provided it's in 'ready' state.
@@ -538,7 +549,7 @@ def test_register_new_process_run_exception(self):
538549
with self.assertRaises(Exception) as context:
539550
# Running registration a second time to mimic job being run twice
540551
self.process_tracker.register_new_process_run()
541-
print(context.exception)
552+
542553
return self.assertTrue(
543554
"The process Testing Process Tracking Initialization "
544555
"is currently running." in str(context.exception)

0 commit comments

Comments
 (0)