Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #6
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
Пример #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
Пример #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
Пример #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
Пример #10
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
Пример #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
Пример #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)
Пример #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)
Пример #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) 
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)