repair osusers.tests.test_admin
- fix test code - fix error in set_ldap_user_password stub
This commit is contained in:
parent
b993053d2a
commit
79b460c4a6
3 changed files with 32 additions and 51 deletions
|
@ -1,6 +1,7 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
* :support:`-` make tests in osusers.tests work again
|
||||
* :support:`-` minor HTML improvements
|
||||
* :support:`-` add API for gvafile task set_file_ssh_authorized_keys (requires
|
||||
gvafile >= 0.5.0 on the fileserver side)
|
||||
|
|
|
@ -52,7 +52,7 @@ def create_ldap_user(username, uid, gid, gecos, homedir, shell, password):
|
|||
|
||||
|
||||
@shared_task
|
||||
def set_ldap_user_password(self, username, password):
|
||||
def set_ldap_user_password(username, password):
|
||||
"""
|
||||
This task sets the password of an existing :py:class:`LDAP user
|
||||
<ldapentities.models.LdapUser>`.
|
||||
|
|
|
@ -3,7 +3,9 @@ from django.contrib.admin import AdminSite
|
|||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from mock import patch, Mock
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from mock import Mock
|
||||
|
||||
from osusers.models import (
|
||||
Group,
|
||||
|
@ -16,31 +18,24 @@ from osusers.admin import (
|
|||
UserCreationForm,
|
||||
)
|
||||
|
||||
Customer = get_user_model()
|
||||
|
||||
class TaskResultInlineTest(TestCase):
|
||||
|
||||
class CustomerTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.site = AdminSite()
|
||||
super(TaskResultInlineTest, self).setUp()
|
||||
|
||||
def test_get_queryset_calls_update_taskstatus(self):
|
||||
with patch('osusers.admin.admin.TabularInline.get_queryset') as mock:
|
||||
entrymock = Mock(name='entry')
|
||||
mock.return_value = [entrymock]
|
||||
requestmock = Mock(name='request')
|
||||
UserTaskResultInline(User, self.site).get_queryset(requestmock)
|
||||
entrymock.update_taskstatus.assert_calledwith()
|
||||
|
||||
def test_has_add_permissions_returns_false(self):
|
||||
self.assertFalse(
|
||||
UserTaskResultInline(User, self.site).has_add_permission(
|
||||
self, Mock(name='request'))
|
||||
)
|
||||
self.customer = Customer.objects.create_user('test')
|
||||
super(CustomerTestCase, self).setUp()
|
||||
|
||||
|
||||
class UserCreationFormTest(TestCase):
|
||||
class UserCreationFormTest(CustomerTestCase):
|
||||
|
||||
def test_clean_password2_same(self):
|
||||
form = UserCreationForm()
|
||||
form.cleaned_data = {'password1': 'secret', 'password2': 'secret'}
|
||||
form.cleaned_data = {
|
||||
'customer': self.customer,
|
||||
'password1': 'secret',
|
||||
'password2': 'secret'
|
||||
}
|
||||
self.assertEqual(form.clean_password2(), 'secret')
|
||||
|
||||
def test_clean_password2_empty(self):
|
||||
|
@ -50,7 +45,11 @@ class UserCreationFormTest(TestCase):
|
|||
|
||||
def test_clean_password2_mismatch(self):
|
||||
form = UserCreationForm()
|
||||
form.cleaned_data = {'password1': 'secretx', 'password2': 'secrety'}
|
||||
form.cleaned_data = {
|
||||
'customer': self.customer,
|
||||
'password1': 'secretx',
|
||||
'password2': 'secrety'
|
||||
}
|
||||
with self.assertRaises(forms.ValidationError) as cm:
|
||||
form.clean_password2()
|
||||
self.assertEqual(cm.exception.message, PASSWORD_MISMATCH_ERROR)
|
||||
|
@ -62,7 +61,11 @@ class UserCreationFormTest(TestCase):
|
|||
)
|
||||
def test_save_commit(self):
|
||||
form = UserCreationForm()
|
||||
form.cleaned_data = {'password1': 'secret', 'password2': 'secret'}
|
||||
form.cleaned_data = {
|
||||
'customer': self.customer,
|
||||
'password1': 'secret',
|
||||
'password2': 'secret'
|
||||
}
|
||||
user = form.save()
|
||||
self.assertIsNotNone(user)
|
||||
self.assertEqual(User.objects.get(pk=user.uid), user)
|
||||
|
@ -72,7 +75,7 @@ class UserCreationFormTest(TestCase):
|
|||
self.assertIsNone(form.save_m2m())
|
||||
|
||||
|
||||
class UserAdminTest(TestCase):
|
||||
class UserAdminTest(CustomerTestCase):
|
||||
def setUp(self):
|
||||
site = AdminSite()
|
||||
self.uadmin = UserAdmin(User, site)
|
||||
|
@ -91,11 +94,12 @@ class UserAdminTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_get_form_with_object(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(customer=self.customer)
|
||||
form = self.uadmin.get_form(Mock(name='request'), user)
|
||||
self.assertEqual(
|
||||
form.Meta.fields,
|
||||
['username', 'group', 'gecos', 'homedir', 'shell', 'uid']
|
||||
['username', 'group', 'gecos', 'homedir', 'shell', 'customer',
|
||||
'uid']
|
||||
)
|
||||
|
||||
def test_get_inline_instances_without_object(self):
|
||||
|
@ -108,7 +112,7 @@ class UserAdminTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_get_inline_instances_with_object(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(customer=self.customer)
|
||||
inlines = self.uadmin.get_inline_instances(
|
||||
Mock(name='request'), user)
|
||||
self.assertEqual(len(inlines), len(UserAdmin.inlines))
|
||||
|
@ -138,27 +142,3 @@ class GroupAdminTest(TestCase):
|
|||
self.assertEqual(len(inlines), len(GroupAdmin.inlines))
|
||||
for index in range(len(inlines)):
|
||||
self.assertIsInstance(inlines[index], GroupAdmin.inlines[index])
|
||||
|
||||
|
||||
class DeleteTaskResultAdminTest(TestCase):
|
||||
def setUp(self):
|
||||
site = AdminSite()
|
||||
self.dtradmin = DeleteTaskResultAdmin(DeleteTaskResult, site)
|
||||
super(DeleteTaskResultAdminTest, self).setUp()
|
||||
|
||||
def test_has_add_permission_returns_false_without_object(self):
|
||||
self.assertFalse(
|
||||
self.dtradmin.has_add_permission(Mock(name='request')))
|
||||
|
||||
def test_has_add_permission_returns_false_with_object(self):
|
||||
self.assertFalse(
|
||||
self.dtradmin.has_add_permission(Mock(name='request'),
|
||||
Mock(name='test')))
|
||||
|
||||
def test_get_queryset_calls_update_taskstatus(self):
|
||||
with patch('osusers.admin.admin.ModelAdmin.get_queryset') as mock:
|
||||
entrymock = Mock(name='entry')
|
||||
mock.return_value = [entrymock]
|
||||
requestmock = Mock(name='request')
|
||||
self.dtradmin.get_queryset(requestmock)
|
||||
entrymock.update_taskstatus.assert_calledwith()
|
||||
|
|
Loading…
Reference in a new issue