def test_wrong_username(self): wrong_usernames = (' ', '.', '*', 'joe!', '###', ',.<>') for username in wrong_usernames: data = {'user': username} form = DashboardAddMemberForm(self.group, data) self.assertFalse(form.is_valid()) self.assertTrue('user' in form._errors)
def response(self, request): profile = request.user.get_profile() if request.user.is_anonymous() or not request.user.is_anonymous or \ not profile or not profile.is_team: messages.warning(request, _('Only teams are allowed to add member')) return redirect(reverse('projector_users_profile_detail', kwargs={'username': request.user.username})) form = DashboardAddMemberForm(profile.group, request.POST or None) if request.method == 'POST' and form.is_valid(): form.save() user = form.cleaned_data['user'] msg = _("User %s is now member of this team!" % user) messages.success(request, msg) return redirect(reverse('projector_users_profile_detail', kwargs={'username': request.user.username})) self.context['form'] = form self.context['profile'] = profile return self.context
def test_already_in_group(self): data = {'user': self.user.username} form = DashboardAddMemberForm(self.group, data) self.assertFalse(form.is_valid()) self.assertTrue('user' in form._errors)
def test_proper_user(self): joe = User.objects.create(username='******') data = {'user': joe.username} form = DashboardAddMemberForm(self.group, data) self.assertTrue(form.is_valid())
def test_wrong_user(self): data = {'user': '******'} form = DashboardAddMemberForm(self.group, data) self.assertFalse(form.is_valid()) self.assertTrue('user' in form._errors)