2015-12-07 01:22:13 +01:00
|
|
|
"""
|
|
|
|
This module contains explicit tests for corner cases in
|
|
|
|
:py:mod:`userdbs.signals` that are not handled by the tests in
|
|
|
|
:py:mod:`userdbs.tests.test_models`.
|
|
|
|
|
|
|
|
"""
|
2019-01-30 21:27:25 +01:00
|
|
|
from unittest.mock import Mock
|
2015-12-07 01:22:13 +01:00
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.utils import override_settings
|
|
|
|
|
|
|
|
from taskresults.models import TaskResult
|
2019-01-30 21:27:25 +01:00
|
|
|
from userdbs.signals import (
|
|
|
|
handle_dbuser_created,
|
|
|
|
handle_dbuser_deleted,
|
|
|
|
handle_dbuser_password_set,
|
|
|
|
handle_userdb_created,
|
|
|
|
handle_userdb_deleted,
|
|
|
|
)
|
2015-12-07 01:22:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
@override_settings(
|
2019-01-30 21:27:25 +01:00
|
|
|
CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND="memory", BROKER_BACKEND="memory"
|
2015-12-07 01:22:13 +01:00
|
|
|
)
|
|
|
|
class TestCaseWithCeleryTasks(TestCase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class TestWithUnknownDBType(TestCaseWithCeleryTasks):
|
|
|
|
def test_handle_dbuser_password_set_unknown(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
instance = Mock(data={"name": "test", "db_type": -1})
|
|
|
|
handle_dbuser_password_set(Mock(name="sender"), instance, "secret")
|
2015-12-07 01:22:13 +01:00
|
|
|
self.assertFalse(TaskResult.objects.exists())
|
|
|
|
|
|
|
|
def test_handle_dbuser_create_unknown(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
instance = Mock(data={"name": "test", "db_type": -1})
|
|
|
|
handle_dbuser_created(Mock(name="sender"), instance, True, password="secret")
|
2015-12-07 01:22:13 +01:00
|
|
|
self.assertFalse(TaskResult.objects.exists())
|
|
|
|
|
|
|
|
def test_handle_dbuser_deleted_unknown(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
instance = Mock(data={"name": "test", "db_type": -1})
|
|
|
|
handle_dbuser_deleted(Mock(name="sender"), instance)
|
2015-12-07 01:22:13 +01:00
|
|
|
self.assertFalse(TaskResult.objects.exists())
|
|
|
|
|
|
|
|
def test_handle_userdb_created_unknown(self):
|
|
|
|
instance = Mock(
|
|
|
|
data={
|
2019-01-30 21:27:25 +01:00
|
|
|
"db_name": "test",
|
|
|
|
"db_user": Mock(data={"name": "test", "db_type": -1}),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
handle_userdb_created(Mock(name="sender"), instance, True)
|
2015-12-07 01:22:13 +01:00
|
|
|
self.assertFalse(TaskResult.objects.exists())
|
|
|
|
|
|
|
|
def test_handle_userdb_deleted_unknown(self):
|
|
|
|
instance = Mock(
|
|
|
|
data={
|
2019-01-30 21:27:25 +01:00
|
|
|
"db_name": "test",
|
|
|
|
"db_user": Mock(data={"name": "test", "db_type": -1}),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
handle_userdb_deleted(Mock(name="sender"), instance)
|
2015-12-07 01:22:13 +01:00
|
|
|
self.assertFalse(TaskResult.objects.exists())
|