Exemplo n.º 1
0
    def test_xml_escaping(self):
        cmd = XmlCommand('foo')
        cmd.add_element('bar', 'Foo & Bar')

        self.assertEqual(cmd.to_string(), '<foo><bar>Foo &amp; Bar</bar></foo>')

        cmd = XmlCommand('foo')
        cmd.set_attribute('bar', 'Foo & Bar')

        self.assertEqual(cmd.to_string(), '<foo bar="Foo &amp; Bar"/>')

        cmd = XmlCommand('foo')
        cmd.set_attribute('bar', 'Foo "Bar"')

        self.assertEqual(cmd.to_string(), '<foo bar="Foo &quot;Bar&quot;"/>')
Exemplo n.º 2
0
    def test_add_filter_id(self):
        cmd = XmlCommand("test")
        filter_id = "foo"

        add_filter(cmd, filter_string=None, filter_id=filter_id)

        self.assertEqual(cmd.to_string(), '<test filt_id="foo"/>')
Exemplo n.º 3
0
    def authenticate(self, username: str, password: str) -> Any:
        """Authenticate to gvmd.

        The generated authenticate command will be send to server.
        Afterwards the response is read, transformed and returned.

        Arguments:
            username: Username
            password: Password

        Returns:
            Transformed response from server.
        """
        cmd = XmlCommand("authenticate")

        if not username:
            raise RequiredArgument(function=self.authenticate.__name__,
                                   argument="username")

        if not password:
            raise RequiredArgument(function=self.authenticate.__name__,
                                   argument="password")

        credentials = cmd.add_element("credentials")
        credentials.add_element("username", username)
        credentials.add_element("password", password)

        self._send(cmd.to_string())
        response = self._read()

        if check_command_status(response):
            self._authenticated = True

        return self._transform(response)
Exemplo n.º 4
0
    def test_should_allow_to_set_attributes(self):
        cmd = XmlCommand('foo')
        cmd.set_attributes(OrderedDict([('bar', '1'), ('baz', '2')]))

        self.assertEqual(cmd.to_string(), '<foo bar="1" baz="2"/>')
Exemplo n.º 5
0
    def test_should_allow_to_set_attribute(self):
        cmd = XmlCommand('foo')
        cmd.set_attribute('bar', '1')

        self.assertEqual(cmd.to_string(), '<foo bar="1"/>')
Exemplo n.º 6
0
    def test_should_allow_to_add_element_with_text(self):
        cmd = XmlCommand('foo')
        cmd.add_element('bar', '1')

        self.assertEqual(cmd.to_string(), '<foo><bar>1</bar></foo>')
Exemplo n.º 7
0
    def test_should_create_command(self):
        cmd = XmlCommand('foo')

        self.assertEqual(cmd.to_string(), '<foo/>')
Exemplo n.º 8
0
    def test_should_allow_to_set_attributes(self):
        cmd = XmlCommand('foo')
        cmd.set_attributes({'bar': '1', 'baz': '2'})

        self.assertEqual(cmd.to_string(), '<foo bar="1" baz="2"/>')
Exemplo n.º 9
0
    def test_should_allow_to_set_attributes(self):
        cmd = XmlCommand("foo")
        cmd.set_attributes(OrderedDict([("bar", "1"), ("baz", "2")]))

        self.assertEqual(cmd.to_string(), '<foo bar="1" baz="2"/>')
Exemplo n.º 10
0
    def test_should_allow_to_set_attribute(self):
        cmd = XmlCommand("foo")
        cmd.set_attribute("bar", "1")

        self.assertEqual(cmd.to_string(), '<foo bar="1"/>')
Exemplo n.º 11
0
    def test_should_allow_to_add_element_with_text(self):
        cmd = XmlCommand("foo")
        cmd.add_element("bar", "1")

        self.assertEqual(cmd.to_string(), "<foo><bar>1</bar></foo>")
Exemplo n.º 12
0
    def test_should_create_command(self):
        cmd = XmlCommand("foo")

        self.assertEqual(cmd.to_string(), "<foo/>")