diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 12:04:32 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 12:04:32 +0100 |
commit | 113f9483a2b2863f3e7e176285e9031593843eda (patch) | |
tree | 0f8e340e919b678da9c6c6d17476cd30754a6dc2 | |
parent | 492c345e355d2ab38bf8fc331f30d7c9df119a0f (diff) |
another test passes but horrific code
-rw-r--r-- | ctrack/register/css.py | 81 | ||||
-rw-r--r-- | ctrack/register/models.py | 2 | ||||
-rw-r--r-- | ctrack/register/tests/test_css.py | 105 | ||||
-rw-r--r-- | ctrack/register/tests/test_forms.py | 1 | ||||
-rw-r--r-- | ctrack/register/tests/test_models.py | 2 |
5 files changed, 123 insertions, 68 deletions
diff --git a/ctrack/register/css.py b/ctrack/register/css.py new file mode 100644 index 0000000..0c49fcd --- /dev/null +++ b/ctrack/register/css.py @@ -0,0 +1,81 @@ +from dataclasses import dataclass +from typing import NamedTuple, List + +from ctrack.register.models import EventType, EventBase, CAFSingleDateEvent + + +class TagAttributes(NamedTuple): + inline_style: str + id_str: str + + +def tag_attrs(event) -> TagAttributes: + if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: + return TagAttributes( + inline_style='style="background-color: green; color: white;"', + id_str="caf-initial-received-event", + ) + if event.type_descriptor == EventType.CAF_INITIAL_REVIEW_COMPLETE.name: + return TagAttributes( + inline_style='style="background-color: green; color: white;"', + id_str="caf-initial-review-complete-event", + ) + + +template = ( + "<tr>\n" + " <td>{0}</td>\n" + " {1}\n" + " {2}\n" + " <td>OES Revisions Submitted</td>\n" + " <td>Validation Agreed</td>\n" + " <td>Improvement Plan Submitted</td>\n" + " <td>Improvement Plan Review</td>\n" + "</tr>\n" +) + + +class Swimlane: + def __init__(self, org_name: str, events: List[EventBase]): + self.events = events + self.org_name = org_name + self.slots = CAFSwimlaneSlots(*events) # type: CAFSwimlaneSlots + + @property + def tr(self): + initial_submitted_str = "".join( + [ + "<td ", + tag_attrs(self.slots.initial_submitted).inline_style, + ">", + self.slots.initial_submitted.type_descriptor, + "</td>" + ] + ) + revision_completed_str = "".join( + [ + "<td ", + tag_attrs(self.slots.reviewed).inline_style, + ">", + self.slots.reviewed.type_descriptor, + "</td>" + ] + ) + return template.format( + self.org_name, initial_submitted_str, revision_completed_str + ) + + +@dataclass(frozen=True) +class CAFSwimlaneSlots: + """ + The pre-compliance stages we expect. + """ + + initial_submitted: CAFSingleDateEvent = None + reviewed: CAFSingleDateEvent = None + revisions_submitted: CAFSingleDateEvent = None + validation_agreed: CAFSingleDateEvent = None + improvement_plan_submitted: CAFSingleDateEvent = None + improvement_plan_reviewed: CAFSingleDateEvent = None + improvement_plan_agreed: CAFSingleDateEvent = None diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 34dc880..475de9e 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -19,6 +19,7 @@ class EventType(Enum): EMAIL = auto() # single date caf events CAF_INITIAL_CAF_RECEIVED = auto() + CAF_INITIAL_REVIEW_COMPLETE = auto() CAF_FEEDBACK_EMAILED_OES = auto() CAF_RECEIVED = auto() CAF_EMAILED_ROSA = auto() @@ -211,6 +212,7 @@ class SingleDateTimeEvent( class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin): AVAILABLE_TYPES = [ (EventType.CAF_INITIAL_CAF_RECEIVED.name, "CAF - Initial CAF Received"), + (EventType.CAF_INITIAL_REVIEW_COMPLETE.name, "CAF - Initial Review Complete"), (EventType.CAF_FEEDBACK_EMAILED_OES.name, "CAF - Emailed to OES"), (EventType.CAF_RECEIVED.name, "CAF - Received"), (EventType.CAF_EMAILED_ROSA.name, "CAF - Emailed to Rosa"), diff --git a/ctrack/register/tests/test_css.py b/ctrack/register/tests/test_css.py index 1b72a23..8c9f77a 100644 --- a/ctrack/register/tests/test_css.py +++ b/ctrack/register/tests/test_css.py @@ -1,26 +1,11 @@ -from dataclasses import dataclass -from typing import NamedTuple, List, Optional - import pytest -from ctrack.register.models import CAFSingleDateEvent, EventType, EventBase +from ctrack.register.css import tag_attrs, Swimlane, CAFSwimlaneSlots +from ctrack.register.models import CAFSingleDateEvent, EventType pytestmark = pytest.mark.django_db -class TagAttributes(NamedTuple): - inline_style: str - id_str: str - - -def tag_attrs(event) -> TagAttributes: - if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: - return TagAttributes( - inline_style='style="background-color: green; color: white;"', - id_str="caf-initial-received-event", - ) - - @pytest.mark.parametrize( "e_type,css_str,id_str", [ @@ -28,6 +13,11 @@ def tag_attrs(event) -> TagAttributes: EventType.CAF_INITIAL_CAF_RECEIVED.name, 'style="background-color: green; color: white;"', "caf-initial-received-event", + ), + ( + EventType.CAF_INITIAL_REVIEW_COMPLETE.name, + 'style="background-color: green; color: white;"', + "caf-initial-review-complete-event", ) ], ) @@ -39,56 +29,6 @@ def test_can_get_class_string(caf, user, e_type, css_str, id_str): assert tag_attrs(event).id_str == id_str -template = ( - "<tr>\n" - " <td>{0}</td>\n" - " {1}\n" - " <td>CAF Reviewed</td>\n" - " <td>OES Revisions Submitted</td>\n" - " <td>Validation Agreed</td>\n" - " <td>Improvement Plan Submitted</td>\n" - " <td>Improvement Plan Review</td>\n" - "</tr>\n" -) - - -class Swimlane: - def __init__(self, org_name: str, events: List[EventBase]): - self.events = events - self.org_name = org_name - self.slots = CAFSwimlaneSlots(*events) # type: CAFSwimlaneSlots - - @property - def tr(self): - initial_submitted_str = "".join( - [ - "<td ", - tag_attrs(self.slots.initial_submitted).inline_style, - ">", - self.slots.initial_submitted.type_descriptor, - "</td>" - ] - ) - return template.format( - self.org_name, initial_submitted_str - ) - - -@dataclass(frozen=True) -class CAFSwimlaneSlots: - """ - The pre-compliance stages we expect. - """ - - initial_submitted: CAFSingleDateEvent = None - reviewed: CAFSingleDateEvent = None - revisions_submitted: CAFSingleDateEvent = None - validation_agreed: CAFSingleDateEvent = None - improvement_plan_submitted: CAFSingleDateEvent = None - improvement_plan_reviewed: CAFSingleDateEvent = None - improvement_plan_agreed: CAFSingleDateEvent = None - - class _TestEvent(CAFSingleDateEvent): def __init__(self, event): self.type_descriptor = event @@ -107,7 +47,7 @@ def test_swimlane_slots(): assert slots.initial_submitted.type_descriptor == "CAF Initial Submitted" -def test_progress_chart_slots(caf, user): +def test_progress_chart_css_initial_review_only(caf, user): accept = ( "<tr>\n" " <td>{}</td>\n" @@ -128,3 +68,32 @@ def test_progress_chart_slots(caf, user): ) output = Swimlane(org_name, [caf_initial]) assert output.tr == accept.format(org_name) + + +def test_progress_chart_css_initial_two_events(caf, user): + accept = ( + "<tr>\n" + " <td>{}</td>\n" + " <td style=\"background-color: green; color: white;\">CAF_INITIAL_CAF_RECEIVED</td>\n" + " <td style=\"background-color: green; color: white;\">CAF_INITIAL_REVIEW_COMPLETE</td>\n" + " <td>OES Revisions Submitted</td>\n" + " <td>Validation Agreed</td>\n" + " <td>Improvement Plan Submitted</td>\n" + " <td>Improvement Plan Review</td>\n" + "</tr>\n" + ) + org_name = caf.organisation.name + caf_initial = CAFSingleDateEvent.objects.create( + type_descriptor=EventType.CAF_INITIAL_CAF_RECEIVED.name, + related_caf=caf, + date="2020-10-20", + user=user, + ) + caf_reviewed = CAFSingleDateEvent.objects.create( + type_descriptor=EventType.CAF_INITIAL_REVIEW_COMPLETE.name, + related_caf=caf, + date="2020-10-20", + user=user, + ) + output = Swimlane(org_name, [caf_initial, caf_reviewed]) + assert output.tr == accept.format(org_name) diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 5a055b6..c002c1c 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -131,6 +131,7 @@ def test_create_note(user, org_with_people): [ "CAF_INITIAL_CAF_RECEIVED", "CAF_RECEIVED", + "CAF_INITIAL_REVIEW_COMPLETE", "CAF_FEEDBACK_EMAILED_OES", "CAF_EMAILED_ROSA", "CAF_VALIDATION_SIGN_OFF", diff --git a/ctrack/register/tests/test_models.py b/ctrack/register/tests/test_models.py index 1a89fd5..1e8351b 100644 --- a/ctrack/register/tests/test_models.py +++ b/ctrack/register/tests/test_models.py @@ -17,6 +17,7 @@ pytestmark = pytest.mark.django_db "allowed_type", [ "CAF_INITIAL_CAF_RECEIVED", + "CAF_INITIAL_REVIEW_COMPLETE", "CAF_FEEDBACK_EMAILED_OES", "CAF_RECEIVED", "CAF_EMAILED_ROSA", @@ -151,6 +152,7 @@ def test_event_type_enum(): assert EventType.VIDEO_CALL.name == "VIDEO_CALL" assert EventType.EMAIL.name == "EMAIL" assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED" + assert EventType.CAF_INITIAL_REVIEW_COMPLETE.name == "CAF_INITIAL_REVIEW_COMPLETE" assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES" assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED" assert EventType.CAF_EMAILED_ROSA.name == "CAF_EMAILED_ROSA" |