django-unittest

How do you skip a unit test in Django?

拈花ヽ惹草 提交于 2019-11-30 01:07:19
How do forcibly skip a unit test in Django? @skipif and @skipunless is all I found, but I just want to skip a test right now for debugging purposes while I get a few things straightened out. Ray Toal Python's unittest module has a few decorators: There is plain old @skip : from unittest import skip @skip("Don't want to test") def test_something(): ... If you can't use @skip for some reason, @skipIf should work. Just trick it to always skip with the argument True : @skipIf(True, "I don't want to run this test yet") def test_something(): ... unittest docs Docs on skipping tests If you are

Django Unit Testing taking a very long time to create test database

爱⌒轻易说出口 提交于 2019-11-29 22:12:40
For some time now, my unit testing has been taking a longer than expected time. I have tried to debug it a couple of times without much success, as the delays are before my tests even begin to run. This has affected my ability to do anything remotely close to test driven development (maybe my expectations are too high), so I want to see if I can fix this once and for all. When a run a test, there is a 70 to 80sec delay between the start and the actual beginning of the test. For example, if I run a test for a small module (using time python manage.py test myapp ), I get <... bunch of

How do you skip a unit test in Django?

旧城冷巷雨未停 提交于 2019-11-28 21:49:48
问题 How do forcibly skip a unit test in Django? @skipif and @skipunless is all I found, but I just want to skip a test right now for debugging purposes while I get a few things straightened out. 回答1: Python's unittest module has a few decorators: There is plain old @skip : from unittest import skip @skip("Don't want to test") def test_something(): ... If you can't use @skip for some reason, @skipIf should work. Just trick it to always skip with the argument True : @skipIf(True, "I don't want to

How can I test binary file uploading with django-rest-framework's test client?

假装没事ソ 提交于 2019-11-27 21:47:58
I have a Django application with a view that accepts a file to be uploaded. Using the Django REST framework I'm subclassing APIView and implementing the post() method like this: class FileUpload(APIView): permission_classes = (IsAuthenticated,) def post(self, request, *args, **kwargs): try: image = request.FILES['image'] # Image processing here. return Response(status=status.HTTP_201_CREATED) except KeyError: return Response(status=status.HTTP_400_BAD_REQUEST, data={'detail' : 'Expected image.'}) Now I'm trying to write a couple of unittests to ensure authentication is required and that an

How can I test binary file uploading with django-rest-framework's test client?

这一生的挚爱 提交于 2019-11-26 20:47:46
问题 I have a Django application with a view that accepts a file to be uploaded. Using the Django REST framework I'm subclassing APIView and implementing the post() method like this: class FileUpload(APIView): permission_classes = (IsAuthenticated,) def post(self, request, *args, **kwargs): try: image = request.FILES['image'] # Image processing here. return Response(status=status.HTTP_201_CREATED) except KeyError: return Response(status=status.HTTP_400_BAD_REQUEST, data={'detail' : 'Expected image