Exemplo n.º 1
0
 def test_push_xml_event(self):
     data = "<foo>barxml</foo>"
     _input = XMLEvent(data=data)
     self.push.input = _input
     _output = self.pull.output
     self.assertEqual(_output.data_string(), _input.data_string())
     self.assertEqual(_output.event_id, _input.event_id)
     self.assertEqual(_output.meta_id, _input.meta_id)
Exemplo n.º 2
0
 def test_push_xml_event(self):
     data = "<foo>barxml</foo>"
     _input = XMLEvent(data=data)
     self.push.input = _input
     _output = self.pull.output
     self.assertEqual(_output.data_string(), _input.data_string())
     self.assertEqual(_output.event_id, _input.event_id)
     self.assertEqual(_output.meta_id, _input.meta_id)
Exemplo n.º 3
0
 def test_xml_to_json_single_element_should_force_list(self):
     sample_xml = """
         <root>
             <sample_item force_list="True">
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], list)
     assert json_event.data['root']['sample_item'][0]['stuff'] == '45'
Exemplo n.º 4
0
 def test_xml_to_json_single_element_default_to_dict(self):
     sample_xml = """
         <root>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], Mapping)
     assert json_event.data['root']['sample_item']['stuff'] == '45'
Exemplo n.º 5
0
 def test_xml_to_json_single_element_should_force_list(self):
     sample_xml = """
         <root>
             <sample_item force_list="True">
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], list)
     assert json_event.data['root']['sample_item'][0]['stuff'] == '45'
Exemplo n.º 6
0
 def test_xml_to_json_single_element_default_to_dict(self):
     sample_xml = """
         <root>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], Mapping)
     assert json_event.data['root']['sample_item']['stuff'] == '45'
Exemplo n.º 7
0
 def test_event_property_xml_conversion(self):
     _input = XMLEvent(data={"foo": "bar"})
     self.actor.input = _input
     output = self.actor.output
     self.assertRegexpMatches(
         output.data_string(),
         "<propertiestoxml>.*<service>.*<\/service>.*<\/propertiestoxml>")
Exemplo n.º 8
0
 def test_xml_to_json_multiple_element_default_to_list(self):
     sample_xml = """
         <root>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], list)
     assert len(json_event.data['root']['sample_item']) == 3
Exemplo n.º 9
0
 def test_xml_to_json_multiple_element_default_to_list(self):
     sample_xml = """
         <root>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
             <sample_item>
                 <stuff>45</stuff>
             </sample_item>
         </root>
     """
     event = XMLEvent(data=sample_xml)
     json_event = event.convert(JSONEvent)
     assert isinstance(json_event.data['root']['sample_item'], list)
     assert len(json_event.data['root']['sample_item']) == 3
Exemplo n.º 10
0
 def test_multiple_repeated_elements_conversion(self):
     _input = XMLEvent(
         data="<root><foo>bar</foo><foo>bar</foo><foo>bar</foo></root>")
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.data_string(),
                      json.dumps({"root": {
                          "foo": ["bar", "bar", "bar"]
                      }}))
Exemplo n.º 11
0
 def test_internal_jsonified_conversion(self):
     _input = XMLEvent(
         data=
         "<jsonified_envelope><errors><foo>bar</foo></errors><errors><foo>bar</foo></errors><errors><foo>bar</foo></errors></jsonified_envelope>"
     )
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(
         output.data_string(),
         json.dumps(
             {"errors": [{
                 "foo": "bar"
             }, {
                 "foo": "bar"
             }, {
                 "foo": "bar"
             }]}))
Exemplo n.º 12
0
 def test_nested_values_conversion(self):
     _input = XMLEvent(
         data=
         "<root><foo><foo><bar>barvalue</bar></foo></foo><fubar>barfu</fubar></root>"
     )
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(
         output.data_string(),
         json.dumps({
             "root": {
                 "foo": {
                     "foo": {
                         "bar": "barvalue"
                     }
                 },
                 "fubar": "barfu"
             }
         }))
Exemplo n.º 13
0
 def test_conversion_classes(self):
     current_conversion_classes = XMLEvent().conversion_methods.keys()
     assert len(current_conversion_classes) == len(conversion_classes)
     for cur_conv_meth in current_conversion_classes:
         assert cur_conv_meth in conversion_classes
Exemplo n.º 14
0
 def test_valid_xml(self):
     _input = XMLEvent(data=valid_xml)
     self.actor.input = _input
     _output = self.actor.output
     self.assertEqual(_input.data_string(), _output.data_string())
Exemplo n.º 15
0
 def test_xml_event_class_consistency(self):
     _input = XMLEvent(data={"foo": "bar"})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.__class__, XMLEvent)
     self.assertEqual(output.data_string(), "<foo>bar</foo>")
Exemplo n.º 16
0
 def test_valid_xml(self):
     _input = XMLEvent(data=valid_xml)
     self.actor.input = _input
     _output = self.actor.output
     self.assertEqual(_input.data_string(), _output.data_string())
Exemplo n.º 17
0
 def test_invalid_xml(self):
     _input = XMLEvent(data=invalid_xml)
     self.actor.input = _input
     _output = self.actor.error
     self.assertTrue(isinstance(_output.error, MalformedEventData))
Exemplo n.º 18
0
 def test_single_root_dict_conversion(self):
     _input = XMLEvent(data="<foo>bar</foo>")
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.data_string(), json.dumps({"foo": "bar"}))