def assert_rules(rules): rank_rules = [] for model, model_rules in rules: rank_rules.extend(search._rank_rules(model, *model_rules)) sql = search._add_relevance(query, rank_rules) for _, model_rules in rules: for attr, rank1, rank2 in model_rules: self.assertTrue(('THEN %d ELSE 0' % rank1) in sql) self.assertTrue(('THEN %d ELSE 0' % rank2) in sql) self.assertTrue(attr in sql)