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 = set() for usernames in chunked(usernames_without_ids, 500): existing_usernames.update(get_existing_usernames(usernames)) if existing_usernames: raise UserUploadError( _("The following usernames already exist and must " "have an id specified to be updated: " + ', '.join(existing_usernames)))
def test_get_existing_usernames(self): users = [self.ccuser_1, self.web_user, self.ccuser_other_domain, self.retired_user] usernames = [u.username for u in users] + ['*****@*****.**'] self.assertItemsEqual( get_existing_usernames(usernames), [u.username for u in users] )
def test_get_existing_usernames(self): users = [self.ccuser_1, self.web_user, self.ccuser_other_domain] usernames = [u.username for u in users] + ['*****@*****.**'] self.assertItemsEqual( get_existing_usernames(usernames), [u.username for u in users] )
def get_exising_users(self): usernames_without_ids = set() for row in self.all_specs: username = row.get('username') if row.get('user_id') or not username: continue try: usernames_without_ids.add( normalize_username(username, self.domain)) except ValidationError: pass existing_usernames = set() for usernames in chunked(usernames_without_ids, 500): existing_usernames.update(get_existing_usernames(usernames)) return existing_usernames
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 = set() for usernames in chunked(usernames_without_ids, 500): existing_usernames.update(get_existing_usernames(usernames)) if existing_usernames: raise UserUploadError(_("The following usernames already exist and must " "have an id specified to be updated: " + ', '.join(existing_usernames)))