def test_service_request_failure(self):
     # Given an incorrect Service key
     service = 'INCORRECT SERVICE KEY'
     # When a call is made to the service
     # Then a RasError is raised
     with self.assertRaises(RasError):
         service_request(service=service, endpoint='missing_end_point', search_value='value')
    def test_service_request(self):
        # Given a configured service
        service = 'case-service'
        mock_response = Response()
        mock_response.status_code = 200

        # When a call is made to the service
        with patch('requests.get', return_value=mock_response):
            response = service_request(service=service, endpoint='cases', search_value='test_case')

            # Then it response successfully
            self.assertStatus(response, 200)
    def _find_or_create_survey_from_exercise_id(exercise_id, session):
        """
        Makes a request to the collection exercise service for the survey ID,
        reuses the survey if it exists in this service or create if it doesn't

        :param exercise_id: An exercise id (UUID)
        :param session: database session
        :return: A survey record
        """
        response = service_request(service='collectionexercise-service',
                                   endpoint='collectionexercises',
                                   search_value=exercise_id)
        survey_id = response.json().get('surveyId')

        survey = query_survey_by_id(survey_id, session)
        if not survey:
            log.info('creating survey', survey_id=survey_id)
            survey = SurveyModel(survey_id=survey_id)
        return survey