Hi, This is my first django project and I'm trying write some tests. So far the experience has been good and I've been able to get by using the documentation and blog posts. Thanks for all of the work that went into django. I'm using django 1.1.1 with python 2.6.4 on x86_64 linux.
I have a few tests that work using client.get. I'm trying to move on to a test of the post functionality and am having problems. I can't get a test.client.Client.post()s raw_post_data to match what I get using my browser and the test throws an exception about reading more than the available bytes. Printing out the raw_post_data when my app is running under './manage.py runserver' stderr.write( request.raw_post_data) I see the following: form-TOTAL_FORMS=2&form-INITIAL_FORMS=2&form-0-id=0&\ form-0-remove=on&form-1-id=2 That looks like what I expect from the docs: http://docs.djangoproject.com/en/1.1/topics/testing/ However, when I try to post in a test using the following code raw_post = 'form-TOTAL_FORMS=2&form-INITIAL_FORMS=2&form-0-id=0&form-0-remove=on&form-1-id=2' bits = raw_post.split('&') post_data = {} for x in bits: k,v = x.split('=', 1) post_data[k] = v print post_data c = Client() response = c.post('/profile/sw/0/remove_packages/', post_data) I get the following from the raw_post_data when running under ./manage.py test. What am I missing? raw data coming up: --BoUnDaRyStRiNg Content-Disposition: form-data; name="form-0-remove" on --BoUnDaRyStRiNg Content-Disposition: form-data; name="form-INITIAL_FORMS" 2 --BoUnDaRyStRiNg Content-Disposition: form-data; name="form-0-id" 0 --BoUnDaRyStRiNg Content-Disposition: form-data; name="form-1-id" 2 --BoUnDaRyStRiNg Content-Disposition: form-data; name="form-TOTAL_FORMS" 2 --BoUnDaRyStRiNg-- <snip> post_data looks like so (the order isn't the same but that shouldn't matter, should it?): {'form-0-remove': 'on', 'form-INITIAL_FORMS': '2', 'form-0-id': '0', 'form-1-id': '2', 'form-TOTAL_FORMS': '2'} My code bails with the following exception: <snip> File "/usr/lib64/python2.6/site-packages/django/core/handlers/wsgi.py", line 171, in _get_post self._load_post_and_files() File "/usr/lib64/python2.6/site-packages/django/core/handlers/wsgi.py", line 137, in _load_post_and_files self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input']) File "/usr/lib64/python2.6/site-packages/django/http/__init__.py", line 124, in parse_file_upload return parser.parse() File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 133, in parse for item_type, meta_data, field_stream in Parser(stream, self._boundary): File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 606, in __iter__ for sub_stream in boundarystream: File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 420, in next return LazyStream(BoundaryIter(self._stream, self._boundary)) File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 446, in __init__ unused_char = self._stream.read(1) File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 299, in read out = ''.join(parts()) File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 292, in parts chunk = self.next() File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 314, in next output = self._producer.next() File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 375, in next data = self.flo.read(self.chunk_size) File "/usr/lib64/python2.6/site-packages/django/http/multipartparser.py", line 405, in read return self._file.read(num_bytes) File "/usr/lib64/python2.6/site-packages/django/test/client.py", line 45, in read assert self.__len >= num_bytes, "Cannot read more than the available bytes from the HTTP incoming data." AssertionError: Cannot read more than the available bytes from the HTTP incoming data. Any help would be greatly appreciated. Also, is there a way to get the output of print statements in my view visible while running the tests or do I need to use a logger? thank you, Paul -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.