Changeset View
Changeset View
Standalone View
Standalone View
bid_main/tests/test_delete.py
| """Tests for the Delete account section of the profile.""" | """Tests for the Delete account section of the profile.""" | ||||
| from datetime import timedelta | from datetime import timedelta | ||||
| from unittest.mock import patch | |||||
| from django.contrib.auth import get_user_model | from django.contrib.auth import get_user_model | ||||
| from django.test import TestCase | from django.test import TestCase | ||||
| from django.urls import reverse | from django.urls import reverse | ||||
| from django.utils import timezone | from django.utils import timezone | ||||
| import oauth2_provider.models as oa2_models | import oauth2_provider.models as oa2_models | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | def test_does_not_override_set_date(self): | ||||
| } | } | ||||
| ) | ) | ||||
| self.assertEqual(200, response.status_code, f"response: {response}") | self.assertEqual(200, response.status_code, f"response: {response}") | ||||
| self.assertIn("We are sad to see you go", str(response.content)) | self.assertIn("We are sad to see you go", str(response.content)) | ||||
| deleted_user.refresh_from_db() | deleted_user.refresh_from_db() | ||||
| self.assertFalse(deleted_user.is_active) | self.assertFalse(deleted_user.is_active) | ||||
| # The date wasn't updated | # The date wasn't updated | ||||
| self.assertEquals(deleted_user.date_deletion_requested, current_date) | self.assertEquals(deleted_user.date_deletion_requested, current_date) | ||||
| @patch('bid_main.email.send_mail') | |||||
| def test_sends_an_email(self, mock_send_mail): | |||||
| self.client.force_login(self.user) | |||||
| response = self.client.post( | |||||
| reverse("bid_main:delete_user"), | |||||
| { | |||||
| "confirm": True, | |||||
| } | |||||
| ) | |||||
| self.assertEqual(200, response.status_code, f"response: {response}") | |||||
| self.assertIn('We are sad to see you go', str(response.content)) | |||||
| mock_send_mail.assert_called_once() | |||||
| self.assertEquals( | |||||
| mock_send_mail.call_args.args[0], | |||||
| 'Deletion of your Blender ID account', | |||||
| ) | |||||
| self.assertEquals( | |||||
| mock_send_mail.call_args.kwargs['recipient_list'], | |||||
| [self.user.email], | |||||
| ) | |||||