

def test_post_request(self):
    img_file = open(os.path.join(self.TEST_IMG_DIR, 'img.jpg'), 'rb')
    data = {
        'image': img_file,
        'upload_to': ['test'],
        'image_element_id': 'mt_image',
        'md5': '',
        'preview_height': '500',
        'preview_width': '800',
        'sizes': '\n            [{\n            "auto": [{\n                        "max_w": null,\n                        "retina": 0,\n                        "min_h": 1,\n                        "name": "lead",\n                        "w": 570,\n                        "h": null,\n                        "min_w": 570,\n                        "__type__": "Size",\n                        "max_h": null,\n                        "label": "Lead"\n                    }, {\n                        "max_w": null,\n                        "retina": 0,\n                        "min_h": 110,\n                        "name": "featured_small",\n                        "w": 170,\n                        "h": 110,\n                        "min_w": 170,\n                        "__type__": "Size",\n                        "max_h": null,\n                        "label": "Featured Small"\n                    }, {\n                        "max_w": null,\n                        "retina": 0,\n                        "min_h": 250,\n                        "name": "featured_large",\n                        "w": 386,\n                        "h": 250,\n                        "min_w": 386,\n                        "__type__": "Size",\n                        "max_h": null,\n                        "label": "Featured Large"\n                    }],\n            "retina": 0,\n            "name": "lead_large",\n            "h": null,\n            "min_w": 615,\n            "__type__": "Size",\n            "max_h": null,\n            "label": "Lead Large",\n            "max_w": null,\n            "min_h": 250,\n            "w": 615\n        }]',
    }
    request = self.factory.post(reverse('cropduster-upload'), data)
    request.user = self.user
    response = views.upload(request)
    data = json.loads(response.content)
    uploaded_img_path = get_media_path(data['url'])
    self.assertEqual(response.status_code, 200)
    self.assertTrue(os.path.exists(uploaded_img_path))

dataset/ETHPy150Open theatlantic/django-cropduster/cropduster/tests/test_views.py TestUpload.test_post_request/original