def test_save(self): """ Filling the ProfileForm with data should cause the Profile to be updated. """ data = { 'username': '******', 'name': 'First Last', 'email': '*****@*****.**', 'description': 'New Description', 'location': 'Where I am', 'website': 'http://www.google.com/' } form = forms.ProfileForm(data, instance=self.user) self.assertTrue(form.is_valid()) instance = form.save() self.assertEqual(instance.username, 'newusername') self.assertEqual(instance.first_name, 'First') self.assertEqual(instance.last_name, 'Last') self.assertEqual(instance.email, '*****@*****.**') self.assertEqual(instance.get_profile().description, 'New Description') self.assertEqual(instance.get_profile().location, 'Where I am') self.assertEqual(instance.get_profile().website, 'http://www.google.com/')
def profile(request): if request.method == 'POST': form = forms.ProfileForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): user = form.save() if request.POST.get('delete_logo'): profile = user.get_profile() if profile.logo: profile.logo.delete() return HttpResponseRedirect(request.path) else: form = forms.ProfileForm(instance=request.user) return render_to_response('localtv/user_profile/edit.html', {'form': form}, context_instance=RequestContext(request))
def test_save_no_changes(self): """ A blank form should have all the data to simply resave and not cause any changes. """ blank_form = forms.ProfileForm(instance=self.user) initial = blank_form.initial.copy() for name, field in blank_form.fields.items(): if field.initial: initial[name] = field.initial form = forms.ProfileForm(initial, instance=self.user) self.assertTrue(form.is_valid(), form.errors) instance = form.save() self.assertEqual(instance.username, self.user.username) self.assertEqual(instance.first_name, self.user.first_name) self.assertEqual(instance.last_name, self.user.last_name) self.assertEqual(instance.email, self.user.email) self.assertEqual(instance.get_profile().description, self.profile.description) self.assertEqual(instance.get_profile().location, self.profile.location) self.assertEqual(instance.get_profile().website, self.profile.website)