@@ -0,0 +1,2750 @@
+from django.test import TestCase%0Afrom django.core.exceptions import ValidationError%0Afrom myhpom.tests.factories import UserFactory%0Afrom myhpom.forms.profile import EditUserDetailsForm%0Afrom myhpom.models import State%0Afrom myhpom.models.user_details import GENDER_CHOICES%0Afrom datetime import date%0A%0A%0Aclass EditProfileUserDetailsFormTestCase(TestCase):%0A    %22%22%22%0A    * nothing is required except state%0A    * form.is_valid()==False when values are not valid for model (e.g., gender not in choices)%0A    * when a State object is given to data, the cleaned_data has State.name%0A    * on save, cleaned_data.state must match an existing State object else ValueError    %0A    %22%22%22%0A%0A    def setUp(self):%0A        state = self.state = State.objects.first()%0A        self.valid_data = %5B%0A            %7B'state': state%7D,%0A            %7B'state': state.name%7D,%0A            %7B'state': state, 'gender': GENDER_CHOICES%5B0%5D%5B0%5D%7D,%0A            %7B'state': state, 'birthdate': date.today()%7D,  # date object ok%0A            %7B'state': state, 'birthdate': date.today().strftime('%25Y-%25m-%25d')%7D,  # ISO format ok%0A            %7B'state': state, 'zip_code': '8' * 10%7D,  # length ok%0A            %7B'state': state, 'phone': '8' * 32%7D,  # length ok%0A        %5D%0A        self.invalid_data = %5B%0A            %7B%7D,  # state is required%0A            %7B'state': 'UU'%7D,  # state must exist%0A            %7B'state': state, 'gender': 'NON_CONFORMING_TO_GENDER_CHOICES'%7D,  # invalid gender%0A            %7B'state': state, 'birthdate': 'today'%7D,  # not a date%0A            %7B'state': state, 'zip_code': '8' * 20%7D,  # too long%0A            %7B'state': state, 'phone': '8' * 40%7D,  # too long%0A        %5D%0A%0A    def test__without_instance(self):%0A        for data in self.valid_data:%0A            form = EditUserDetailsForm(data=data)%0A            self.assertTrue(form.is_valid())%0A            self.assertEqual(form.cleaned_data%5B'state'%5D, self.state.name)%0A        for data in self.invalid_data:%0A            form = EditUserDetailsForm(data=data)%0A            self.assertFalse(form.is_valid())%0A            for key in %5Bkey for key in data.keys() if key != 'state'%5D:%0A                self.assertIn(key, form.errors)%0A%0A    def test__with_instance(self):%0A        user = UserFactory()%0A        userdetails = user.userdetails%0A        for data in self.valid_data:%0A            form = EditUserDetailsForm(data=data, instance=userdetails)%0A            self.assertTrue(form.is_valid())%0A            form.save() # ok%0A        for data in self.invalid_data:%0A            form = EditUserDetailsForm(data=data, instance=userdetails)%0A            self.assertFalse(form.is_valid())%0A            for key in %5Bkey for key in data.keys() if key != 'state'%5D:%0A                self.assertIn(key, form.errors)%0A            with self.assertRaises(ValueError):%0A                form.save()%0A

test profile.EditUserDetailsForm