OpenSlides/server/tests/unit/users/test_serializers.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

43 lines
1.4 KiB
Python

from unittest import TestCase
from unittest.mock import MagicMock, patch
from openslides.users.serializers import UserSerializer
from openslides.utils.rest_api import ValidationError
class UserCreateUpdateSerializerTest(TestCase):
def test_validate_no_data(self):
"""
Tests, that the validator raises a ValidationError, if not data is given.
"""
serializer = UserSerializer()
data: object = {}
with self.assertRaises(ValidationError):
serializer.validate(data)
@patch("openslides.users.serializers.User.objects.generate_username")
def test_validate_no_username(self, generate_username):
"""
Tests, that an empty username is generated.
"""
generate_username.return_value = "test_value"
serializer = UserSerializer()
data = {"first_name": "TestName"}
new_data = serializer.validate(data)
self.assertEqual(new_data["username"], "test_value")
def test_validate_no_username_in_patch_request(self):
"""
Tests, that an empty username is not set in a patch request context.
"""
view = MagicMock(action="partial_update")
serializer = UserSerializer(context={"view": view})
data = {"first_name": "TestName"}
new_data = serializer.validate(data)
self.assertIsNone(new_data.get("username"))