예제 #1
0
    def test_it_calls_from_question_and_render(self):
        ctx = mock.Mock()
        question = mock.Mock()
        data = mock.Mock()
        errors = mock.Mock()

        with mock.patch("dmcontent.govuk_frontend.from_question") as from_question:
            with mock.patch("dmcontent.govuk_frontend.render") as render:
                # with default args
                render_question(ctx, question)

                assert from_question.call_args == mock.call(question, None, None)
                assert render.call_args == mock.call(
                    ctx,
                    from_question(question, None, None),
                    question=question
                )

                # with args and kwargs
                render_question(ctx, question, data, errors, some_kwarg="foobar")

                assert from_question.call_args == mock.call(
                    question, data, errors, some_kwarg="foobar"
                )
                assert render.call_args == mock.call(
                    ctx,
                    from_question(question, data, errors, some_kwarg="foobar"),
                    question=question
                )
예제 #2
0
    def test_from_question_with_data(self, question, snapshot):
        data = {"oneAndAnother": "one"}

        form = from_question(question, data)

        assert "value" not in form["params"]
        assert form["params"]["items"][0]["checked"] is True

        data = {"oneAndAnother": ["one", "another"]}
        form = from_question(question, data)
        assert form["params"]["items"][0]["checked"] is True
        assert form["params"]["items"][1]["checked"] is True
        assert form == snapshot
예제 #3
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "cost": {
                "input_name": "cost",
                "href": "#input-cost",
                "question": "What's the cost?",
                "message": "Enter a cost.",
            },
            "priceRange": {
                "input_name": "priceRange",
                "href": "#input-priceRange-minPrice",
                "question": "What's the price range?",
                "message": "Enter a price range.",
            },
        }

        form = from_question(question, errors=errors)

        if "params" in form:
            assert form["params"]["errorMessage"]
        elif "components" in form:
            pytest.skip("TODO: get errors working with pricing form with multiple fields")
            assert form["errorMessage"]
            # TODO: get errors working for indivual fields in the pricing form
            # this will require changes to validation of pricing forms
            for component in form["components"]:
                assert "--error" in component["params"]["classes"]
        else:
            raise ValueError("form should have params or a fieldset")

        assert form == snapshot
예제 #4
0
    def test_from_question_with_data(self, question, snapshot):
        data = {"howMany": "10"}

        form = from_question(question, data)

        assert form["params"]["value"] == "10"
        assert form == snapshot
예제 #5
0
    def test_from_question_with_data(self, question, snapshot):
        data = {"yesOrNo": "yes"}

        form = from_question(question, data)

        assert "value" not in form["params"]
        assert form["params"]["items"][0]["checked"] is True
        assert "checked" not in form["params"]["items"][1]
        assert form == snapshot
예제 #6
0
    def test_from_question_with_data(self, question, snapshot):
        data = {"startDate-day": 1, "startDate-month": 12, "startDate-year": 2020}

        form = from_question(question, data)

        assert "value" not in form["params"]
        assert form["params"]["items"][0]["value"] == 1
        assert form["params"]["items"][1]["value"] == 12
        assert form["params"]["items"][2]["value"] == 2020
        assert form == snapshot
예제 #7
0
    def test_with_errors(self, question, snapshot):
        errors = {
            "culturalFitCriteria": {
                "input_name": "culturalFitCriteria",
                "href": "#input-culturalFitCriteria",
                "question": "Cultural fit criteria",
                "message": "Enter at least one criterion.",
            }
        }

        assert from_question(question, errors=errors) == snapshot
예제 #8
0
    def test_with_errors(self, question, snapshot):
        errors = {
            "description": {
                "input_name": "description",
                "href": "#input-description",
                "question": "Description",
                "message": "Enter a description of the specialist's role.",
            }
        }

        assert from_question(question, errors=errors) == snapshot
예제 #9
0
    def test_with_errors(self, question, snapshot):
        errors = {
            "title": {
                "input_name": "title",
                "href": "#input-title",
                "question": "What you want to call your requirements",
                "message": "Enter a title.",
            }
        }

        assert from_question(question, errors=errors) == snapshot
예제 #10
0
    def test_from_question_with_data(self, question, snapshot):
        data = {
            "question": "What is going on?",
            "answer": "I don't know.",
        }

        form = from_question(question, data)

        assert form[1]["params"]["value"] == "What is going on?"
        assert form[2]["params"]["value"] == "I don't know."

        assert form == snapshot
예제 #11
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "howMany": {
                "input_name": "howMany",
                "href": "#input-howMany",
                "question": "How many?",
                "message": "Enter how many",
            }
        }

        form = from_question(question, errors=errors)

        assert "errorMessage" in form["params"]
        assert form == snapshot
예제 #12
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "oneAndAnother": {
                "input_name": "title",
                "href": "#input-oneAndAnother",
                "question": "Select one and/or another.",
                "message": "Select one or another",
            }
        }

        form = from_question(question, errors=errors)

        assert "errorMessage" in form["params"]
        assert form == snapshot
예제 #13
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "startDate": {
                "input_name": "startDate",
                "href": "#input-startDate-day",
                "question": "What is the latest start date?",
                "message": "Enter a start date",
            }
        }

        form = from_question(question, errors=errors)

        assert "errorMessage" in form["params"]
        assert form == snapshot
