コード例 #1
0
class TestChoices(object):
    def test_str(self):
        assert str(Choices(value="value")) == "value"

    def test_repr(self):
        choices = Choices(type="static",
                          display="select",
                          strict=True,
                          value=[1])
        assert "static" in repr(choices)
        assert "select" in repr(choices)
        assert "[1]" in repr(choices)

    @pytest.mark.parametrize(
        "choice_obj",
        [
            Choices(type="static", value="SHOULD_BE_A_LIST"),
            Choices(type="url", value=[1, 2]),
            Choices(type="command", value=[1, 2]),
            Choices(type="command", value={"command": "foo"}),
        ],
    )
    def test_clean_value_types(self, choice_obj):
        with pytest.raises(ModelValidationError):
            choice_obj.clean()

    def test_clean_static(self):
        choice = Choices(type="static", value=["a", "b", "c"])
        choice.clean()
        assert choice.details == {}

    def test_clean_parse(self):
        choice = Choices(type="command", value="foo")
        choice.clean()
        assert choice.details == {"name": "foo", "args": []}

    def test_clean_with_details(self):
        choice = Choices(type="command", value="foo", details={"non": "empty"})
        choice.clean()

        assert choice.details == {"non": "empty"}

    @pytest.mark.parametrize(
        "value",
        [
            "foo${arg",
            "http://foo?arg=${val",
            {
                "command": "foo${arg",
                "system": "foo",
                "version": "1.0.0",
                "instance_name": "default",
            },
        ],
    )
    def test_clean_bad_parse(self, value):
        with pytest.raises(ModelValidationError):
            Choices(type="command", value=value).clean()
コード例 #2
0
 def test_repr(self):
     choices = Choices(type="static",
                       display="select",
                       strict=True,
                       value=[1])
     assert "static" in repr(choices)
     assert "select" in repr(choices)
     assert "[1]" in repr(choices)
コード例 #3
0
 def test_str(self):
     assert str(Choices(value="value")) == "value"
コード例 #4
0
 def test_clean_bad_parse(self, value):
     with pytest.raises(ModelValidationError):
         Choices(type="command", value=value).clean()
コード例 #5
0
    def test_clean_with_details(self):
        choice = Choices(type="command", value="foo", details={"non": "empty"})
        choice.clean()

        assert choice.details == {"non": "empty"}
コード例 #6
0
 def test_clean_parse(self):
     choice = Choices(type="command", value="foo")
     choice.clean()
     assert choice.details == {"name": "foo", "args": []}
コード例 #7
0
 def test_clean_static(self):
     choice = Choices(type="static", value=["a", "b", "c"])
     choice.clean()
     assert choice.details == {}