def search(tags=None, tag_ids=None): """ Find all objects whose tags make superset of given tags. If any unknown tag given or none tags given at all, returns None. Otherwise, returns SearchCache object. """ if tags: tags = split_tags(tags) if not tags: return None # if no tag given, don't just return all objects # what if an unknown tag is in the list? tag_ids = list(get_available_tags(tags).values_list('id', flat=True)) if len(tag_ids) != len(tags): return None # unknown tag given elif not tag_ids: return None else: tag_ids = split_tag_ids(tag_ids) # Sort by id before calling. return _search_and_cache(sorted(tag_ids))
def test_split_tag_ids(self): CHECK = lambda x, y, z = None: self.assertEqual(split_tag_ids(x), y, z) CHECK("123", [123]) CHECK("10,20,30,40,50,15", [10, 20, 30, 40, 50, 15]) CHECK("50, 40, 30, 25", [50, 40, 30, 25]) CHECK([20, 10, 30], [20, 10, 30], "should accept lists")