Example #1
0
def request_casegroups_for_business(business_id):
    logger.info('Retrieving casegroups for business', business_id=business_id)
    url = f'{current_app.config["CASE_URL"]}/casegroups/partyid/{business_id}'
    response = Requests.get(url)
    response.raise_for_status()
    logger.info('Successfully retrieved casegroups for business',
                business_id=business_id)
    return response.json()
Example #2
0
def request_collection_exercises_for_survey(survey_id):
    logger.info('Retrieving collection exercises for survey',
                survey_id=survey_id)
    url = f'{current_app.config["COLLECTION_EXERCISE_URL"]}/collectionexercises/survey/{survey_id}'
    response = Requests.get(url)
    response.raise_for_status()
    logger.info('Successfully retrieved collection exercises for survey',
                survey_id=survey_id)
    return response.json()
def get_cases_for_casegroup(case_group_id):
    logger.info('Requesting cases for case group', casegroup_id=case_group_id)
    case_svc = current_app.config['CASE_URL']
    get_case_url = f'{case_svc}/cases/casegroupid/{case_group_id}'

    response = Requests.get(get_case_url)
    response.raise_for_status()
    logger.info('Successfully retrieved case for case group', casegroup_id=case_group_id)
    return response.json()
Example #4
0
def request_collection_exercise(collection_exercise_id):
    """
    Contact the collection exercise service for a collection exercise by id

    :param collection_exercise_id: The id of the collection exercise
    """
    ce_url = f'{current_app.config["COLLECTION_EXERCISE_URL"]}/collectionexercises/{collection_exercise_id}'
    logger.info('Retrieving collection exercise by id',
                collection_exercise_id=collection_exercise_id)
    response = Requests.get(ce_url)
    response.raise_for_status()
    logger.info("Successfully retrived collection exercise by id")
    return response.json()
Example #5
0
def request_case(enrolment_code):
    """
    Contact the case service to retrieve a case for a given enrolment code

    :param enrolment_code: A respondent provided enrolment code
    """
    case_url = f'{current_app.config["CASE_URL"]}/cases/iac/{enrolment_code}'
    logger.info('Retrieving case from an enrolment code',
                enrolment_code=enrolment_code)
    response = Requests.get(case_url)
    response.raise_for_status()
    logger.info("Successfully retrieved case from an enrolment code",
                enrolment_code=enrolment_code)
    return response.json()
Example #6
0
def request_survey(survey_id):
    """
    Contact the survey service to get the details of a survey from its uuid.

    :param survey_id: A uuid of a survey
    """
    survey_url = f'{current_app.config["SURVEY_URL"]}/surveys/{survey_id}'
    logger.info("Retrieving survey information from the survey service",
                survey_id=survey_id)
    response = Requests.get(survey_url)
    response.raise_for_status()
    logger.info(
        'Successfully retrieved survey information from the survey service',
        survey_id=survey_id)
    return response.json()
def post_case_event(case_id, category='Default category message', desc='Default description message'):
    """Posts a case event

    :raises HTTPError: Raised if the post returns a failure status code
    """
    logger.info('Posting case event', case_id=case_id)
    case_svc = current_app.config['CASE_URL']
    case_url = f'{case_svc}/cases/{case_id}/events'
    payload = {
        'description': desc,
        'category': category,
        'createdBy': 'Party Service'
    }

    response = Requests.post(case_url, json=payload)
    response.raise_for_status()
    logger.info('Successfully posted case event', case_id=case_id)
    return response.json()
def disable_iac(enrolment_code, case_id):
    """
    Disables the iac code by calling the iac service

    :param enrolment_code: A string containing the code to disable
    :param case_id: A string containing a uuid for the case
    :returns:  A dictionary containing the json response from the call
    :raises ValueError:  Raised when the response doesn't return json (on a 500 response?)
    """
    iac_url = f'{current_app.config["IAC_URL"]}/iacs/{enrolment_code}'
    payload = {
        "updatedBy": "Party Service"
    }
    response = Requests.put(iac_url, json=payload)
    try:
        response.raise_for_status()
    except requests.HTTPError:
        # Needs to be investigated by someone with more time, do we swallow the HTTPError because the
        # response.json line below will probably throw a ValueError?  If it's a 404 then it's assumed that
        # it returns a json message saying it's not found.  Or is the idea to not interrupt the users
        # journey and we can just handle it ourselves after the fact?
        logger.error("IAC failed to be disabled", case_id=case_id)

    return response.json()
Example #9
0
 def update_account(self, **kwargs):
     payload = {}
     payload.update(kwargs)
     return Requests.put(self.admin_url, data=payload)
Example #10
0
 def create_account(self, username, password):
     payload = {
         'username': username,
         'password': password,
     }
     return Requests.post(self.admin_url, data=payload)
def request_iac(enrolment_code):
    iac_url = f'{current_app.config["IAC_URL"]}/iacs/{enrolment_code}'
    response = Requests.get(iac_url)
    response.raise_for_status()
    return response.json()