Add tests for userdbs.views.DeleteUserDatabase
This commit adds tests for the DeleteUserDatabase view and improves the grammar of flash messages of the userdbs.views module.
This commit is contained in:
parent
e6c38b632b
commit
1f700fc06a
2 changed files with 62 additions and 5 deletions
|
@ -169,7 +169,7 @@ class AddUserDatabaseTest(
|
|||
self.assertEqual(
|
||||
str(messages[0]), (
|
||||
'Successfully create new {type} database {dbname} for user '
|
||||
'{dbuser}').format(
|
||||
'{dbuser}.').format(
|
||||
type=db.db_user.db_type, dbname=db.db_name,
|
||||
dbuser=db.db_user))
|
||||
|
||||
|
@ -188,15 +188,72 @@ class ChangeDatabaseUserPasswordTest(HostingPackageAwareTestMixin, TestCase):
|
|||
'slug': userdatabase.db_name})
|
||||
|
||||
|
||||
class DeleteUserDatabaseTest(HostingPackageAwareTestMixin, TestCase):
|
||||
class DeleteUserDatabaseTest(
|
||||
HostingPackageAwareTestMixin, CustomerUserDatabaseOptionAwareTestMixin,
|
||||
TestCase
|
||||
):
|
||||
|
||||
def setUp(self):
|
||||
self.customer = User.objects.create_user(
|
||||
username=TEST_USER, password=TEST_PASSWORD)
|
||||
self.package = self._setup_hosting_package(self.customer)
|
||||
template = self._create_userdatabase_option()
|
||||
self.database = UserDatabase.objects.create_userdatabase_with_user(
|
||||
template.db_type, self.package.osuser)
|
||||
|
||||
def _get_url(self, userdatabase):
|
||||
return reverse(
|
||||
'delete_userdatabase', kwargs={
|
||||
'package': self.package.id,
|
||||
'slug': userdatabase.db_name})
|
||||
|
||||
def test_get_anonymous(self):
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_get_regular_user(self):
|
||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_get_other_regular_user(self):
|
||||
User.objects.create_user(
|
||||
'test2', password=TEST_PASSWORD)
|
||||
self.client.login(username='test2', password=TEST_PASSWORD)
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_get_staff_user(self):
|
||||
User.objects.create_superuser(
|
||||
'admin', email=TEST_EMAIL, password=TEST_PASSWORD)
|
||||
self.client.login(username='admin', password=TEST_PASSWORD)
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_get_template(self):
|
||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertTemplateUsed(
|
||||
response, 'userdbs/userdatabase_confirm_delete.html')
|
||||
|
||||
def test_get_context_data(self):
|
||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
||||
response = self.client.get(self._get_url(self.database))
|
||||
self.assertIn('database', response.context)
|
||||
self.assertEqual(response.context['database'], self.database)
|
||||
self.assertIn('hostingpackage', response.context)
|
||||
self.assertEqual(response.context['hostingpackage'], self.package)
|
||||
self.assertIn('customer', response.context)
|
||||
self.assertEqual(response.context['customer'], self.customer)
|
||||
|
||||
def test_form_valid_redirect(self):
|
||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
||||
response = self.client.post(self._get_url(self.database))
|
||||
self.assertRedirects(response, self.package.get_absolute_url())
|
||||
|
||||
def test_form_valid_message(self):
|
||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
||||
response = self.client.post(self._get_url(self.database), follow=True)
|
||||
messages = list(response.context['messages'])
|
||||
self.assertEqual(len(messages), 1)
|
||||
self.assertEqual(str(messages[0]), "Database deleted.")
|
||||
|
|
|
@ -65,7 +65,7 @@ class AddUserDatabase(
|
|||
messages.success(
|
||||
self.request,
|
||||
_('Successfully create new {type} database {dbname} for user '
|
||||
'{dbuser}').format(
|
||||
'{dbuser}.').format(
|
||||
type=userdatabase.db_user.db_type,
|
||||
dbname=userdatabase.db_name, dbuser=userdatabase.db_user)
|
||||
)
|
||||
|
@ -101,7 +101,7 @@ class ChangeDatabaseUserPassword(
|
|||
db_user = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully changed password of database user {dbuser}'
|
||||
_('Successfully changed password of database user {dbuser}.'
|
||||
).format(dbuser=db_user.name)
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
@ -130,6 +130,6 @@ class DeleteUserDatabase(
|
|||
def get_success_url(self):
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Database deleted'),
|
||||
_('Database deleted.'),
|
||||
)
|
||||
return self.get_hosting_package().get_absolute_url()
|
||||
|
|
Loading…
Reference in a new issue