def test_get_user_docs_by_username(self): users = [self.ccuser_1, self.web_user, self.ccuser_other_domain] usernames = [u.username for u in users] + ['*****@*****.**'] self.assertItemsEqual( get_user_docs_by_username(usernames), [u.to_json() for u in users] )
def check_existing_usernames(user_specs, domain): usernames_without_ids = set() invalid_usernames = set() for row in user_specs: username = row.get('username') user_id = row.get('user_id') if username and user_id: continue try: usernames_without_ids.add(normalize_username(username, domain)) except ValidationError: invalid_usernames.add(username) if invalid_usernames: raise UserUploadError( _('The following usernames are invalid: ' + ', '.join(invalid_usernames))) existing_usernames = [ u.get('username') for u in get_user_docs_by_username(usernames_without_ids) ] if existing_usernames: raise UserUploadError( _("The following usernames already exist and must " "have an id specified to be updated: " + ', '.join(existing_usernames)))
def dashboard_users(self): usernames = User.objects.filter( username__regex=r'^\d*\.[a-zA-Z]*@.*').values_list('username', flat=True) user_docs = list() for user_list in chunked(usernames, 200): user_docs.extend(get_user_docs_by_username(user_list)) return user_docs
def check_existing_usernames(user_specs, domain): usernames_without_ids = set() invalid_usernames = set() for row in user_specs: username = row.get('username') user_id = row.get('user_id') if username and user_id: continue try: usernames_without_ids.add(normalize_username(username, domain)) except ValidationError: invalid_usernames.add(username) if invalid_usernames: raise UserUploadError(_('The following usernames are invalid: ' + ', '.join(invalid_usernames))) existing_usernames = [u.get('username') for u in get_user_docs_by_username(usernames_without_ids)] if existing_usernames: raise UserUploadError(_("The following usernames already exist and must " "have an id specified to be updated: " + ', '.join(existing_usernames)))