def setUp(self): group_a = Group.objects.create(name='group-a') group_b = Group.objects.create(name='group-b') self.user_a = create_user('*****@*****.**') self.user_b = create_user('*****@*****.**') self.user_c = create_user('*****@*****.**') self.user_a.groups.add(group_a) self.user_b.groups.add(group_a, group_b) self.task_type_a = TaskType.objects.create(name='task-type-a') self.task_type_a.group = group_a self.task_type_b = TaskType.objects.create(name='task-type-b') self.task_type_b.group = group_b self.task_type_c = TaskType.objects.create(name='task-type-c')
def setUp(self): self.email = '*****@*****.**' self.user = create_user(self.email) self.sender = create_user('*****@*****.**') self.sf = create_submission_form() self.sf.sponsor_email = self.email self.sf.investigator_email = self.email self.sf.submitter_email = self.email self.user.save() self.sender.save() self.sf.save()
def test_password_reset(self): '''Makes sure that a user can reset his password, by following the link in a password reset mail message, setting a new password and performing a test login with the newly set password. ''' user = create_user('*****@*****.**') user.set_password('password') user.save() response = self.client.post(reverse('ecs.users.views.request_password_reset'), { 'email': '*****@*****.**', }) self.assertEqual(response.status_code, 200) mimetype, message = self.get_mimeparts(self.queue_get(0), "text", "html")[0] # XXX: how do we get the right url without knowing its path-prefix? (FMD1) match = re.search(rb'href="https?://[^/]+(/password-reset/[^"]+)"', message) self.assertTrue(match) password_reset_url = match.group(1) response = self.client.get(password_reset_url) self.assertEqual(response.status_code, 200) self.assertTrue('form' in response.context) response = self.client.post(password_reset_url, { 'new_password1': '12345678', 'new_password2': '12345678', }) self.assertEqual(response.status_code, 200) user = get_user('*****@*****.**') self.assertTrue(user.check_password('12345678')) response = self.client.get(password_reset_url) self.assertEqual(response.status_code, 200) self.assertFalse('form' in response.context)
def save(self): self.instance = create_user(self.cleaned_data['email'], first_name=self.cleaned_data['first_name'], last_name=self.cleaned_data['last_name']) user = super().save() user.profile.forward_messages_after_minutes = 5 user.profile.save() return user
def _create_test_user(self, name, **profile_attrs): email = '{0}@example.com'.format(name) user = create_user(email) user.set_password(email) user.save() profile = user.profile for name, value in profile_attrs.items(): setattr(profile, name, value) profile.save() return user
def test_password_change(self): '''Makes sure that a password can be changed, by changing a password and performing a test-login afterwards with the changed password. ''' user = create_user('*****@*****.**') user.set_password('test') user.save() self.client.login(email='*****@*****.**', password='******') url = reverse('ecs.users.views.change_password') response = self.client.get(url) self.assertEqual(response.status_code, 200) response = self.client.post(url, { 'old_password': '******', 'new_password1': '12345678', 'new_password2': '12345678', }) self.assertEqual(response.status_code, 200) self.client.logout() user = get_user('*****@*****.**') self.assertTrue(user.check_password('12345678'))
def setUp(self, *args, **kwargs): testuser = create_user('*****@*****.**') testuser.set_password('4223') testuser.save() return super().setUp(*args, **kwargs)
def handle(self, *args, **options): username = options.get('username', None) email = options.get('email', None) interactive = options.get('interactive') if username: raise DeprecationWarning('there is no such thing as a username') if not interactive: if not email: raise CommandError('You must use --email with --noinput') try: is_valid_email(email) except exceptions.ValidationError: raise CommandError('Invalid email address.') password = '' if interactive: try: while 1: if not email: email = input('Email: ') try: is_valid_email(email) except exceptions.ValidationError: sys.stderr.write( 'Error: That e-mail address is invalid.\n') email = None else: try: User.objects.get(username=hash_email(email)) except User.DoesNotExist: break else: print( 'Error: That e-mail address is already taken.', file=sys.stderr) email = None while 1: if not password: password = getpass.getpass('Password:'******'Password: (again):') if password != password2: print('Error: Your passwords didn\'t match.', file=sys.stderr) password = None continue if password.strip() == '': print('Error: Blank passwords aren\'t allowed.', file=sys.stderr) password = None continue break except KeyboardInterrupt: print('Operation cancelled.', file=sys.stderr) sys.exit(1) u = create_user(email, is_superuser=True, is_staff=True, is_active=True) u.set_password(password) u.save() print('Superuser created successfully.')