Skip to content

Commit

Permalink
Increased coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 28, 2020
1 parent b701b2f commit 72332e9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
6 changes: 1 addition & 5 deletions infracheck/infracheck/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ def add(self, config_name: str, result: ExecutedCheckResult) -> None:

def to_hash(self) -> dict:
checks_as_hash = {}
global_status = True

for name, details in self.checks.items():
checks_as_hash[name] = details.to_hash()

if not details.exit_status:
global_status = False

return {
'checks': checks_as_hash,
'global_status': global_status
'global_status': self.is_global_status_success()
}

def is_global_status_success(self) -> bool:
Expand Down
67 changes: 67 additions & 0 deletions tests/unit_test_executed_checks_result_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import sys
import os
import inspect
from rkd.api.testing import BasicTestingCase

path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + '/../'
sys.path.insert(0, path)

from infracheck.infracheck.model import ExecutedChecksResultList, ExecutedCheckResult


class ExecutedChecksResultListTest(BasicTestingCase):
def test_is_global_status_success(self):
"""
Checks if global status of the endpoint works as expected in basing on checks results
"""

with self.subTest('One check is failing, then global status is failure'):
results = ExecutedChecksResultList()
results.add('first', ExecutedCheckResult(
configured_name='first',
output='Test',
exit_status=False,
hooks_output=''
))
results.add('second', ExecutedCheckResult(
configured_name='second',
output='Test',
exit_status=True,
hooks_output=''
))

self.assertFalse(results.is_global_status_success())

with self.subTest('All checks are passing, then we have a success'):
results = ExecutedChecksResultList()
results.add('first', ExecutedCheckResult(
configured_name='first',
output='Test',
exit_status=True,
hooks_output=''
))
results.add('second', ExecutedCheckResult(
configured_name='second',
output='Test',
exit_status=True,
hooks_output=''
))

self.assertTrue(results.is_global_status_success())

with self.subTest('All checks are failing, then we have a failure'):
results = ExecutedChecksResultList()
results.add('first', ExecutedCheckResult(
configured_name='first',
output='Test',
exit_status=False,
hooks_output=''
))
results.add('second', ExecutedCheckResult(
configured_name='second',
output='Test',
exit_status=False,
hooks_output=''
))

self.assertFalse(results.is_global_status_success())

0 comments on commit 72332e9

Please sign in to comment.