Esempio 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)
Esempio 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)
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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>")
Esempio 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
Esempio 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
Esempio 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"]
                      }}))
Esempio 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"
             }]}))
Esempio 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"
             }
         }))
Esempio 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
Esempio 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())
Esempio 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>")
Esempio 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())
Esempio 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))
Esempio 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"}))