-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09073ac
commit 24fe946
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.contrib import admin | ||
from django.test import TestCase, RequestFactory | ||
from unittest.mock import patch, call | ||
from users.admin import AccountUserAdmin, ProfileInline | ||
from users.models import CustomUser | ||
|
||
class AccountUserAdminTests(TestCase): | ||
def setUp(self): | ||
self.factory = RequestFactory() | ||
self.admin = AccountUserAdmin(model=CustomUser, admin_site=admin.site) | ||
|
||
@patch('django.contrib.auth.admin.UserAdmin.add_view') | ||
def test_add_view(self, mock_add_view): | ||
request = self.factory.get('/admin/users/customuser/add/') | ||
|
||
# Call the add_view method | ||
self.admin.add_view(request) | ||
|
||
# Check that inlines is set to an empty list | ||
self.assertEqual(self.admin.inlines, []) | ||
|
||
# Check that the super add_view method was called | ||
mock_add_view.assert_called_once_with(request) | ||
|
||
@patch('django.contrib.auth.admin.UserAdmin.change_view') | ||
def test_change_view(self, mock_change_view): | ||
request = self.factory.get('/admin/users/customuser/1/change/') | ||
|
||
# Call the change_view method | ||
self.admin.change_view(request) | ||
|
||
# Check that inlines is set to [ProfileInline] | ||
self.assertEqual(self.admin.inlines, [ProfileInline]) | ||
|
||
# Check that the super change_view method was called | ||
mock_change_view.assert_called_once_with(request) |