def test_valid_form_with_optionals(self): form = ProfileChangeForm(data = { 'email': '*****@*****.**', 'first_name': 'john', 'last_name': 'doe' }) self.assertTrue(form.is_valid())
def get_profile_form(self): form_kwargs = {'instance': self.object.profile} if self.request.method == 'POST': form_kwargs['data'] = self.request.POST form_kwargs['files'] = self.request.FILES return ProfileChangeForm(**form_kwargs)
def update_profile(request): """View for updating User profile.""" context = gen_alerts(request) form = ProfileChangeForm() # updates the User profile in the database. if request.method == 'POST': form = ProfileChangeForm(request.POST) if form.is_valid(): user = request.user if (form.cleaned_data['email']): user.email = form.cleaned_data['email'] if (form.cleaned_data['first_name']): user.first_name = form.cleaned_data['first_name'] if (form.cleaned_data['last_name']): user.last_name = form.cleaned_data['last_name'] user.save() request.session['notify'] = "Successfully Updated Profile!" return HttpResponseRedirect(reverse('profile')) context['form'] = form return render(request, 'profile_change.html', context)
def test_valid_form_one_optional(self): form = ProfileChangeForm(data = { 'email': '*****@*****.**' }) self.assertTrue(form.is_valid())
def test_last_name_help_text(self): form = ProfileChangeForm() self.assertEqual(form.fields['last_name'].help_text, "Enter your last name (optional).")
def test_email_field_help_text(self): form = ProfileChangeForm() self.assertEqual(form.fields['email'].help_text, "Enter an email address (optional).")
def test_last_name_field_label(self): form = ProfileChangeForm() self.assertTrue(form.fields['last_name'].label == 'Last Name')
def test_email_field_label(self): form = ProfileChangeForm() self.assertTrue(form.fields['email'].label == 'Email')