def test_self(self):
    url = reverse('profiles.user_self')
    response = self.url_get('unicef', url)
    self.assertLoginRedirect(response, 'unicef', url)
    self.login(self.superuser)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 404)
    self.login(self.admin)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    self.login(self.user1)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    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 = dict(full_name='Morris', email='example@example.com')
    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.region1])
    old_password_hash = user.password
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'new_password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertNotEqual(user.password, old_password_hash)
    old_password_hash = user.password
    self.user1.profile.change_password = True
    self.user1.profile.save()
    data = dict(full_name='Morris', email='example@example.com')
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'password', 'This field is required.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'confirm_password', "Passwords don't match.")
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertFalse(user.profile.change_password)
    self.assertNotEqual(user.password, old_password_hash)
def test_self(self):
    url = reverse('profiles.user_self')
    response = self.url_get('unicef', url)
    self.assertLoginRedirect(response, 'unicef', url)
    self.login(self.superuser)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 404)
    self.login(self.admin)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    self.login(self.user1)
    response = self.url_get('unicef', url)
    self.assertEqual(response.status_code, 200)
    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 = dict(full_name='Morris', email='example@example.com')
    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.region1])
    old_password_hash = user.password
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'new_password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertNotEqual(user.password, old_password_hash)
    old_password_hash = user.password
    self.user1.profile.change_password = True
    self.user1.profile.save()
    data = dict(full_name='Morris', email='example@example.com')
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'password', 'This field is required.')
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 200)
    self.assertFormError(response, 'form', 'confirm_password', "Passwords don't match.")
    data = {'full_name': 'Morris', 'email': 'example@example.com', 'password': 'Qwerty123', 'confirm_password': 'Qwerty123'}
    response = self.url_post('unicef', url, data)
    self.assertEqual(response.status_code, 302)
    user = User.objects.get(pk=self.user1.pk)
    self.assertFalse(user.profile.change_password)
    self.assertNotEqual(user.password, old_password_hash)