def test_delete(self): u = User(email='*****@*****.**') u.is_active = True u.save() p = Profile(contact_email='*****@*****.**', user=u) p.save() r = Recommendation(profile=p, reviewer_email='*****@*****.**') r.save() self.client.force_login(u) response = self.client.get(reverse('profiles:user_delete')) self.assertEqual(response.status_code, HTTPStatus.OK) User.objects.get(id=u.id) response = self.client.post(reverse('profiles:user_delete'), data={ 'confirm': True, }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:login')) with self.assertRaises(User.DoesNotExist): User.objects.get(id=u.id) with self.assertRaises(Profile.DoesNotExist): Profile.objects.get(id=p.id) Recommendation.objects.get(id=r.id)
def test_account_changepassword(self): u = User(email='*****@*****.**') u.is_active = True u.set_password('Myunittest1!') u.save() self.client.force_login(u) response = self.client.get(reverse('profiles:user_change_password')) self.assertEqual(response.status_code, HTTPStatus.OK) response = self.client.post(reverse('profiles:user_change_password'), data={ 'old_password': '******', 'new_password1': 'myunittest1!passchange', 'new_password2': 'myunittest1!passchange', }) self.assertEqual(response.status_code, HTTPStatus.OK) self.assertIn('old_password', response.context['form'].errors) response = self.client.post(reverse('profiles:user_change_password'), data={ 'old_password': '******', 'new_password1': 'Myunittest1!passchange', 'new_password2': 'Myunittest1!passchange', }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:user'))
def test_account_edit(self): u = User(email='*****@*****.**') u.username = '******' u.name = 'Unit Test' u.is_active = True u.set_password('Myunitarytest1!') u.save() self.client.force_login(u) with self.settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend'): response = self.client.post(reverse('profiles:user_edit'), { 'username': u.username, 'name': 'Another Unit Test', 'email': u.email, }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:user')) self.assertEqual(len(mail.outbox), 1) u.refresh_from_db() self.assertTrue(u.is_active) self.assertEqual(u.name, 'Another Unit Test')
def test_profile_delete(self): u = User(email='*****@*****.**') u.is_active = True u.save() p = Profile(contact_email='*****@*****.**', user=u) p.save() r = Recommendation(profile=p, reviewer_email='*****@*****.**') r.save() self.client.force_login(u) response = self.client.get(reverse('profiles:user_profile_delete')) self.assertEqual(response.status_code, HTTPStatus.OK) User.objects.get(id=u.id) response = self.client.post(reverse('profiles:user_profile_delete'), data={ 'confirm': True, }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:user')) p = Profile.all_objects.get(id=p.id) self.assertNotEquals(p.deleted_at, None)
def test_account_page(self): u = User(email='*****@*****.**') u.is_active = True u.save() self.client.force_login(u) response = self.client.get(reverse('profiles:user')) self.assertEqual(response.status_code, HTTPStatus.OK) self.assertContains(response, '*****@*****.**')
def test_account_login(self): u = User(email='*****@*****.**') u.is_active = True u.set_password('Myunitarytest1!') u.save() next = reverse('profiles:user_edit') response = self.client.get(reverse('profiles:login') + '?next=' + next) response = self.client.post(reverse('profiles:login'), { 'username': '******', 'password': '******', }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, next)
def test_account_edit_email(self): u = User(email='*****@*****.**') u.username = '******' u.name = 'Unit Test' u.is_active = True u.set_password('Myunitarytest1!') u.save() self.client.force_login(u) with self.settings( EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend'): response = self.client.post(reverse('profiles:user_edit'), { 'username': u.username, 'name': 'Another Unit Test', 'email': '*****@*****.**', }, follow=True) self.assertRedirects( response, reverse('profiles:login') + '?next=' + reverse('profiles:user')) self.assertEqual(response.status_code, HTTPStatus.OK) self.assertEqual(len(mail.outbox), 2) self.assertEqual(mail.outbox[0].to, ['*****@*****.**']) self.assertEqual(mail.outbox[1].to, ['*****@*****.**']) u.refresh_from_db() self.assertFalse(u.is_active) self.assertEqual(u.name, 'Another Unit Test') self.assertEqual(u.email, '*****@*****.**') token = mail.outbox[0].context['token'] self.assertTrue('user_confirmation_token' in self.client.session) self.assertEqual(self.client.session['user_confirmation_token'], token) response = self.client.get(reverse('profiles:signup_confirm'), data={ 'token': token, }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:user'))
def test_profile_delete_new(self): u = User(email='*****@*****.**') u.is_active = True u.save() p = Profile(contact_email='*****@*****.**', user=u) p.save() self.client.force_login(u) response = self.client.get(reverse('profiles:user_profile_delete')) self.assertEqual(response.status_code, HTTPStatus.OK) User.objects.get(id=u.id) response = self.client.post(reverse('profiles:user_profile_delete'), data={ 'confirm': True, }) self.assertEqual(response.status_code, HTTPStatus.FOUND) self.assertEqual(response.url, reverse('profiles:user')) with self.assertRaises(Profile.DoesNotExist): p.refresh_from_db()