def test_update(self):
    url = reverse('profiles.user_update', args=[self.user1.pk])
    self.login(self.admin)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    self.assertEqual(len(response.context['form'].fields['regions'].choices), 3)
    response = self.url_post('unicef', url, dict())
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'full_name', 'This field is required.')
    self.assertFormError(response, 'form', 'email', 'This field is required.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [self.region3.pk], 'is_active': True}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertEqual(user.profile.full_name, 'Morris')
    self.assertEqual(user.email, 'example@example.com')
    self.assertEqual(user.username, 'example@example.com')
    self.assertEqual(list(user.regions.all()), [self.region3])
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [self.region3.pk], 'is_active': True}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertFormError(response, 'form', None, 'Email address already taken.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [], 'is_active': False}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertFalse(user.is_active)
def test_update(self):
    url = reverse('profiles.user_update', args=[self.user1.pk])
    self.login(self.admin)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    self.assertEqual(len(response.context['form'].fields['regions'].choices), 3)
    response = self.url_post('unicef', url, dict())
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'full_name', 'This field is required.')
    self.assertFormError(response, 'form', 'email', 'This field is required.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [self.region3.pk], 'is_active': True}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertEqual(user.profile.full_name, 'Morris')
    self.assertEqual(user.email, 'example@example.com')
    self.assertEqual(user.username, 'example@example.com')
    self.assertEqual(list(user.regions.all()), [self.region3])
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [self.region3.pk], 'is_active': True}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertFormError(response, 'form', None, 'Email address already taken.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'regions': [], 'is_active': False}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertFalse(user.is_active)