I'm trying to implement the service layer in my API. Now im trying to test create function with unittest lib. I dont really figure out, how to code it right.

views.py

class AuthorListApi(APIView):
    class InputSerializer(serializers.Serializer):
        name = serializers.CharField()

    def post(self, request):
        serializer = self.InputSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        create_author(**serializer.validated_data)

        return Response(serializer.data, status=status.HTTP_201_CREATED)

services.py

def create_author(name: str) -> Author:
    """
    Create a Author model object.
    """
    author = Author(name=name)

    author.full_clean()
    author.save()

    return author

test_view.py

@mock.patch('books.views.AuthorListApi.create_author')
    def test_view_calls_service(self, service_mock):
        self.client.post(self.url, data=self.data)
        service_mock.assert_called_once_with(**self.data)

Assertion error is:

AttributeError: <class 'books.views.AuthorListApi'> does not have the attribute 'create_author'
🔴 No definitive solution yet