예제 #14
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "yesOrNo": {
                "input_name": "title",
                "href": "#input-yesOrNo",
                "question": "Yes or no?",
                "message": "Select yes or no,",
            }
        }

        form = from_question(question, errors=errors)

        assert "errorMessage" in form["params"]
        assert form == snapshot
예제 #15
0
    def test_from_question_with_followup_with_data(self, question_with_followup, snapshot):
        data = {
            "yesNo": "True",
            "tellUsMore": "Gosh, there's a lot to say.",
        }

        form = from_question(question_with_followup, data)

        assert form[1]["params"]["items"][0]["checked"]
        assert (
            form[1]["params"]["items"][0]["conditional"]["html"][0]["params"]["value"]
            == "Gosh, there's a lot to say."
        )

        assert form == snapshot
예제 #16
0
    def test_from_question_with_data(self, question, snapshot):
        data = {
            "cost": "1.00",
            "minPrice": "10.00",
            "maxPrice": "50.00",
        }

        form = from_question(question, data)

        self.assert_params(
            lambda params: params["value"] in data.values(),
            form
        )

        assert form == snapshot
예제 #17
0
    def test_from_question_with_followup_with_errors(self, question_with_followup, snapshot):
        errors = {
            "tellUsMore": {
                "input_name": "tellUsMore",
                "href": "#input-answer",
                "question": "Tell us more",
                "message": "Enter an answer.",
            },
        }

        form = from_question(question_with_followup, errors=errors)

        assert "errorMessage" not in form[1]["params"]
        assert form[1]["params"]["items"][0]["conditional"]["html"][0]["params"]["errorMessage"]

        assert form == snapshot
예제 #18
0
    def test_from_question_with_multiple_followups_with_data(self, question_with_multiple_followups, snapshot):
        data = {
            "yesNo": "True",
            "tellUsMore": "Gosh, there's a lot to say.",
            "letUsContactYou": "*****@*****.**",
        }

        form = from_question(question_with_multiple_followups, data)

        assert form[1]["params"]["items"][0]["checked"]
        assert (
            form[1]["params"]["items"][0]["conditional"]["html"][0]["params"]["value"]
            == "Gosh, there's a lot to say."
        )
        assert (
            form[1]["params"]["items"][0]["conditional"]["html"][1]["params"]["value"]
            == "*****@*****.**"
        )

        assert form == snapshot
예제 #19
0
    def test_from_question_with_errors(self, question, snapshot):
        errors = {
            "question": {
                "input_name": "question",
                "href": "#input-question",
                "question": "What's the question?",
                "message": "Enter a question.",
            },
            "answer": {
                "input_name": "answer",
                "href": "#input-answer",
                "question": "What's the answer?",
                "message": "Enter an answer.",
            },
        }

        form = from_question(question, errors=errors)

        assert form[1]["params"]["errorMessage"]
        assert form[2]["params"]["errorMessage"]

        assert form == snapshot
예제 #20
0
    def test_from_question_with_multiple_followups_with_errors(self, question_with_multiple_followups, snapshot):
        errors = {
            "tellUsMore": {
                "input_name": "tellUsMore",
                "href": "#input-answer",
                "question": "Tell us more",
                "message": "Enter an answer.",
            },
            "letUsContactYou": {
                "input_name": "letUsContactYou",
                "href": "#input-other-answer",
                "question": "Enter your email so we can ask you to tell us even more",
                "message": "Enter an email",
            }
        }

        form = from_question(question_with_multiple_followups, errors=errors)

        assert "errorMessage" not in form[1]["params"]
        assert form[1]["params"]["items"][0]["conditional"]["html"][0]["params"]["errorMessage"]
        assert form[1]["params"]["items"][0]["conditional"]["html"][1]["params"]["errorMessage"]

        assert form == snapshot
예제 #21
0
 def test_from_question_with_multiple_followups(self, question_with_multiple_followups, snapshot):
     assert from_question(question_with_multiple_followups) == snapshot
예제 #22
0
 def test_from_question_with_followup(self, question_with_followup, snapshot):
     assert from_question(question_with_followup) == snapshot
예제 #23
0
 def test_from_question(self, question, snapshot):
     form = from_question(question)
     assert snapshot == form
예제 #24
0
    def test_from_question(self, question, snapshot):
        form = from_question(question)

        assert form["macro_name"] == "dmListInput"
        assert form["params"] == snapshot
예제 #25
0
 def test_from_question_with_errors(self, question, errors, snapshot):
     form = from_question(question, errors=errors)
     assert snapshot == form
예제 #26
0
    def test_with_data(self, question, snapshot):
        data = {
            "title": "Find an individual specialist",
        }

        assert from_question(question, data) == snapshot
예제 #27
0
    def test_from_question_with_is_page_heading_false(self, question, snapshot):
        form = from_question(question, is_page_heading=False)

        assert form["macro_name"] == "govukInput"
        assert form["params"] == snapshot
예제 #28
0
    def test_with_data(self, question, snapshot):
        data = {
            "culturalFitCriteria": ["Must know how to make tea", "Must believe unicorns"],
        }

        assert from_question(question, data) == snapshot
예제 #29
0
 def test_from_question(self, question, snapshot):
     assert from_question(question) == snapshot
예제 #30
0
 def test_from_question_with_data(self, question, data, snapshot):
     form = from_question(question, data=data)
     assert form == snapshot