def findBy(klass, **attrs): """ Find all instances of the given class based on an exact match of attributes. For instance: C{User.find(first_name='Bob', last_name='Smith')} Will return all matches. """ where = dictToWhere(attrs) return klass.find(where = where)
def findBy(klass, **attrs): """ Find all instances of the given class based on an exact match of attributes. For instance: C{User.find(first_name='Bob', last_name='Smith')} Will return all matches. """ where = dictToWhere(attrs) return klass.find(where=where)
def findBy(klass, **attrs): """ Find all instances of the given class based on an exact match of attributes. For instance: C{User.find(first_name='Bob', last_name='Smith')} Will return all matches. """ transaction = None if 'transaction' in attrs: transaction = attrs['transaction'] del(attrs['transaction']) where = dictToWhere(attrs) return klass.find(where = where, transaction=transaction)
def test_dictToWhere(self): self.assertEqual(utils.dictToWhere({}), None) result = utils.dictToWhere({ 'one': 'two' }, "BLAH") self.assertEqual(result, ["(one = ?)", "two"]) result = utils.dictToWhere({ 'one': None }, "BLAH") self.assertEqual(result, ["(one is ?)", None]) result = utils.dictToWhere({ 'one': 'two', 'three': 'four' }) self.assertEqual(result, ["(three = ?) AND (one = ?)", "four", "two"]) result = utils.dictToWhere({ 'one': 'two', 'three': 'four', 'five': 'six' }, "BLAH") self.assertEqual(result, ["(five = ?) BLAH (three = ?) BLAH (one = ?)", "six", "four", "two"]) result = utils.dictToWhere({ 'one': 'two', 'three': None }) self.assertEqual(result, ["(three is ?) AND (one = ?)", None, "two"])
def test_dictToWhere(self): self.assertEqual(utils.dictToWhere({}), None) result = utils.dictToWhere({'one': 'two'}, "BLAH") self.assertEqual(result, ["(one = ?)", "two"]) result = utils.dictToWhere({'one': None}, "BLAH") self.assertEqual(result, ["(one is ?)", None]) result = utils.dictToWhere(OrderedDict([ ('one', 'two'), ('three', 'four')])) self.assertEqual(result, ["(one = ?) AND (three = ?)", "two", "four"]) result = utils.dictToWhere(OrderedDict([ ('one', 'two'), ('three', 'four'), ('five', 'six')]), "BLAH") self.assertEqual(result, ["(one = ?) BLAH (three = ?) BLAH (five = ?)", "two", "four", "six"]) result = utils.dictToWhere(OrderedDict([ ('one', 'two'), ('three', None)])) self.assertEqual(result, ["(one = ?) AND (three is ?)", "two", None])
def test_dictToWhere(self): self.assertEqual(utils.dictToWhere({}), None) result = utils.dictToWhere({'one': 'two'}, "BLAH") self.assertEqual(result, ["(one = ?)", "two"]) result = utils.dictToWhere({'one': None}, "BLAH") self.assertEqual(result, ["(one is ?)", None]) result = utils.dictToWhere( OrderedDict([('one', 'two'), ('three', 'four')])) self.assertEqual(result, ["(one = ?) AND (three = ?)", "two", "four"]) result = utils.dictToWhere( OrderedDict([('one', 'two'), ('three', 'four'), ('five', 'six')]), "BLAH") self.assertEqual(result, [ "(one = ?) BLAH (three = ?) BLAH (five = ?)", "two", "four", "six" ]) result = utils.dictToWhere( OrderedDict([('one', 'two'), ('three', None)])) self.assertEqual(result, ["(one = ?) AND (three is ?)", "two", None])