def test_xml_escaping(self): cmd = XmlCommand('foo') cmd.add_element('bar', 'Foo & Bar') self.assertEqual(cmd.to_string(), '<foo><bar>Foo & Bar</bar></foo>') cmd = XmlCommand('foo') cmd.set_attribute('bar', 'Foo & Bar') self.assertEqual(cmd.to_string(), '<foo bar="Foo & Bar"/>') cmd = XmlCommand('foo') cmd.set_attribute('bar', 'Foo "Bar"') self.assertEqual(cmd.to_string(), '<foo bar="Foo "Bar""/>')
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"/>')
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)
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"/>')
def test_should_allow_to_set_attribute(self): cmd = XmlCommand('foo') cmd.set_attribute('bar', '1') self.assertEqual(cmd.to_string(), '<foo bar="1"/>')
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>')
def test_should_create_command(self): cmd = XmlCommand('foo') self.assertEqual(cmd.to_string(), '<foo/>')
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"/>')
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"/>')
def test_should_allow_to_set_attribute(self): cmd = XmlCommand("foo") cmd.set_attribute("bar", "1") self.assertEqual(cmd.to_string(), '<foo bar="1"/>')
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>")
def test_should_create_command(self): cmd = XmlCommand("foo") self.assertEqual(cmd.to_string(), "<foo/>")