def setUp(self):
     pylons = Mock()
     pylons.response = Mock()
     pylons.response.headers = {}
     self.runs_properties_service = Mock(RunPropertyService)
     self.runs_properties = RunPropertyController(self.runs_properties_service)
     self.runs_properties._py_object = pylons
class TestGetRunPropertiesController(TestController):

    def setUp(self):
        pylons = Mock()
        pylons.response = Mock()
        pylons.response.headers = {}
        self.runs_properties_service = Mock(RunPropertyService)
        self.runs_properties = RunPropertyController(self.runs_properties_service)
        self.runs_properties._py_object = pylons

    def test_GIVEN_database_is_not_up_WHEN_request_run_properties_THEN_return_fail(self):
        error_message = "Database is not available"
        self.runs_properties_service.list = Mock(side_effect=ServiceException(error_message))

        assert_that(calling(self.runs_properties.list), raises(HTTPInternalServerError, error_message))

    def test_GIVEN_database_is_empty_WHEN_request_run_properties_THEN_return_empty_list(self):
        self.runs_properties_service.list = Mock(return_value=[])

        result = self.runs_properties.list()

        decoded = json.JSONDecoder().decode(result)
        assert_that(decoded, is_({"model_runs": []}))