OpenSlides/server/tests/unit/users/test_user_backend.py
FinnStutzenstein 2bcab5d098
Repository restructure
- moved all server related things into the folder `server`, so this
configuration is parallel to the client.
- All main "services" are now folders in the root directory
- Added Dockerfiles to each service (currently server and client)
- Added a docker compose configuration to start everything together.
Currently there are heavy dependencies into https://github.com/OpenSlides/openslides-docker-compose
- Resturctured the .gitignore. If someone needs something excluded,
please add it to the right section.
- Added initial build setup with Docker and docker-compose.
- removed setup.py. We won't deliver OpenSlides via pip anymore.
2020-08-21 08:11:13 +02:00

57 lines
1.6 KiB
Python

from typing import List
from unittest import TestCase
from openslides.users.user_backend import (
BaseUserBackend,
UserBackendException,
UserBackendManager,
)
class TUserBackend(BaseUserBackend):
disallowed_update_keys = ["test_key1", "another_test_key"]
@property
def name(self) -> str:
return "test_backend"
def get_disallowed_update_keys(self) -> List[str]:
return self.disallowed_update_keys
class UserManagerTest(TestCase):
def setUp(self):
self.manager = UserBackendManager()
def test_register_backend(self):
self.manager.register_user_backend(TUserBackend())
self.assertTrue("test_backend" in self.manager.backends)
def test_get_backend(self):
backend = TUserBackend()
self.manager.register_user_backend(backend)
self.assertEqual(self.manager.get_backend("test_backend"), backend)
def test_format_backends(self):
self.manager.register_user_backend(TUserBackend())
self.assertEqual(
self.manager.get_backends_for_client(),
{
"test_backend": {
"disallowedUpdateKeys": TUserBackend.disallowed_update_keys
}
},
)
def test_register_backend_twice(self):
self.manager.register_user_backend(TUserBackend())
self.assertRaises(
UserBackendException, self.manager.register_user_backend, TUserBackend()
)
def test_get_unknown_backend(self):
self.assertRaises(
UserBackendException, self.manager.get_backend, "unknwon_backend"
)