Skip to content
Browse files

changed schema not to validate empty required elements any more

In RelaxNG, <text /> is as good as <optional><text /></optional>,
i.e. empty strings are allowed even when they should not be. Fixed
schema accordingly, which makes the entry XML with default values
not validate any more (which is fine).
  • Loading branch information...
1 parent 582dcd7 commit 72dde89913e8c0a217661984dfb3cbae8ce956ca @tgpfeiffer committed
Showing with 24 additions and 18 deletions.
  1. +9 −2 basicTests.py
  2. +15 −16 restfulOpenErpProxy.py
View
11 basicTests.py
@@ -254,6 +254,13 @@ def _isValidXml(self, ((s1, schemaxml), (s2, docxml)), node):
print log.last_error
self.assertTrue(valid)
+ def _isXmlButNotValid(self, ((s1, schemaxml), (s2, docxml)), node):
+ schema = etree.fromstring(schemaxml)
+ relaxng = etree.RelaxNG(schema)
+ doc = etree.fromstring(docxml).find("{http://www.w3.org/2005/Atom}content").find(node)
+ valid = relaxng.validate(doc)
+ self.assertFalse(valid)
+
## test collection
def test_whenAccessToProperCollectionThenValidFeed(self):
@@ -308,7 +315,7 @@ def test_whenAccessToProperDefaultsThenValidFeed(self):
None)
return d.addCallback(self._checkBody, self._isValidFeed)
- def test_whenAccessToProperDefaultsThenValidXml(self):
+ def test_whenAccessToProperDefaultsThenXmlButNotValid(self):
d1 = self.agent.request(
'GET',
'http://localhost:8068/erptest/res.partner/schema',
@@ -320,7 +327,7 @@ def test_whenAccessToProperDefaultsThenValidXml(self):
Headers({'Authorization': ['Basic %s' % self.basic]}),
None)
dl = DeferredList([d1, d2])
- return dl.addCallback(self._checkBodies, self._isValidXml, "{http://localhost:8068/erptest/res.partner/schema}res_partner")
+ return dl.addCallback(self._checkBodies, self._isXmlButNotValid, "{http://localhost:8068/erptest/res.partner/schema}res_partner")
# to be tested:
# * Last-Modified header exists and is well-formed in every response
View
31 restfulOpenErpProxy.py
@@ -366,36 +366,35 @@ def __getSchema(self, uid, request):
request.write('''<?xml version="1.0" encoding="utf-8"?>
<element name="%s" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="%s">
<interleave>
- <element name="id"><text /></element>
+ <element name="id"><data type="decimal" /></element>
''' % (self.model.replace(".", "_"), ns))
for key, val in self.desc.iteritems():
fieldtype = val['type']
required = val.has_key('required') and val['required'] or False
request.write(' <element name="%s">\n <attribute name="type" />' % key)
if fieldtype in ('many2many', 'one2many'):
- if required:
- elemName = "oneOrMore"
- else:
- elemName = "zeroOrMore"
+ elemName = required and "oneOrMore" or "zeroOrMore"
request.write('\n <%s><element name="link"><attribute name="href" /></element></%s>\n ' % (elemName, elemName))
else:
- s = ""
+ output = "\n "
# select the correct field type
if fieldtype == "many2one":
- s += '<element name="link"><attribute name="href" /></element>'
+ s = '<element name="link"><attribute name="href" /></element>'
+ output += required and s or "<optional>"+s+"</optional>"
elif fieldtype == "float":
- s += '<data type="double" />'
+ s = '<data type="double" />'
+ output += required and s or "<optional>"+s+"</optional>"
elif fieldtype == "boolean":
- s += '<choice><value>True</value><value>False</value></choice>'
+ s = '<choice><value>True</value><value>False</value></choice>'
+ output += required and s or "<optional>"+s+"</optional>"
elif fieldtype == "integer":
- s += '<data type="decimal" />'
- else:
- s += '<text />'
- # optionally surround by <optional> tag
- if required:
- request.write('\n '+s+'\n ')
+ s = '<data type="decimal" />'
+ output += required and s or "<optional>"+s+"</optional>"
else:
- request.write('\n <optional>'+s+'</optional>\n ')
+ s = required and '<data type="string"><param name="minLength">1</param></data>' or \
+ "<optional><text /></optional>"
+ output += s
+ request.write(output+'\n ')
request.write('</element>\n')
request.write('</interleave>\n</element>')
#request.write(self.desc.__repr__())

0 comments on commit 72dde89

Please sign in to comment.
Something went wrong with that request. Please try again.