From f9d19db9e2e517434b691d01b71d39d6a354fb41 Mon Sep 17 00:00:00 2001 From: Finn Stutzenstein Date: Mon, 26 Apr 2021 08:31:22 +0200 Subject: [PATCH] Update black --- .../assignments/migrations/0009_voting_2.py | 4 ++-- server/openslides/assignments/serializers.py | 2 +- server/openslides/mediafiles/config.py | 2 +- server/openslides/mediafiles/models.py | 6 +++--- .../motions/migrations/0011_motion_version_3.py | 2 +- .../motions/migrations/0011_motion_version_4.py | 2 +- .../migrations/0021_state_access_level_1.py | 2 +- .../motions/migrations/0034_voting_2.py | 4 ++-- server/openslides/motions/models.py | 2 +- server/openslides/motions/serializers.py | 4 ++-- server/openslides/poll/models.py | 4 ++-- server/openslides/poll/views.py | 2 +- server/openslides/saml/views.py | 4 ++-- server/openslides/users/user_backend.py | 8 ++++---- server/openslides/users/views.py | 2 +- server/openslides/utils/autoupdate.py | 1 - server/openslides/utils/autoupdate_bundle.py | 4 ++-- server/openslides/utils/cache_providers.py | 6 +++--- server/openslides/utils/redis_connection_pool.py | 2 +- server/openslides/utils/stats.py | 8 ++++---- .../tests/integration/mediafiles/test_viewset.py | 2 +- server/tests/integration/motions/test_polls.py | 4 ++-- server/tests/integration/motions/test_viewset.py | 2 +- server/tests/integration/users/test_viewset.py | 16 ++++++++-------- 24 files changed, 47 insertions(+), 48 deletions(-) diff --git a/server/openslides/assignments/migrations/0009_voting_2.py b/server/openslides/assignments/migrations/0009_voting_2.py index fc5d1501c..4da076bd8 100644 --- a/server/openslides/assignments/migrations/0009_voting_2.py +++ b/server/openslides/assignments/migrations/0009_voting_2.py @@ -6,7 +6,7 @@ from django.db import migrations, transaction def change_pollmethods(apps, schema_editor): - """ yn->YN, yna->YNA """ + """yn->YN, yna->YNA""" AssignmentPoll = apps.get_model("assignments", "AssignmentPoll") pollmethod_map = { "yn": "YN", @@ -113,7 +113,7 @@ def convert_votesno(apps, schema_editor): def set_correct_state(apps, schema_editor): - """ if poll.published, set state to published """ + """if poll.published, set state to published""" AssignmentPoll = apps.get_model("assignments", "AssignmentPoll") AssignmentVote = apps.get_model("assignments", "AssignmentVote") for poll in AssignmentPoll.objects.all(): diff --git a/server/openslides/assignments/serializers.py b/server/openslides/assignments/serializers.py index 7bcca9043..b567e2182 100644 --- a/server/openslides/assignments/serializers.py +++ b/server/openslides/assignments/serializers.py @@ -106,7 +106,7 @@ class AssignmentPollSerializer(BasePollSerializer): read_only_fields = ("state",) def update(self, instance, validated_data): - """ Prevent updating the assignment """ + """Prevent updating the assignment""" validated_data.pop("assignment", None) return super().update(instance, validated_data) diff --git a/server/openslides/mediafiles/config.py b/server/openslides/mediafiles/config.py index cb42ba88d..73c9f60b9 100644 --- a/server/openslides/mediafiles/config.py +++ b/server/openslides/mediafiles/config.py @@ -23,7 +23,7 @@ def watch_and_update_configs(): def build_mapping(base_config_key, mediafiles): - """ Returns a map of config keys to medaifile ids """ + """Returns a map of config keys to medaifile ids""" logos = {} for key in config[base_config_key]: url = config[key]["path"] diff --git a/server/openslides/mediafiles/models.py b/server/openslides/mediafiles/models.py index 4c2291c2b..735a5fb6a 100644 --- a/server/openslides/mediafiles/models.py +++ b/server/openslides/mediafiles/models.py @@ -169,11 +169,11 @@ class Mediafile(RESTModelMixin, ListOfSpeakersMixin, models.Model): return deleted_ids def _db_delete(self, *args, **kwargs): - """ Captures the original .delete() method. """ + """Captures the original .delete() method.""" return super().delete(*args, **kwargs) def get_children_deep(self): - """ Returns all children and all children of childrens and so forth. """ + """Returns all children and all children of childrens and so forth.""" children = [] for child in self.children.all(): children.append(child) @@ -257,7 +257,7 @@ class Mediafile(RESTModelMixin, ListOfSpeakersMixin, models.Model): @property def is_file(self): - """ Do not check the self.mediafile, becuase this is not a valid indicator. """ + """Do not check the self.mediafile, becuase this is not a valid indicator.""" return not self.is_directory def get_list_of_speakers_title_information(self): diff --git a/server/openslides/motions/migrations/0011_motion_version_3.py b/server/openslides/motions/migrations/0011_motion_version_3.py index fb803ad3d..19ab758fc 100644 --- a/server/openslides/motions/migrations/0011_motion_version_3.py +++ b/server/openslides/motions/migrations/0011_motion_version_3.py @@ -4,7 +4,7 @@ from django.db import migrations class Migration(migrations.Migration): - """ Cleanup 1 """ + """Cleanup 1""" dependencies = [("motions", "0011_motion_version_2")] diff --git a/server/openslides/motions/migrations/0011_motion_version_4.py b/server/openslides/motions/migrations/0011_motion_version_4.py index 9855ac4d3..ed40c1785 100644 --- a/server/openslides/motions/migrations/0011_motion_version_4.py +++ b/server/openslides/motions/migrations/0011_motion_version_4.py @@ -5,7 +5,7 @@ from django.db import migrations, models class Migration(migrations.Migration): - """ Cleanup 2 """ + """Cleanup 2""" dependencies = [("motions", "0011_motion_version_3")] diff --git a/server/openslides/motions/migrations/0021_state_access_level_1.py b/server/openslides/motions/migrations/0021_state_access_level_1.py index 8900e6c3d..32b341719 100644 --- a/server/openslides/motions/migrations/0021_state_access_level_1.py +++ b/server/openslides/motions/migrations/0021_state_access_level_1.py @@ -4,7 +4,7 @@ from django.db import migrations, models class Migration(migrations.Migration): - """ Note: this is a combined migration to execute code in a seperate transaction """ + """Note: this is a combined migration to execute code in a seperate transaction""" dependencies = [("motions", "0020_auto_20190119_1425")] diff --git a/server/openslides/motions/migrations/0034_voting_2.py b/server/openslides/motions/migrations/0034_voting_2.py index 1fb620d86..6c56ae47c 100644 --- a/server/openslides/motions/migrations/0034_voting_2.py +++ b/server/openslides/motions/migrations/0034_voting_2.py @@ -4,7 +4,7 @@ from django.db import migrations def change_pollmethods(apps, schema_editor): - """ yn->YN, yna->YNA """ + """yn->YN, yna->YNA""" MotionPoll = apps.get_model("motions", "MotionPoll") pollmethod_map = { "yn": "YN", @@ -83,7 +83,7 @@ def convert_votes(apps, schema_editor): def set_correct_state(apps, schema_editor): - """ If there are votes, set the state to finished """ + """If there are votes, set the state to finished""" MotionPoll = apps.get_model("motions", "MotionPoll") MotionVote = apps.get_model("motions", "MotionVote") for poll in MotionPoll.objects.all(): diff --git a/server/openslides/motions/models.py b/server/openslides/motions/models.py index fdbb4be66..7cb3dbe7f 100644 --- a/server/openslides/motions/models.py +++ b/server/openslides/motions/models.py @@ -1057,7 +1057,7 @@ class State(RESTModelMixin, models.Model): ) def is_next_or_previous_state_id(self, state_id): - """ Returns true, if the given state id is a valid next or previous state """ + """Returns true, if the given state id is a valid next or previous state""" next_state_ids = [item.id for item in self.next_states.all()] previous_state_ids = [ item.id for item in State.objects.filter(next_states__in=[self.id]) diff --git a/server/openslides/motions/serializers.py b/server/openslides/motions/serializers.py index 631bf47aa..c2ab73eea 100644 --- a/server/openslides/motions/serializers.py +++ b/server/openslides/motions/serializers.py @@ -256,7 +256,7 @@ class MotionPollSerializer(BasePollSerializer): read_only_fields = ("state",) def update(self, instance, validated_data): - """ Prevent updating the motion """ + """Prevent updating the motion""" validated_data.pop("motion", None) return super().update(instance, validated_data) @@ -320,7 +320,7 @@ class MotionCommentSectionSerializer(ModelSerializer): read_only_fields = ("weight",) def create(self, validated_data): - """ Call inform_changed_data on creation, so the cache includes the groups. """ + """Call inform_changed_data on creation, so the cache includes the groups.""" section = super().create(validated_data) inform_changed_data(section) return section diff --git a/server/openslides/poll/models.py b/server/openslides/poll/models.py index a72e43617..0bb3d3819 100644 --- a/server/openslides/poll/models.py +++ b/server/openslides/poll/models.py @@ -15,7 +15,7 @@ from ..utils.models import SET_NULL_AND_AUTOUPDATE def generate_user_token(): - """ Generates a 16 character alphanumeric token. """ + """Generates a 16 character alphanumeric token.""" return get_random_string(16) @@ -215,7 +215,7 @@ class BasePoll(models.Model): abstract = True def create_options(self): - """ Should be called after creation of this model. """ + """Should be called after creation of this model.""" raise NotImplementedError() @classmethod diff --git a/server/openslides/poll/views.py b/server/openslides/poll/views.py index ca82542b7..d979fcbf4 100644 --- a/server/openslides/poll/views.py +++ b/server/openslides/poll/views.py @@ -316,7 +316,7 @@ class BasePollViewSet(ModelViewSet): raise ValidationError({"detail": "You have already voted."}) def parse_vote_value(self, obj, key): - """ Raises a ValidationError on incorrect values, including None """ + """Raises a ValidationError on incorrect values, including None""" if key not in obj: raise ValidationError({"detail": f"The field {key} is required"}) field = DecimalField(min_value=-2, max_digits=15, decimal_places=6) diff --git a/server/openslides/saml/views.py b/server/openslides/saml/views.py index cd6e14e8c..fa1ce69c7 100644 --- a/server/openslides/saml/views.py +++ b/server/openslides/saml/views.py @@ -32,7 +32,7 @@ class SamlView(View): return super().__init__(*args, **kwargs) def post(self, request, *args, **kwargs): - """ POST requests should do the same as GET requests. """ + """POST requests should do the same as GET requests.""" return self.get(request, *args, **kwargs) def get(self, request, *args, **kwargs): @@ -183,7 +183,7 @@ class SamlView(View): return queryargs def update_user(self, user, attributes): - """ Updates a user with the new attributes """ + """Updates a user with the new attributes""" if "auth_type" in attributes: del attributes["auth_type"] diff --git a/server/openslides/users/user_backend.py b/server/openslides/users/user_backend.py index 100294316..43b72caee 100644 --- a/server/openslides/users/user_backend.py +++ b/server/openslides/users/user_backend.py @@ -30,7 +30,7 @@ class BaseUserBackend: class DefaultUserBackend(BaseUserBackend): - """ The default user backend for OpenSlides """ + """The default user backend for OpenSlides""" @property def name(self) -> str: @@ -51,14 +51,14 @@ class UserBackendManager: self.backends: Dict[str, BaseUserBackend] = {} def collect_backends_from_apps(self): - """ Iterate through app configs and get an optional "user_backend_class" for a backend """ + """Iterate through app configs and get an optional "user_backend_class" for a backend""" for app in apps.get_app_configs(): user_backend_class = getattr(app, "user_backend_class", None) if user_backend_class: self.register_user_backend(user_backend_class()) def register_user_backend(self, backend: BaseUserBackend): - """ Registeres a user backend """ + """Registeres a user backend""" if backend.name in self.backends: raise UserBackendException( f"The user backend {backend.name} already exists." @@ -75,7 +75,7 @@ class UserBackendManager: return self.backends[name] def get_backends_for_client(self) -> Dict[str, Dict[str, Any]]: - """ Formats the backends for the client """ + """Formats the backends for the client""" return {name: backend.for_client() for name, backend in self.backends.items()} diff --git a/server/openslides/users/views.py b/server/openslides/users/views.py index 3b15c99c4..95583c7a5 100644 --- a/server/openslides/users/views.py +++ b/server/openslides/users/views.py @@ -554,7 +554,7 @@ class UserViewSet(ModelViewSet): ) def assert_list_of_ints(self, ids, ids_name="user_ids"): - """ Asserts, that ids is a list of ints. Raises a ValidationError, if not. """ + """Asserts, that ids is a list of ints. Raises a ValidationError, if not.""" if not isinstance(ids, list): raise ValidationError({"detail": "{0} must be a list", "args": [ids_name]}) for id in ids: diff --git a/server/openslides/utils/autoupdate.py b/server/openslides/utils/autoupdate.py index 6b34d5e37..00b1c5929 100644 --- a/server/openslides/utils/autoupdate.py +++ b/server/openslides/utils/autoupdate.py @@ -20,7 +20,6 @@ AutoupdateFormat = TypedDict( def disable_history() -> None: - """""" with autoupdate_bundle() as bundle: bundle.disable_history() diff --git a/server/openslides/utils/autoupdate_bundle.py b/server/openslides/utils/autoupdate_bundle.py index 2c5668524..5f64fc215 100644 --- a/server/openslides/utils/autoupdate_bundle.py +++ b/server/openslides/utils/autoupdate_bundle.py @@ -56,7 +56,7 @@ class AutoupdateBundle: self._disable_history = False def add(self, elements: Iterable[AutoupdateElement]) -> None: - """ Adds the elements to the bundle """ + """Adds the elements to the bundle""" for element in elements: self.autoupdate_elements[element["collection_string"]][ element["id"] @@ -103,7 +103,7 @@ class AutoupdateBundle: @property def element_iterator(self) -> Iterable[AutoupdateElement]: - """ Iterator for all elements in this bundle """ + """Iterator for all elements in this bundle""" for elements in self.autoupdate_elements.values(): yield from elements.values() diff --git a/server/openslides/utils/cache_providers.py b/server/openslides/utils/cache_providers.py index d26041af6..b5d2ad65e 100644 --- a/server/openslides/utils/cache_providers.py +++ b/server/openslides/utils/cache_providers.py @@ -424,7 +424,7 @@ class RedisCacheProvider: return value async def get_schema_version(self) -> Optional[SchemaVersion]: - """ Retrieves the schema version of the cache or None, if not existent """ + """Retrieves the schema version of the cache or None, if not existent""" async with get_connection(read_only=True) as redis: try: schema_version = await redis.hgetall(self.schema_cache_key) @@ -441,7 +441,7 @@ class RedisCacheProvider: } async def set_schema_version(self, schema_version: SchemaVersion) -> None: - """ Sets the schema version for this cache. """ + """Sets the schema version for this cache.""" async with get_connection() as redis: await redis.hmset_dict(self.schema_cache_key, schema_version) @@ -483,7 +483,7 @@ class RedisCacheProvider: async def _eval( self, redis: Any, script_name: str, keys: List[str] = [], args: List[Any] = [] ) -> Any: - """ Do a real eval of the script (no hash used here). Catches "cache_reset". """ + """Do a real eval of the script (no hash used here). Catches "cache_reset".""" try: return await redis.eval(self.scripts[script_name][0], keys, args) except aioredis.errors.ReplyError as e: diff --git a/server/openslides/utils/redis_connection_pool.py b/server/openslides/utils/redis_connection_pool.py index 48042907e..f050a3098 100644 --- a/server/openslides/utils/redis_connection_pool.py +++ b/server/openslides/utils/redis_connection_pool.py @@ -142,7 +142,7 @@ class InvalidConnection(Exception): class ConnectionPool(ChannelRedisConnectionPool): - """ Adds a trivial, soft limit for the pool """ + """Adds a trivial, soft limit for the pool""" def __init__(self, host: Any) -> None: self.counter = 0 diff --git a/server/openslides/utils/stats.py b/server/openslides/utils/stats.py index ff4eba54e..4d0022833 100644 --- a/server/openslides/utils/stats.py +++ b/server/openslides/utils/stats.py @@ -28,7 +28,7 @@ class WebsocketLatencyLogger: @classmethod async def add_latency(cls, latency: int) -> None: - """ Add the latency to the logger. """ + """Add the latency to the logger.""" # pass the latency value to the single instance if cls.instance is None: cls.instance = cls() @@ -49,7 +49,7 @@ class WebsocketLatencyLogger: self.flush() def flush(self) -> None: - """ Calc Stats and print to logger. """ + """Calc Stats and print to logger.""" N = len(self.latencies) mean = sum(self.latencies) / N std = sum((latency - mean) ** 2 for latency in self.latencies) @@ -58,7 +58,7 @@ class WebsocketLatencyLogger: self.reset() def reset(self) -> None: - """ Resets the stats. """ + """Resets the stats.""" self.latencies: List[int] = [] self.time = time.time() @@ -131,7 +131,7 @@ class WebsocketThroughputLogger: self.reset() def reset(self) -> None: - """ Resets the stats. """ + """Resets the stats.""" self.send_compressed = 0 self.send_uncompressed = 0 self.receive_compressed = 0 diff --git a/server/tests/integration/mediafiles/test_viewset.py b/server/tests/integration/mediafiles/test_viewset.py index 706570ef4..be9cf0d22 100644 --- a/server/tests/integration/mediafiles/test_viewset.py +++ b/server/tests/integration/mediafiles/test_viewset.py @@ -266,7 +266,7 @@ class TestUpdate(TestCase): ) def test_update_parent_id(self): - """ Assert, that the parent id does not change """ + """Assert, that the parent id does not change""" response = self.client.put( reverse("mediafile-detail", args=[self.mediafileA.pk]), {"title": self.mediafileA.title, "parent_id": None}, diff --git a/server/tests/integration/motions/test_polls.py b/server/tests/integration/motions/test_polls.py index 730f9505e..60063b628 100644 --- a/server/tests/integration/motions/test_polls.py +++ b/server/tests/integration/motions/test_polls.py @@ -881,7 +881,7 @@ class VoteMotionPollNamed(TestCase): self.assertFalse(MotionPoll.objects.get().get_votes().exists()) def setup_vote_delegation(self, with_delegation=True): - """ user -> admin """ + """user -> admin""" self.start_poll() self.make_admin_delegate() self.make_admin_present() @@ -1392,7 +1392,7 @@ class ResetMotionPoll(TestCase): class TestMotionPollWithVoteDelegationAutoupdate(TestCase): def advancedSetUp(self): - """ Set up user -> other_user delegation. """ + """Set up user -> other_user delegation.""" self.motion = Motion( title="test_title_dL91JqhMTiQuQLSDRItZ", text="test_text_R7nURdXKVEfEnnJBXJYa", diff --git a/server/tests/integration/motions/test_viewset.py b/server/tests/integration/motions/test_viewset.py index ca16ff18e..bfa6702da 100644 --- a/server/tests/integration/motions/test_viewset.py +++ b/server/tests/integration/motions/test_viewset.py @@ -660,7 +660,7 @@ class TestMotionCommentSectionSorting(TestCase): self.assert_not_changed() def assert_not_changed(self): - """ Asserts, that every comment section has the default weight of 10000. """ + """Asserts, that every comment section has the default weight of 10000.""" for section in MotionCommentSection.objects.all(): self.assertEqual(section.weight, 10000) diff --git a/server/tests/integration/users/test_viewset.py b/server/tests/integration/users/test_viewset.py index ab99de703..6a454b4e3 100644 --- a/server/tests/integration/users/test_viewset.py +++ b/server/tests/integration/users/test_viewset.py @@ -313,7 +313,7 @@ class UserUpdate(TestCase): self.assertIsNone(admin.vote_delegated_to_id) def setup_vote_delegation(self): - """ login and setup user -> user2 delegation """ + """login and setup user -> user2 delegation""" self.user, _ = self.create_user() self.user2, _ = self.create_user() self.user.vote_delegated_to = self.user2 @@ -354,7 +354,7 @@ class UserUpdate(TestCase): self.assertEqual(user.vote_delegated_to_id, self.user2.id) def test_update_nested_vote_delegation_1(self): - """ user -> user2 -> admin """ + """user -> user2 -> admin""" self.setup_vote_delegation() response = self.client.patch( reverse("user-detail", args=[self.user2.pk]), @@ -366,7 +366,7 @@ class UserUpdate(TestCase): self.assertIsNone(user2.vote_delegated_to_id) def test_update_nested_vote_delegation_2(self): - """ admin -> user -> user2 """ + """admin -> user -> user2""" self.setup_vote_delegation() response = self.client.patch( reverse("user-detail", args=[self.admin.pk]), @@ -391,7 +391,7 @@ class UserUpdate(TestCase): self.assertIsNone(user.vote_delegated_to_id) def test_update_vote_delegated_from_nested_1(self): - """ admin -> user -> user2 """ + """admin -> user -> user2""" self.setup_vote_delegation() response = self.client.patch( reverse("user-detail", args=[self.user.pk]), @@ -403,7 +403,7 @@ class UserUpdate(TestCase): self.assertIsNone(admin.vote_delegated_to_id) def test_update_vote_delegated_from_nested_2(self): - """ user -> user2 -> admin """ + """user -> user2 -> admin""" self.setup_vote_delegation() response = self.client.patch( reverse("user-detail", args=[self.admin.pk]), @@ -415,7 +415,7 @@ class UserUpdate(TestCase): self.assertIsNone(user2.vote_delegated_to_id) def test_update_vote_delegation_both_1(self): - """ Change user -> user2 to admin -> user in one request. """ + """Change user -> user2 to admin -> user in one request.""" self.user2 = User.objects.create_user( username="user2", password="non-admin 1WywRnqKbcdtQwS2", @@ -446,7 +446,7 @@ class UserUpdate(TestCase): self.assertEqual(user2.vote_delegated_from_users.count(), 0) def test_update_vote_delegation_both_2(self): - """ Change user -> user2 to user2 -> admin in one request. """ + """Change user -> user2 to user2 -> admin in one request.""" self.user2 = User.objects.create_user( username="user2", password="non-admin 1WywRnqKbcdtQwS2", @@ -519,7 +519,7 @@ class UserDelete(TestCase): self.assertFalse(User.objects.filter(pk__in=ids).exists()) def test_bulk_delete_self(self): - """ The own id should be excluded, so nothing should happen. """ + """The own id should be excluded, so nothing should happen.""" response = self.admin_client.post( reverse("user-bulk-delete"), {"user_ids": [1]} )