def __convert_to_validation(self, validation_document):
     return ValidationResponse(
         validation_document["validation_name"],
         validation_document["status"],
         validation_document["details"],
         validation_document["settings"],
         last_execution=validation_document["last_execution"],
     )
Exemple #2
0
    def test_validation_response_object(self):
        details = {}
        settings = {}

        response = ValidationResponse("name", NORMAL, details, settings)

        self.assertEqual(response.validation_name, "name")
        self.assertEqual(response.status, "NORMAL")
        self.assertEqual(response.details, details)
        self.assertEqual(response.settings, settings)
    def __convert_to_validation(self, entry):
        last_execution = entry["last_execution"]

        if last_execution:
            last_execution = datetime.strptime(last_execution, DATE_FORMAT)

        return ValidationResponse(
            entry["validation_name"],
            entry["status"],
            entry["details"],
            entry["settings"],
            last_execution=last_execution,
        )
    def test_get_validation_result(self, mock_validation_repository,
                                   mock_make_response):

        mock_response = MagicMock(name="mock_response")
        mock_make_response.return_value = mock_response

        mock_repository_instance = MagicMock(name="mock_repository_instance")
        mock_validation_repository.return_value = mock_repository_instance
        mock_repository_instance.fetch_last_validation_result.return_value = (
            ValidationResponse("test_validation", NORMAL, {}))

        response = get_validation("test_validation")
        self.assertEqual(response, mock_response)
Exemple #5
0
    def test_save_validation_result_create(self):
        self.collection.count_documents.return_value = 0
        response = ValidationResponse("name", "status", {})

        self.repository.save_validation_result(response)

        self.collection.insert_one.assert_called_with({
            "validation_name": "name",
            "status": "status",
            "details": {},
            "settings": None,
            "last_execution": None,
        })
Exemple #6
0
    def test_get_status_validations_empty_when_normal(
        self, mock_validation_repository, mock_make_response
    ):

        mock_response = MagicMock(name="mock_response")
        mock_make_response.return_value = mock_response

        mock_repository_instance = MagicMock(name="mock_repository_instance")
        mock_validation_repository.return_value = mock_repository_instance
        mock_repository_instance.fetch_all_validation_results.return_value = [
            ValidationResponse("test_validation", NORMAL, {})
        ]

        response = get_status()
        mock_make_response.assert_called_with('{"status": "NORMAL", "validations": []}')
        self.assertEqual(response, mock_response)
Exemple #7
0
    def test_get_status(self, mock_validation_repository, mock_make_response):

        mock_response = MagicMock(name="mock_response")
        mock_make_response.return_value = mock_response

        mock_repository_instance = MagicMock(name="mock_repository_instance")
        mock_validation_repository.return_value = mock_repository_instance
        mock_repository_instance.fetch_all_validation_results.return_value = [
            ValidationResponse("test_validation", PROBLEM, {})
        ]

        response = get_status()
        mock_make_response.assert_called_with(
            '{"status": "PROBLEM", "validations": [{"validation_name": "test_validation", "status": "PROBLEM", "details": {}, "settings": null}]}'
        )
        self.assertEqual(response, mock_response)
Exemple #8
0
    def test_save_validation_result_update(self):
        self.table.count.return_value = 1
        response = ValidationResponse("name",
                                      "status", {},
                                      last_execution=datetime(2021, 1, 21))

        self.repository.save_validation_result(response)

        self.table.update.assert_called_with(
            {
                "validation_name": "name",
                "status": "status",
                "details": {},
                "settings": None,
                "last_execution": '2021-01-21 00:00',
            },
            Query().validation_name == "name",
        )
def simple_validation():
    return ValidationResponse("simple_validation", NORMAL, {})
Exemple #10
0
import json
import unittest
from unittest.mock import MagicMock, patch

from lifeguard import NORMAL, PROBLEM
from lifeguard.server import (
    execute_validation,
    get_validation,
    get_status,
    get_status_complete,
)
from lifeguard.validations import ValidationResponse

test_validation = MagicMock(name="test_validation")
test_validation.return_value = ValidationResponse("test_validation", NORMAL, {})

VALIDATIONS = {"test_validation": {"ref": test_validation}}


class TestServer(unittest.TestCase):
    @patch("lifeguard.server.make_response")
    @patch("lifeguard.server.VALIDATIONS", VALIDATIONS)
    def test_execute_validation(self, mock_make_response):
        mock_response = MagicMock(name="mock_response")
        mock_make_response.return_value = mock_response

        response = execute_validation("test_validation")
        self.assertEqual(response, mock_response)

    @patch("lifeguard.server.make_response")
    @patch("lifeguard.server.traceback")
def simple_with_invalid_action_validation():
    return ValidationResponse("simple_with_invalid_action_validation", NORMAL,
                              {})
Exemple #12
0
 def test_validation_response_to_str(self):
     response = ValidationResponse("name", NORMAL, {}, {})
     self.assertEqual(
         str(response),
         "{'validation_name': 'name', 'status': 'NORMAL', 'details': {}, 'settings': {}}",
     )