• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ministryofjustice / cla_public / 21210

18 Apr 2024 09:48AM UTC coverage: 73.867% (-0.1%) from 74.006%
21210

Pull #1256

circleci

said-moj
Add field description
Pull Request #1256: WIP LGA-3027 - Add hlpas page after user fails means

2 of 8 new or added lines in 3 files covered. (25.0%)

1 existing line in 1 file now uncovered.

2216 of 3000 relevant lines covered (73.87%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.65
/cla_public/apps/scope/views.py
1
# coding: utf-8
2
from cla_common.constants import DIAGNOSIS_SCOPE
1✔
3
from cla_public.apps.base.utils import check_categories
1✔
4
from cla_public.apps.checker.views import HelpOrganisations
1✔
5
from cla_public.apps.scope import scope
1✔
6
from cla_public.apps.scope.api import diagnosis_api_client as api
1✔
7
from cla_public.libs.views import RequiresSession
1✔
8
from flask import views, render_template, current_app, url_for, redirect, session
1✔
9

10

11
OUTCOME_URLS = {
1✔
12
    DIAGNOSIS_SCOPE.INSCOPE: ("checker.interstitial", {}, None),
13
    DIAGNOSIS_SCOPE.INELIGIBLE: ("scope.ineligible", None, "referred/help-organisations/scope"),
14
    DIAGNOSIS_SCOPE.OUTOFSCOPE: ("scope.ineligible", {"category_name": "legal-adviser"}, "referred/f2f/scope"),
15
    DIAGNOSIS_SCOPE.MEDIATION: ("scope.ineligible", {"category_name": "mediation"}, "referred/mediation/scope"),
16
    DIAGNOSIS_SCOPE.CONTACT: ("contact.get_in_touch", {}, "incomplete"),
17
}
18

19

20
@scope.after_request
1✔
21
def add_header(response):
22
    """
23
    Add no-cache headers
24
    """
25
    response.headers["Cache-Control"] = "no-cache, must-revalidate, no-store, max-age=0"
1✔
26
    response.headers["Pragma"] = "no-cache"
1✔
27
    return response
1✔
28

29

30
class ScopeDiagnosis(RequiresSession, views.MethodView):
1✔
31
    # flake8: noqa: C901
32
    def get(self, choices="", *args, **kwargs):
1✔
33
        api.create_diagnosis()
×
34

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

37
        try:
×
38
            response_json = response.json()
×
39
        except ValueError:
×
40
            if current_app.config["DEBUG"]:
×
41
                return response.text
×
42
            raise
×
43

44
        state = response_json.get("state")
×
45
        nodes = response_json.get("nodes", [])
×
46

47
        if state and state != DIAGNOSIS_SCOPE.UNKNOWN:
×
48
            api.save(response_json)
×
49

50
            outcome_url = OUTCOME_URLS[state]
×
51
            outcome = outcome_url[2]
×
52

53
            if outcome:
×
54
                session.store({"outcome": outcome})
×
55

56
            if state == DIAGNOSIS_SCOPE.INELIGIBLE:
×
57
                outcome_url = url_for(outcome_url[0], category_name=session.checker.category_slug)
×
58
            else:
59
                try:
×
60
                    is_hlpas = "yes" if nodes[-2]["context"]["hlpas"].lower() == "true" else "no"
×
61
                except Exception:
×
62
                    is_hlpas = "no"
×
63

64
                outcome_url[1]["hlpas"] = is_hlpas
×
NEW
65
                session.store(dict(hlpas=is_hlpas))
×
66

67
                if state == DIAGNOSIS_SCOPE.OUTOFSCOPE:
×
68
                    category = self.get_category_for_larp(session)
×
69
                    outcome_url[1]["category"] = category
×
70

71
                outcome_url = url_for(outcome_url[0], **outcome_url[1])
×
72

73
            return redirect(outcome_url)
×
74

75
        def add_link(choice):
×
76
            choices_list = [choice["id"]]
×
77
            if choices:
×
78
                choices_list.insert(0, choices.strip("/"))
×
79
            choice["url"] = url_for(".diagnosis", choices="/".join(choices_list))
×
80
            return choice
×
81

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

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

86
    def get_category_for_larp(self, session):
1✔
87
        categories_list = ["n88", "n149"]
×
88
        if check_categories(session, categories_list):
×
89
            return "traffickingandslavery"
×
90
        return session.checker.category
×
91

92

93
class ScopeIneligible(HelpOrganisations):
1✔
94
    _template = "scope/ineligible.html"
1✔
95

96

97
class ScopeMediation(views.MethodView):
1✔
98
    def get(self):
1✔
99
        session.clear_checker()
×
100
        return render_template("scope/mediation.html")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc