Beispiel #1
0
    def test_validate_command_choices_dictionary_list_response(
            self, validator):
        mock_client = Mock()
        mock_client.send_bg_request.return_value.output = '[{"value": "value"}]'
        validator._client = mock_client

        request = Request(
            system="foo",
            command="command1",
            parameters={"key1": "value"},
            system_version="0.0.1",
            instance_name="instance_name",
        )
        command = Mock(parameters=[
            Parameter(
                key="key1",
                choices=Choices(type="command", value="command_name"),
                optional=False,
            )
        ])

        validator.get_and_validate_parameters(request, command)
        mock_client.send_bg_request.assert_called_with(
            _command="command_name",
            _system_name="foo",
            _system_version="0.0.1",
            _instance_name="instance_name",
        )
Beispiel #2
0
 def test_update_and_validate_parameter_extract_parameter_nullable_no_default(
         self, validator):
     req = Request(system="foo", command="command1", parameters={})
     command_parameter = Parameter(key="key1",
                                   multi=False,
                                   nullable=True,
                                   default=None)
     command = Mock(parameters=[command_parameter])
     validated_parameters = validator.get_and_validate_parameters(
         req, command)
     assert validated_parameters["key1"] is None
Beispiel #3
0
 def test_validate_regex_nullable(self, validator):
     req = Request(system="foo",
                   command="command1",
                   parameters={"key1": None})
     command_parameter = Parameter(key="key1",
                                   multi=False,
                                   type="String",
                                   regex=r"^Hi.*",
                                   nullable=True)
     command = Command("test", parameters=[command_parameter])
     validator.get_and_validate_parameters(req, command)
Beispiel #4
0
    def test_validate_minimum_non_sequence(self, validator):
        req = Request(system="foo", command="command1", parameters={"key1": 5})

        command_parameter = Parameter(key="key1",
                                      multi=False,
                                      type="Integer",
                                      optional=False,
                                      minimum=3)
        command = Command("test", parameters=[command_parameter])
        validator.get_and_validate_parameters(req, command)

        command_parameter = Parameter(key="key1",
                                      multi=False,
                                      type="Integer",
                                      optional=False,
                                      minimum=10)
        command = Command("test", parameters=[command_parameter])

        with pytest.raises(ModelValidationError):
            validator.get_and_validate_parameters(req, command)
Beispiel #5
0
    def test_update_and_validate_parameter_extract_parameter_optional_no_default(
            self, validator):
        req = Request(system="foo", command="command1", parameters={})
        command_parameter = Parameter(key="key1",
                                      multi=False,
                                      optional=True,
                                      default=None)
        command = Mock(parameters=[command_parameter])

        with pytest.raises(ModelValidationError):
            validator.get_and_validate_parameters(req, command)
Beispiel #6
0
    def test_validate_regex(self, validator):
        req = Request(system="foo",
                      command="command1",
                      parameters={"key1": "Hi World!"})

        command_parameter = Parameter(key="key1",
                                      multi=False,
                                      type="String",
                                      optional=False,
                                      regex=r"^Hi.*")
        command = Command("test", parameters=[command_parameter])
        validator.get_and_validate_parameters(req, command)

        command_parameter = Parameter(key="key1",
                                      multi=False,
                                      type="String",
                                      optional=False,
                                      regex=r"^Hello.*")
        command = Command("test", parameters=[command_parameter])

        with pytest.raises(ModelValidationError):
            validator.get_and_validate_parameters(req, command)
Beispiel #7
0
 def test_validate_maximum_nullable(self, validator):
     req = Request(system="foo",
                   command="command1",
                   parameters={"key1": None})
     command_parameter = Parameter(
         key="key1",
         multi=False,
         type="Integer",
         optional=False,
         minimum=3,
         nullable=True,
     )
     command = Command("test", parameters=[command_parameter])
     validator.get_and_validate_parameters(req, command)
Beispiel #8
0
    def test_validate_command_choices_bad_value_type(self, validator):
        mock_client = Mock()
        mock_client.send_bg_request.return_value.output = '["value"]'
        validator._client = mock_client

        request = Request(
            system="foo",
            command="command1",
            parameters={"key1": "value"},
            system_version="0.0.1",
            instance_name="instance_name",
        )
        command = Mock(parameters=[
            Parameter(key="key1",
                      optional=False,
                      choices=Choices(type="command", value=1))
        ])

        with pytest.raises(ModelValidationError):
            validator.get_and_validate_parameters(request, command)
Beispiel #9
0
 def test_clean_fail_duplicate_parameter_keys(self):
     parameter = Parameter(key="foo", optional=False)
     command = Command(name="foo", parameters=[parameter, parameter])
     self.assertRaises(ModelValidationError, command.clean)
Beispiel #10
0
    def test_clean_fail_duplicate_parameter_keys(self):
        nested = Parameter(key="foo")
        p = Parameter(key="foo", optional=False, parameters=[nested, nested])

        self.assertRaises(ModelValidationError, p.clean)
Beispiel #11
0
 def test_clean(self):
     Command(name="foo", parameters=[Parameter(key="foo", optional=False)]).clean()
Beispiel #12
0
 def test_clean_fail_nullable_optional_but_no_default(self):
     p = Parameter(key="foo", optional=True, default=None, nullable=False)
     self.assertRaises(ModelValidationError, p.clean)
Beispiel #13
0
 def test_clean(self):
     Parameter(key="foo", optional=False).clean()
Beispiel #14
0
 def test_default_display_name(self):
     p = Parameter(key="foo")
     self.assertEqual(p.display_name, "foo")
Beispiel #15
0
 def test_repr(self):
     p = Parameter(key="foo", description="bar", type="Boolean", optional=False)
     self.assertEqual("<Parameter: key=foo, type=Boolean, description=bar>", repr(p))
Beispiel #16
0
 def test_str(self):
     p = Parameter(key="foo", description="bar", type="Boolean", optional=False)
     self.assertEqual("foo", str(p))