def select_with_where_and_order_by(self): result = self.ds.select(person, sql.where("height IS NOT NULL"), sql.order_by("height")) firstnames = map(lambda p: p.firstname, list(result)) self.assertEqual(firstnames, [u"Annette", u"Marie-Luise", u"Diedrich", ])
def test(self): for fqdn, emails in self.data: dom, tld = split(fqdn, ".") new_domain = domain(domain=dom, tld=tld) self.ds.insert(new_domain) for addr in emails: new_domain.emails.append( email(remote_part_domain=dom, remote_part_tld=tld, local_part=addr)) # Let's check... tux4web = self.ds.select_one(domain, sql.where("domain='tux4web'")) self.assertEqual(len(tux4web.emails), 4) apple = self.ds.select_by_primary_key(domain, ("apple", "com",)) self.assertEqual(len(apple.emails), 3) result = apple.emails.select(sql.where("local_part = 'steve'")) steve = result.next() self.assertEqual(steve.local_part, "steve") self.assertEqual(steve.remote_part_domain, "apple") # The other way 'round emails = self.ds.select(email) # This will yield one select statement for each email. # This effect can be prevented by using SQL joins. # This is being worked on. for a in emails: self.assertEqual(a.remote_part_domain, a.domain.domain) new_email = email(local_part="dv") tux4web.emails.append(new_email) self.assertEqual(len(tux4web.emails), 5) result = tux4web.emails.select(sql.order_by("local_part")) result = list(result) last = result[-1] self.assertEqual(last.local_part, "support")