Ejemplo n.º 1
0
 def test_date_field_returns_none_when_xpathed_value_for_the_node_is_none(
         self):
     xml_string = '<root><kiddie><value></value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = DateField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEqual(None, response)
Ejemplo n.º 2
0
 def test_bool_field_returns_true_when_xpathed_value_for_the_node_is_true(
         self):
     xml_string = '<root><kiddie1><value>true</value></kiddie1></root>'
     xml = xpath.domify(xml_string)
     field = BoolField(xpath='/root/kiddie1/value')
     response = field.parse(xml, None)
     self.assertEqual(True, response)
Ejemplo n.º 3
0
 def test_date_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>2008-06-21T10:36:12</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = DateField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     date = datetime.datetime(2008, 0o6, 21, 10, 36, 12)
     self.assertEqual(date, response)
Ejemplo n.º 4
0
 def test_date_field_strips_utc_offset_from_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>2008-06-21T10:36:12-06:00</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = DateField(xpath='/root/kiddie/value')
     response = field.parse(xml,None)
     date = datetime.datetime(2008,06,21,10,36,12)
     self.assertEquals(date, response)
Ejemplo n.º 5
0
 def test_date_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = "<root><kiddie><value>2008-06-21T10:36:12</value></kiddie></root>"
     xml = xpath.domify(xml_string)
     field = DateField(xpath="/root/kiddie/value")
     response = field.parse(xml, None)
     date = datetime.datetime(2008, 06, 21, 10, 36, 12)
     self.assertEquals(date, response)
Ejemplo n.º 6
0
Archivo: base.py Proyecto: MVReddy/TMS
 def _get_xml(self):
     if self._dom is None:
         try :
             self._dom = xpath.domify(self._xml)
         except Exception, e:
             print self._xml
             print str(e)
             raise e
Ejemplo n.º 7
0
 def _get_xml(self):
     if self._dom is None:
         try:
             self._dom = xpath.domify(self._xml)
         except Exception, e:
             print self._xml
             print str(e)
             raise e
Ejemplo n.º 8
0
 def test_int_field_raises_exception_when_non_int_value_is_parsed(self):
     xml_string = '<root><kiddie><value>NaN</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/root/kiddie/value')
     try:
         response = field.parse(xml, None)
         self.fail('Should have raised an exception')
     except:
         pass
Ejemplo n.º 9
0
 def test_int_field_raises_exception_when_non_int_value_is_parsed(self):
     xml_string = '<root><kiddie><value>NaN</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/root/kiddie/value')
     try:
         response = field.parse(xml, None)
         self.fail('Should have raised an exception')
     except:
         pass
Ejemplo n.º 10
0
Archivo: base.py Proyecto: MVReddy/TMS
    def parse(self, xml, namespace):
        matches = xpath.find_all(xml, self.xpath, namespace)

        if not xml_models.BaseField in self.field_type.__bases__:
            results = CollectionList(type=self.field_type)
            for match in matches:
                results.append(self.field_type(xml=match))
        else:
            field = self.field_type(xpath = '.')
            results = [field.parse(xpath.domify(match), namespace) for match in matches]
        if self.order_by:
            results.sort(lambda a,b : cmp(getattr(a, self.order_by), getattr(b, self.order_by)))
        return results
Ejemplo n.º 11
0
    def parse(self, xml, namespace):
        matches = xpath.find_all(xml, self.xpath, namespace)

        if not xml_models.BaseField in self.field_type.__bases__:
            results = CollectionList(type=self.field_type)
            for match in matches:
                results.append(self.field_type(xml=match))
        else:
            field = self.field_type(xpath='.')
            results = [
                field.parse(xpath.domify(match), namespace)
                for match in matches
            ]
        if self.order_by:
            results.sort(lambda a, b: cmp(getattr(a, self.order_by),
                                          getattr(b, self.order_by)))
        return results
Ejemplo n.º 12
0
 def test_int_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>123</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEquals(123, response)
Ejemplo n.º 13
0
 def test_char_field_reads_from_attribute(self):
     xml_string = '<Listing><Details><Bathrooms comment="Nice Baths">6</Bathrooms></Details></Listing>'
     xml = xpath.domify(xml_string)
     field = CharField(xpath='/Listing/Details/Bathrooms/@comment')
     response = field.parse(xml, None)
     self.assertEquals('Nice Baths', response)
Ejemplo n.º 14
0
 def test_char_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>Muppets rock</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = CharField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEquals('Muppets rock', response) 
Ejemplo n.º 15
0
 def test_bool_field_returns_true_when_xpathed_value_for_the_node_is_true(self):
     xml_string = '<root><kiddie1><value>true</value></kiddie1></root>'
     xml = xpath.domify(xml_string)
     field = BoolField(xpath='/root/kiddie1/value')
     response = field.parse(xml, None)
     self.assertEquals(True, response)
Ejemplo n.º 16
0
 def test_date_field_returns_none_when_xpathed_value_for_the_node_is_none(self):
     xml_string = '<root><kiddie><value></value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = DateField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEquals(None, response)
Ejemplo n.º 17
0
 def test_bool_field_returns_false_when_xpathed_value_for_the_node_is_false(self):
     xml_string = "<root><kiddie1><value1>false</value1></kiddie1></root>"
     xml = xpath.domify(xml_string)
     field = BoolField(xpath="/root/kiddie1/value1")
     response = field.parse(xml, None)
     self.assertEquals(False, response)
Ejemplo n.º 18
0
 def test_char_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>Muppets rock</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = CharField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEqual('Muppets rock', response)
Ejemplo n.º 19
0
 def test_int_field_returns_xpathed_value_for_the_node_passed_in(self):
     xml_string = '<root><kiddie><value>123</value></kiddie></root>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEqual(123, response)
Ejemplo n.º 20
0
 def test_char_field_reads_from_attribute(self):
     xml_string = '<Listing><Details><Bathrooms comment="Nice Baths">6</Bathrooms></Details></Listing>'
     xml = xpath.domify(xml_string)
     field = CharField(xpath='/Listing/Details/Bathrooms/@comment')
     response = field.parse(xml, None)
     self.assertEqual('Nice Baths', response)
Ejemplo n.º 21
0
 def test_int_field_reads_from_attribute(self):
     xml_string = '<Listing id="123"/>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/Listing/@id')
     response = field.parse(xml, None)
     self.assertEquals(123, response)
Ejemplo n.º 22
0
 def test_int_field_reads_from_attribute(self):
     xml_string = '<Listing id="123"/>'
     xml = xpath.domify(xml_string)
     field = IntField(xpath='/Listing/@id')
     response = field.parse(xml, None)
     self.assertEqual(123, response)