Пример #1
0
    def post(self, request):
        """Processes a request"""
        if request.session.get("is_hijacked_user", False):
            return Response(status=status.HTTP_403_FORBIDDEN)

        serializer_cls = self.get_serializer_cls()
        strategy = load_drf_strategy(request)
        backend = load_backend(strategy, EmailAuth.name, None)
        serializer = serializer_cls(
            data=request.data,
            context={"request": request, "strategy": strategy, "backend": backend},
        )

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
def test_strategy_clean_authenticate_args(mocker):
    """Tests that the strategy clean_authenticate_args moves the request to kwargs"""
    # NOTE: don't pass this to load_drf_Strategy, it will error
    drf_request = Request(mocker.Mock(spec=HttpRequest))
    strategy = load_drf_strategy(mocker.Mock())
    assert strategy.clean_authenticate_args(drf_request,
                                            2,
                                            3,
                                            kwarg1=1,
                                            kwarg2=2) == (
                                                (2, 3),
                                                {
                                                    "request": drf_request,
                                                    "kwarg1": 1,
                                                    "kwarg2": 2
                                                },
                                            )
Пример #3
0
def test_load_drf_strategy(mocker):
    """Test that load_drf_strategy returns a DjangoRestFrameworkStrategy instance"""
    assert isinstance(load_drf_strategy(mocker.Mock()), DjangoRestFrameworkStrategy)
Пример #4
0
def test_strategy_init(mocker):
    """Test that the constructor works as expected"""
    drf_request = mocker.Mock()
    strategy = load_drf_strategy(request=drf_request)
    assert strategy.drf_request == drf_request
    assert strategy.request == drf_request._request  # pylint: disable=protected-access
Пример #5
0
def test_strategy_request_data(mocker):
    """Tests that the strategy request_data correctly returns the DRF request data"""
    drf_request = mocker.Mock()
    strategy = load_drf_strategy(request=drf_request)
    assert strategy.request_data() == drf_request.data