'Tests the Upload form.'

def test_upload_document_form(self):

    form_data = dict()
    form = DocumentCreateForm(data=form_data)
    self.assertFalse(form.is_valid())
    self.assertTrue(('title' in form.errors))
    self.assertTrue(('permissions' in form.errors))
    self.assertTrue(('__all__' in form.errors))
    form_data = {'title': 'GeoNode    Map', 'permissions': '{"anonymous":"document_readonly","authenticated":"resourcebase_readwrite","users":[]}', 'doc_url': 'http://www.geonode.org/map.pdf'}
    form = DocumentCreateForm(data=form_data)
    self.assertTrue(form.is_valid())
    self.assertTrue(isinstance(form.cleaned_data['permissions'], dict))
    form_data['permissions'] = 'non-json    string'
    self.assertTrue(('permissions' in DocumentCreateForm(data=form_data).errors))
    form_data = {'title': 'GeoNode    Map', 'permissions': '{"anonymous":"document_readonly","authenticated":"resourcebase_readwrite","users":[]}'}
    file_data = {'doc_file': SimpleUploadedFile('test_img_file.gif', self.imgfile.read(), 'image/gif')}
    form = DocumentCreateForm(form_data, file_data)
    self.assertTrue(form.is_valid())
    form_data['doc_url'] = 'http://www.geonode.org/map.pdf'
    form = DocumentCreateForm(form_data, file_data)
    self.assertFalse(form.is_valid())
    self.assertTrue(('__all__' in form.errors))
