Esempio n. 1
0
 def test_clean_when_no_groups_given(self):
     form_data = self.form_data
     form_data['groups'] = ""
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "This field is required."
     self.assertEquals(user_form.errors['groups'], [message])
Esempio n. 2
0
 def test_clean_username_no_duplicates_on_create(self):
     form_data = self.form_data
     User.objects.create(username=form_data['username'])
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "%s is already associated to a different user." % form_data['username']
     self.assertEquals(user_form.errors['username'], [message])
Esempio n. 3
0
 def test_clean_username_no_duplicates_on_create(self):
     form_data = self.form_data
     User.objects.create(username=form_data['username'])
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "%s is already associated to a different user." % form_data['username']
     self.assertEquals(user_form.errors['username'], [message])
Esempio n. 4
0
 def test_groups_required(self):
     form_data = self.form_data.copy()
     form_data['groups'] = ''
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "This field is required."
     self.assertEquals(user_form.errors['groups'], [message])
Esempio n. 5
0
 def test_groups_required(self):
     form_data = self.form_data.copy()
     form_data['groups'] = ''
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "This field is required."
     self.assertEquals(user_form.errors['groups'], [message])
Esempio n. 6
0
 def test_country_must_belong_to_selected_region(self):
     sudan = Country.objects.create(name="Sudan", code="SDX")
     form_data = self.form_data.copy()
     form_data['country'] = sudan.id
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "%s does not belong to region %s" % (sudan.name, self.region.name)
     self.assertEquals(user_form.errors['country'], [message])
Esempio n. 7
0
 def test_clean_when_regional_admin_is_selected_with_no_organization(self):
     form_data = self.form_data
     form_data['groups'] = self.regional_admin.id
     form_data['organization'] = ""
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "This field is required."
     self.assertEquals(user_form.errors['organization'], [message])
Esempio n. 8
0
 def test_country_must_belong_to_selected_region(self):
     sudan = Country.objects.create(name="Sudan", code="SDX")
     form_data = self.form_data.copy()
     form_data['country'] = sudan.id
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "%s does not belong to region %s" % (sudan.name, self.region.name)
     self.assertEquals(user_form.errors['country'], [message])
Esempio n. 9
0
    def test_email_already_used(self):
        form_data = self.form_data
        User.objects.create(email=form_data['email'])

        user_form = UserProfileForm(form_data)
        self.assertFalse(user_form.is_valid())
        message = "%s is already associated to a different user." % form_data['email']
        self.assertEquals(user_form.errors['email'], [message])
Esempio n. 10
0
 def test_clean_when_country_admin_is_selected_with_no_country(self):
     form_data = self.form_data
     form_data['groups'] = self.country_admin.id
     form_data['country'] = ""
     user_form = UserProfileForm(form_data)
     self.assertFalse(user_form.is_valid())
     message = "This field is required."
     self.assertEquals(user_form.errors['country'], [message])
Esempio n. 11
0
    def test_email_already_used(self):
        form_data = self.form_data
        User.objects.create(email=form_data['email'])

        user_form = UserProfileForm(form_data)
        self.assertFalse(user_form.is_valid())
        message = "%s is already associated to a different user." % form_data['email']
        self.assertEquals(user_form.errors['email'], [message])
Esempio n. 12
0
    def test_clean_confirm_password(self):
        form_data = self.form_data
        form_data['password2'] = 'tank'
        user_form = UserProfileForm(form_data)
        self.assertFalse(user_form.is_valid())
        message = "The two password fields didn't match."
        self.assertEquals(user_form.errors['password2'], [message])

        form_data['password2'] = form_data['password1']
        user_form = UserProfileForm(form_data)
        self.assertTrue(user_form.is_valid())
Esempio n. 13
0
    def test_valid(self):
        user_profile_form = UserProfileForm(self.form_data)
        self.assertTrue(user_profile_form.is_valid())
        user = user_profile_form.save()
        saved_user = User.objects.get(username='******')
        self.failUnless(saved_user.id)
        self.assertEqual(1, len(saved_user.groups.all()))
        self.assertIn(self.global_admin, saved_user.groups.all())

        user_profile = UserProfile.objects.filter(user=user)
        self.failUnless(user_profile)
        self.assertEqual(user_profile[0].region, self.region)
        self.assertEqual(user_profile[0].country, self.uganda)
        self.assertEqual(user_profile[0].organization, self.organization)
Esempio n. 14
0
    def test_valid(self):
        user_profile_form = UserProfileForm(self.form_data)
        self.assertTrue(user_profile_form.is_valid())
        user = user_profile_form.save()
        saved_user = User.objects.get(username='******')
        self.failUnless(saved_user.id)
        self.assertEqual(1, len(saved_user.groups.all()))
        self.assertIn(self.global_admin, saved_user.groups.all())

        user_profile = UserProfile.objects.filter(user=user)
        self.failUnless(user_profile)
        self.assertEqual(user_profile[0].region, self.region)
        self.assertEqual(user_profile[0].country, self.uganda)
        self.assertEqual(user_profile[0].organization, self.organization)
Esempio n. 15
0
    def test_clean_confirm_password(self):
        form_data = self.form_data
        form_data['password2'] = 'tank'
        user_form = UserProfileForm(form_data)
        self.assertFalse(user_form.is_valid())
        message = "The two password fields didn't match."
        self.assertEquals(user_form.errors['password2'], [message])

        form_data['password2'] = form_data['password1']
        user_form = UserProfileForm(form_data)
        self.assertTrue(user_form.is_valid())
Esempio n. 16
0
 def test_valid_when_region_is_blank(self):
     form_data = self.form_data.copy()
     form_data['country'] = ''
     form_data['region'] = ''
     user_form = UserProfileForm(form_data)
     self.assertTrue(user_form.is_valid())
Esempio n. 17
0
 def test_valid_when_region_is_blank(self):
     form_data = self.form_data.copy()
     form_data['country'] = ''
     form_data['region'] = ''
     user_form = UserProfileForm(form_data)
     self.assertTrue(user_form.is_valid())