def post(self, request):
        serializer = AuthTokenSerializer(data=request.data)

        if serializer.is_valid():
            token, _ = ExpiringToken.objects.get_or_create(
                user=serializer.validated_data['user']
            )

            if token.expired():
                # If the token is expired, generate a new one.
                token.delete()
                token = ExpiringToken.objects.create(
                    user=serializer.validated_data['user']
                )

            data = {'token': token.key}
            return Response(data)

        return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
Test instrument_ioloop() setups monitoring and creates a PeriodicCallback
dataset/ETHPy150Open JamesRitchie/django-rest-framework-expiring-tokens/rest_framework_expiring_authtoken/views.py/ObtainExpiringAuthToken.post--crossover with--dataset/ETHPy150Open uber/mutornadomon/tests/test_config.py/TestInitializeMutornadomon.test_publisher_initializer