def assertQueryResult(self, query: QuerySet, item_lists: [[any]]): expected_items = [] for item_list in item_lists: expected_items = expected_items + item_list expected_items = unique(expected_items, operator.attrgetter('id')) self.assertCountEqual(list(query), expected_items)
def parse_tag_string(tag_string: str, delimiter: str = ','): if not tag_string: return [] names = tag_string.strip().split(delimiter) names = [name.strip() for name in names if name] names = unique(names, str.lower) names.sort(key=str.lower) return names
def _parse_query_string(query_string): # Sanitize query params if not query_string: query_string = '' # Split query into search terms and tags keywords = query_string.strip().split(' ') keywords = [word for word in keywords if word] search_terms = [word for word in keywords if word[0] != '#'] tag_names = [word[1:] for word in keywords if word[0] == '#'] tag_names = unique(tag_names, str.lower) return { 'search_terms': search_terms, 'tag_names': tag_names, }
def get_or_create_tags(tag_names: List[str], user: User): tags = [get_or_create_tag(tag_name, user) for tag_name in tag_names] return unique(tags, operator.attrgetter('id'))