コード例 #1
0
    def test_update_instance(self):
        # initialize data the same way a view processing a POST would
        update_form = TestForm(self.post_data, instance=self.testobj)
        # check that form is valid - if no errors, this populates cleaned_data
        self.assertTrue(update_form.is_valid())

        instance = update_form.update_instance()
        self.assert_(isinstance(instance, TestObject))
        self.assertEqual(21, instance.int)
        self.assertEqual(False, instance.bool)
        self.assertEqual('b', instance.id)
        self.assertEqual('completely new text content', instance.longtext)
        self.assertEqual(0, instance.other_child.val)
        
        # spot check that values were set properly in the xml
        xml = instance.serialize()
        self.assert_('id="b"' in xml)
        self.assert_('<boolean>no</boolean>' in xml)

        # test save on form with no pre-existing xmlobject instance
        class SimpleForm(XmlObjectForm):
            class Meta:
                model = TestObject
                fields = ['id', 'bool', 'longtext'] # fields with simple, top-level xpaths
                # creation for nested node not yet supported in xmlmap - excluding int
                exclude = ['child']      # exclude subform to simplify testing

        new_form = SimpleForm({'id': 'A1', 'bool': True, 'longtext': 'la-di-dah'})
        self.assertTrue(new_form.is_valid())
        instance = new_form.update_instance()
        self.assert_(isinstance(instance, TestObject),
            "update_instance on unbound xmlobjectform returns correct xmlobject instance")
        self.assertEqual(True, instance.bool)
        self.assertEqual('A1', instance.id)
        self.assertEqual('la-di-dah', instance.longtext)
        # spot check values in created-from-scratch xml
        xml = instance.serialize()
        self.assert_('id="A1"' in xml)
        self.assert_('<boolean>yes</boolean>' in xml)

        # formset deletion
        data = self.post_data.copy()
        # update post data to test deleting items
        data.update({
            'children-INITIAL_FORMS': 4,        # only initial forms can be deleted
            'children-0-DELETE': True,
            'children-2-DELETE': True,
        })
        # make a copy object, since the instance will be updated by the form
        testobj = xmlmap.load_xmlobject_from_string(self.testobj.serialize(), TestObject)
        update_form = TestForm(data, instance=self.testobj)
        # check that form is valid - if no errors, this populates cleaned_data
        self.assertTrue(update_form.is_valid())
        instance = update_form.update_instance()
        # children 0 and 2 should be removed from the updated instance
        self.assert_(testobj.children[0] not in instance.children)
        self.assert_(testobj.children[2] not in instance.children)
コード例 #2
0
 def loadFixtureData(self, fname):
     data = load_fixture_data(fname)
     # if pidspace is specified, get a new pid from fedora and set it as the pid in the xml 
     if hasattr(self, 'pidspace'):
         xml = xmlmap.load_xmlobject_from_string(data, _MinimalFoxml)            
         xml.pid = self.getNextPid()
         return xml.serialize()
     else:
         return data
コード例 #3
0
 def setUp(self):
   
     # load the three xml poetry objects    
     self.poetry = dict()
     for file in self.FIXTURES:    
       filebase = file.split('.')[0]       
       self.poetry[filebase] = xmlmap.load_xmlobject_from_file(path.join(exist_fixture_path,
                             file), TestPoetryBook)
     # load the poet fixture docAuthor
     self.poet = xmlmap.load_xmlobject_from_string(self.POET_STRING, Poet)
コード例 #4
0
   def test_isvalid(self):
       self.assertTrue(self.dc.is_valid())
       
       invalid = """<oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
 <dc:title>Feet in the Fire</dc:title>
       <not_a_dc_field>bogus</not_a_dc_field>
       </oai_dc:dc>
       """
       invalid_dc = load_xmlobject_from_string(invalid, DublinCore)
       self.assertFalse(invalid_dc.is_valid())
コード例 #5
0
ファイル: db.py プロジェクト: emory-libraries/eulcore-history
    def query(self, xquery, start=1, how_many=10, **kwargs):
        """Execute an XQuery query, returning the results directly.

        :param xquery: a string XQuery query
        :param start: first index to return (1-based)
        :param how_many: maximum number of items to return
        :rtype: the resultType specified at the creation of this ExistDB;
                defaults to :class:`QueryResult`.

        """
        logger.debug("query how_many=%d start=%d args=%s\n%s" % (how_many, start, kwargs, xquery))
        xml_s = self.server.query(xquery, how_many, start, kwargs)

        # xmlrpclib tries to guess whether the result is a string or
        # unicode, returning whichever it deems most appropriate.
        # Unfortunately, :meth:`~eulcore.xmlmap.load_xmlobject_from_string`
        # requires a byte string. This means that if xmlrpclib gave us a
        # unicode, we need to encode it:
        if isinstance(xml_s, unicode):
            xml_s = xml_s.encode("UTF-8")

        return xmlmap.load_xmlobject_from_string(xml_s, self.resultType)
コード例 #6
0
 def setUp(self):
     # instance of form with no test object
     self.new_form = TestForm()
     # instance of form with test object instance
     self.testobj = xmlmap.load_xmlobject_from_string(FIXTURE_TEXT, TestObject)
     self.update_form = TestForm(instance=self.testobj)
コード例 #7
0
 def test_SubordinateComponents_noseries(self):
     # simple finding aid with no series but only a container list
     simple_dsc = """<dsc><c01 level="file"/></dsc>"""
     dsc = load_xmlobject_from_string(simple_dsc, eadmap.SubordinateComponents)
     self.assertFalse(dsc.hasSeries())
コード例 #8
0
 def setUp(self):
     self.dc = load_xmlobject_from_string(self.FIXTURE, DublinCore)