def test_direct_link(self):
        # family > dispute over children > in a dispute with ex-partner > family mediation
        resp = api.move(["n43n14", "n105", "n106", "n59"])
        self.assertResponseHasNNodes(resp, 4)

        # family > problem with ex
        resp = api.move(["n43n14", "n51"])
        self.assertResponseHasNNodes(resp, 2)

        # family
        resp = api.move(["n43n14"])
        self.assertResponseHasNNodes(resp, 1)

        resp = api.move([])
        self.assertResponseHasNNodes(resp, 0)
    def test_direct_link(self):
        # family > dispute over children > in a dispute with ex-partner > family mediation
        resp = api.move(["n43n14", "n105", "n106", "n59"])
        self.assertResponseHasNNodes(resp, 4)

        # family > problem with ex
        resp = api.move(["n43n14", "n51"])
        self.assertResponseHasNNodes(resp, 2)

        # family
        resp = api.move(["n43n14"])
        self.assertResponseHasNNodes(resp, 1)

        resp = api.move([])
        self.assertResponseHasNNodes(resp, 0)
    def get(self, choices="", *args, **kwargs):
        api.create_diagnosis()

        response = api.move([c for c in choices.strip("/").split("/") if c])

        try:
            response_json = response.json()
        except ValueError:
            if current_app.config["DEBUG"]:
                return response.text
            raise

        state = response_json.get("state")
        nodes = response_json.get("nodes", [])

        if state and state != DIAGNOSIS_SCOPE.UNKNOWN:
            api.save(response_json)

            outcome_url = OUTCOME_URLS[state]
            outcome = outcome_url[2]

            if outcome:
                session.store({"outcome": outcome})

            if state == DIAGNOSIS_SCOPE.INELIGIBLE:
                outcome_url = url_for(
                    outcome_url[0],
                    category_name=session.checker.category_slug)
            else:
                outcome_url = url_for(outcome_url[0], **outcome_url[1])
                if state == DIAGNOSIS_SCOPE.OUTOFSCOPE:
                    outcome_url = "%s?category=%s" % (
                        outcome_url, self.get_category_for_larp(session))

            return redirect(outcome_url)

        def add_link(choice):
            choices_list = [choice["id"]]
            if choices:
                choices_list.insert(0, choices.strip("/"))
            choice["url"] = url_for(".diagnosis",
                                    choices="/".join(choices_list))
            return choice

        display_choices = map(add_link, response_json.get("choices", []))

        return render_template("scope/diagnosis.html",
                               choices=display_choices,
                               nodes=nodes)
    def test_outcome(self):
        paths = [
            # family > disputes over children > with ex over children > domestic abuse > no immediate harm risk
            ("INSCOPE", ["n43n14", "n105", "n106", "n62", "n19"]),
            # family > disputes over children > with ex over children > domestic abuse > immediate harm risk
            ("CONTACT", ["n43n14", "n105", "n106", "n62", "n18"]),
            # family > any other problem
            ("INELIGIBLE", ["n43n14", "n53"]),
        ]

        for outcome, choices in paths:
            resp = None
            for n in range(1, len(choices) + 1):
                resp = api.move(choices[:n])

            self.assertEqual(resp.json().get("state"), outcome)
    def test_outcome(self):
        paths = [
            # family > disputes over children > with ex over children > domestic abuse > no immediate harm risk
            ("INSCOPE", ["n43n14", "n105", "n106", "n62", "n19"]),
            # family > disputes over children > with ex over children > domestic abuse > immediate harm risk
            ("CONTACT", ["n43n14", "n105", "n106", "n62", "n18"]),
            # family > any other problem
            ("INELIGIBLE", ["n43n14", "n53"]),
        ]

        for outcome, choices in paths:
            resp = None
            for n in range(1, len(choices) + 1):
                resp = api.move(choices[:n])

            self.assertEqual(resp.json().get("state"), outcome)
Пример #6
0
    def get(self, choices="", *args, **kwargs):
        api.create_diagnosis()

        response = api.move([c for c in choices.strip("/").split("/") if c])

        try:
            response_json = response.json()
        except ValueError:
            if current_app.config["DEBUG"]:
                return response.text
            raise

        state = response_json.get("state")
        nodes = response_json.get("nodes", [])

        if state and state != DIAGNOSIS_SCOPE.UNKNOWN:
            api.save(response_json)

            outcome_url = OUTCOME_URLS[state]
            outcome = outcome_url[2]

            if outcome:
                session.store({"outcome": outcome})

            if state == DIAGNOSIS_SCOPE.INELIGIBLE:
                outcome_url = url_for(outcome_url[0], category_name=session.checker.category_slug)
            else:
                outcome_url = url_for(outcome_url[0], **outcome_url[1])
                if state == DIAGNOSIS_SCOPE.OUTOFSCOPE:
                    outcome_url = "%s?category=%s" % (outcome_url, session.checker.category)

            return redirect(outcome_url)

        def add_link(choice):
            choices_list = [choice["id"]]
            if choices:
                choices_list.insert(0, choices.strip("/"))
            choice["url"] = url_for(".diagnosis", choices="/".join(choices_list))
            return choice

        display_choices = map(add_link, response_json.get("choices", []))

        return render_template("scope/diagnosis.html", choices=display_choices, nodes=nodes)