--- a/test/unittest_rset.py Tue Dec 10 12:36:50 2013 +0100
+++ b/test/unittest_rset.py Wed Dec 11 17:52:54 2013 +0100
@@ -28,6 +28,8 @@
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.rset import NotAnEntity, ResultSet, attr_desc_iterator
+from cubicweb import NoResultError, MultipleResultsError
+
def pprelcachedict(d):
res = {}
@@ -368,6 +370,39 @@
attr = etype == 'Bookmark' and 'title' or 'name'
self.assertEqual(entity.cw_attr_cache[attr], n)
+ def test_one(self):
+ self.request().create_entity('CWUser', login=u'cdevienne',
+ upassword=u'cdevienne',
+ surname=u'de Vienne',
+ firstname=u'Christophe')
+ e = self.execute('Any X WHERE X login "cdevienne"').one()
+
+ self.assertEqual(e.surname, u'de Vienne')
+
+ e = self.execute(
+ 'Any X, N WHERE X login "cdevienne", X surname N').one()
+ self.assertEqual(e.surname, u'de Vienne')
+
+ e = self.execute(
+ 'Any N, X WHERE X login "cdevienne", X surname N').one(col=1)
+ self.assertEqual(e.surname, u'de Vienne')
+
+ def test_one_no_rows(self):
+ with self.assertRaises(NoResultError):
+ self.execute('Any X WHERE X login "patanok"').one()
+
+ def test_one_multiple_rows(self):
+ self.request().create_entity(
+ 'CWUser', login=u'cdevienne', upassword=u'cdevienne',
+ surname=u'de Vienne', firstname=u'Christophe')
+
+ self.request().create_entity(
+ 'CWUser', login=u'adim', upassword='adim', surname=u'di mascio',
+ firstname=u'adrien')
+
+ with self.assertRaises(MultipleResultsError):
+ self.execute('Any X WHERE X is CWUser').one()
+
def test_related_entity_optional(self):
e = self.request().create_entity('Bookmark', title=u'aaaa', path=u'path')
rset = self.execute('Any B,U,L WHERE B bookmarked_by U?, U login L')