samedi 31 octobre 2015

Unit Testing for Django Projects

I've recently started for a new company and I've started on Django Project. Now I want to write unit tests to test the complete functionality of the Project. How do I proceed. One more thing I want to ask is how can I call the methods to the test files from the files for which test case has to be written. Let's say I have the following code in views :

class SourcesViewSet(viewsets.ViewSet): authentication_classes = (authentication.TokenAuthentication, authentication.SessionAuthentication,) permission_classes = (permissions.IsAuthenticated,) lookup_field = 'key'

def list(self, request):
    """
        Get a list of sources.
        ---
        request_serializer: SourceSerializer
        response_serializer: SourceSerializer
        responseMessages:
            - code : 200
              message : Success
            - code : 401
              message : Not authenticated
    """
    request_arrival_time = timezone.now()
    sources = Sensor.objects.filter(user=request.user,
                                    isTemplate=False)
    serializer = SourceSerializer(sources, many=True)
    response = Response(serializer.data, status=status.HTTP_200_OK)
    log_a_success(request.user.id, request, response.status_code,
                  request_arrival_time)
    return response

How test case can be written for this. Please suggest. Thanks.

Aucun commentaire:

Enregistrer un commentaire