Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "shipchain-common"
version = "1.0.29"
version = "1.0.30"
description = "A PyPI package containing shared code for ShipChain's Python/Django projects."

license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/shipchain_common/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_serializer(self, *args, **kwargs):
"""
serialization_type = kwargs.pop('serialization_type', mixins.SerializationType.REQUEST)
serializer_class = self.get_serializer_class(serialization_type)
kwargs['context'] = self.get_serializer_context()
kwargs.setdefault('context', self.get_serializer_context())
return serializer_class(*args, **kwargs)

# pylint: disable=arguments-differ
Expand Down
20 changes: 20 additions & 0 deletions tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from shipchain_common.mixins import SerializationType, MultiSerializerViewSetMixin, MultiPermissionViewSetMixin
from shipchain_common.viewsets import ActionConfiguration, ConfigurableGenericViewSet
from rest_framework_json_api import serializers
from tests.django_mocking.models import EnumObject


class FakePermission:
Expand Down Expand Up @@ -55,6 +57,12 @@ class CustomActionCSVSerializer(DefaultSerializer):
pass


class ModelSerializer(serializers.ModelSerializer):
class Meta:
model = EnumObject
fields = '__all__'


class TestActionConfiguration:

def test_validation_list(self):
Expand Down Expand Up @@ -469,6 +477,18 @@ def test_configurable_generic_view_set(self, viewset):
assert 'update' not in viewset.configuration
assert 'update' not in viewset.action_user_permissions

def test_custom_context(self, viewset):
viewset.default_required_user_permissions = ['feature.default_permission']
viewset.configuration = {
'create': ActionConfiguration(
request_serializer=ModelSerializer
),
}

viewset.action = 'create'
serializer = viewset.get_serializer(context={'custom key': 'custom value'})
assert serializer.context['custom key'] == 'custom value'

def test_configurable_generic_view_set_default_user_perms(self, viewset):
viewset.default_required_user_permissions = ['feature.default_permission']
viewset.configuration = {
Expand Down