def test_upload(self): self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024 * 5, 'file': BytesIO('X' * 1024), 'name': 'foobar.bin' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertTrue('id' in data) self.assertTrue(data['success']) self.request.form.update({ 'id': data['id'] }) for idx in range(4): self.request.form.update({ 'action': 'chunk-upload', 'chunk': str(idx + 2), 'file': BytesIO('X' * 1024) }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertTrue(data['success']) self.assertTrue(data['valid']) self.assertTrue('url' in data) fileOb = api.content.get(path='/file-repository/foobar.bin') self.assertEquals(fileOb.file.data, 'X' * 1024 * 5) return fileOb
def test_save_file_saves_custom_field_values(self): # add new field registry = getUtility(IRegistry) fields = deepcopy(registry['castle.file_upload_fields']) for f in fields: f['required'] = unicode(f['required']).lower() fields.append({ u'name': u'foobar', u'label': u'Foobar', u'widget': u'text', u'required': u'false', u'for-file-types': u'*' }) registry['castle.file_upload_fields'] = fields self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024, 'file': BytesIO('X' * 1024), 'name': 'foobar.bin', 'title': 'Foobar', 'foobar': 'Some value here' }) cc = content.Creator(self.portal, self.request) cc() fileOb = api.content.get(path='/file-repository/foobar.bin') self.assertEquals(fileOb.file.data, 'X' * 1024) self.assertEquals(fileOb.foobar, 'Some value here') return fileOb
def test_tmp_upload(self): fileOb = self.test_upload() api.content.transition(obj=fileOb, to_state='published') self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024, 'file': BytesIO('T' * 1024), 'name': 'foobar2.bin', 'content': IUUID(fileOb), 'field': 'tmp_blarg' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertTrue(data['valid']) self.assertTrue('url' in data) fileOb = api.content.get(path='/file-repository/foobar.bin') # should not change! self.assertEquals(fileOb.file.data, 'X' * 1024 * 5) # tmp file should be uploaded annotations = IAnnotations(fileOb) tmp_files = annotations['_tmp_files'] self.assertTrue('tmp_blarg' in tmp_files)
def test_check(self): self.request.form.update({ 'action': 'check', 'selectedType[typeId]': 'Folder', 'basePath': '/', 'id': 'foobar' }) cc = content.Creator(self.portal, self.request) data = cc() self.assertEqual(json.loads(data)['valid'], True)
def test_modify_content_upload_permission(self): api.user.create( email='*****@*****.**', username='******', password='******', roles=('Member',)) setRoles(self.portal, 'foobar', ( 'Member', 'Contributor', 'Reviewer')) api.user.create( email='*****@*****.**', username='******', password='******', roles=('Member',)) setRoles(self.portal, 'foobar2', ( 'Member', 'Reviewer')) login(self.portal, 'foobar') self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024, 'file': BytesIO('X' * 1024), 'name': 'foobar.bin' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) fileOb = api.content.get(path='/file-repository/foobar.bin') self.assertEquals(fileOb.file.data, 'X' * 1024) # and publish the sucker api.content.transition(fileOb, 'publish') logout() login(self.portal, 'foobar2') self.request.form.update({ 'action': 'chunk-upload', 'file': BytesIO('U' * 1024), 'name': 'foobar2.bin', 'content': IUUID(fileOb), 'field': 'file' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertFalse(data['success'])
def upload_file_to_castle(self): self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024 * 5, 'file': BytesIO('X' * 1024), 'name': 'foobar.bin' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.request.form.update({'id': data['id']}) for idx in range(4): self.request.form.update({ 'action': 'chunk-upload', 'chunk': str(idx + 2), 'file': BytesIO('X' * 1024) }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) return api.content.get(path='/file-repository/foobar.bin')
def test_create_folders(self): self.request.form.update({ 'action': 'create', 'basePath': 'foo/bar', 'id': 'foobar', 'title': 'Foobar', 'selectedType[id]': 'Document', 'transitionTo': 'publish' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) ob = api.content.get(path='/foo/bar/foobar') self.assertTrue(ob is not None) self.assertEquals(data['base_url'], 'http://nohost/plone/foo/bar/foobar') self.assertEquals(api.content.get_state(ob), 'published')
def test_update_upload(self): fileOb = self.test_upload() api.content.transition(obj=fileOb, to_state='published') self.request.form.update({ 'action': 'chunk-upload', 'chunk': '1', 'chunkSize': 1024, 'totalSize': 1024, 'file': BytesIO('U' * 1024), 'name': 'foobar2.bin', 'content': IUUID(fileOb), 'field': 'file' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertTrue(data['valid']) self.assertTrue('url' in data) fileOb = api.content.get(path='/file-repository/foobar.bin') self.assertEquals(fileOb.file.data, 'U' * 1024)
def test_create_content_from_template(self): site = getSite() obj = api.content.create(type='Document', id='template-document', title='Template Document', container=self.portal) template_obj = save_as_template(obj, 'convert') self.request.form.update({ 'action': 'create-from-template', 'basePath': '/', 'id': 'document-from-template', 'title': 'Document From Template', 'selectedType[id]': template_obj.id, 'selectedType[title]': template_obj.title, 'transitionTo': '' }) cc = content.Creator(self.portal, self.request) data = json.loads(cc()) self.assertFalse(ITemplate.providedBy(data)) self.assertTrue(template_obj in site.template_list and data not in site.template_list)
def test_accees_denied(self): content.Creator(self.portal, self.request)() self.assertEquals(self.request.response.getStatus(), 403)