def test_add(self): self.browser_do_login('contributor', 'contributor') self.browser.go('http://localhost/portal/myfolder/g/f/photo_add_html') self.failUnless('<h1>Photo submission</h1>' in self.browser.get_html()) form = self.browser.get_form('frmAdd') expected_controls = set([ 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'author:utf8:ustring', 'source:utf8:ustring', 'releasedate', 'discussion:boolean', 'file', ]) found_controls = set(c.name for c in form.controls) self.failUnless(expected_controls.issubset(found_controls), 'Missing form controls: %s' % repr(expected_controls - found_controls)) self.browser.clicked(form, self.browser.get_form_field(form, 'title')) form['title:utf8:ustring'] = 'test_create_photo' form['description:utf8:ustring'] = 'test_photo_description' form['author:utf8:ustring'] = 'test_author' form['source:utf8:ustring'] = 'test_source' form.find_control('file').add_file(load_test_file('data/test.gif', globals())) self.browser.submit() html = self.browser.get_html() self.failUnlessEqual(self.browser.get_url(), 'http://localhost/portal/myfolder/g/f') self.failUnless('test_create_photo' in html) photo = self.portal.myfolder.g.f['testcreatephoto'] self.failUnlessEqual(photo.description, 'test_photo_description') self.failUnlessEqual(photo.author, 'test_author') self.failUnlessEqual(photo.source, 'test_source') self.failUnlessEqual(photo.approved, 1) self.browser.go('http://localhost/portal/myfolder/g/f/testcreatephoto') html = self.browser.get_html() self.failUnless(re.search(r'<h1>.*My folder.*</h1>', html, re.DOTALL)) self.failUnless('image/gif' in html) self.failUnless('26.66 KB' in html) self.failUnless('test_author' in html) self.failUnless('test_source' in html) self.failUnless('test_create_photo' in html) self.browser.go('http://localhost/portal/myfolder/g/f/testcreatephoto/view?display=Original') self.failUnlessEqual(self.browser_get_header('content-type'), 'image/gif') self.failUnlessEqual(self.browser.get_html(), load_test_file('data/test.gif', globals()).getvalue()) self.failIf('XSmall-testcreatephoto' in self.portal.myfolder.g.f.testcreatephoto.objectIds()) self.browser.go('http://localhost/portal/myfolder/g/f/testcreatephoto/view?display=XSmall') self.failUnless('XSmall-testcreatephoto' in self.portal.myfolder.g.f.testcreatephoto.objectIds()) self.browser_do_logout()
def test_parse(self): kml_file = load_test_file('data/kml_export.kml', globals()) expected_data = [{'name': u'Bucharest', 'description': u'Bucharest description', 'latitude': u'44.31693022912877', 'longitude': u'25.68361842517931'}, {'name': u'Prague', 'description': u'Prague description', 'latitude': u'50.16784182573986', 'longitude': u'14.51580418937693', }, {'name': u'Copenhagen', 'description': u'Copenhagen description', 'latitude': u'55.76806626940991', 'longitude': u'12.59385459456745', }] parsed_data = parse_kml(kml_file) self.failUnless(parsed_data, 'KML parser returned no data') for location in parsed_data: index = parsed_data.index(location) for key in location.keys(): self.failUnlessEqual(location[key], expected_data[index][key])
def test_add_with_zip(self): """ Test album adding with pictures submitted as zip archive """ self.browser_do_login('admin', '') self.browser.go('http://localhost/portal/myfolder/mygallery/photofolder_add_html') form = self.browser.get_form('frmAdd') form['title:utf8:ustring'] = 'test_create_album_zip' pictures_zip = load_test_file('data/test.zip', globals()) form.find_control('file').add_file(pictures_zip, filename="photos.zip", content_type='application/octet-stream') self.browser.clicked(form, self.browser.get_form_field(form, 'title')) self.browser.submit() self.browser.go('http://localhost/portal/myfolder/mygallery/testcreatealbumzip') html = self.browser.get_html() self.failUnless(re.search(r'<h1>.*test_create_album_zip.*</h1>', html, re.DOTALL)) album = self.portal.myfolder.mygallery['testcreatealbumzip'] pics_in_zip = ['a.gif', 'b.gif', 'c-d.gif', 'd and d.gif', 'e-34.gif', 'k.gif'] for pic in pics_in_zip: self.failUnless(pic in html) pics_ids = ['a.gif', 'b.gif', 'c-d.gif', 'd_and_d.gif', 'e-34.gif', 'k.gif'] for pic in pics_ids: self.failUnless(pic in album.objectIds()) self.failUnlessEqual(album[pic].approved, 1) self.browser_do_logout()
def test_cut_paste(self): return #TODO: cannot paste from the test; some photos are not correctly pasted (d and d, e-34, and pasting when id exists) photos_zip = load_test_file('data/test.zip', globals()) manage_addNyPhotoGallery(self.portal.myfolder, id='mygallery2', title='My second photo gallery', submitted=1, contributor='contributor') manage_addNyPhotoFolder(self.portal.myfolder.mygallery2, id='myalbum', title='My photo album') self.portal.myfolder.mygallery2.myalbum.uploadPhotoOrZip(photos_zip) import transaction; transaction.commit() album_source = self.portal.myfolder.mygallery2.myalbum album_destination = self.portal.myfolder.mygallery.myalbum pics = [ {'zip': 'a.gif' , 'portal': 'a.gif'}, {'zip': 'b.gif' , 'portal': 'b.gif'}, {'zip': 'c-d.gif' , 'portal': 'c-d.gif'}, {'zip': 'd and d.gif' , 'portal': 'd_and_d.gif'}, {'zip': 'e-34.gif' , 'portal': 'e-34.gif'}, {'zip': 'k.gif' , 'portal': 'k.gif'}, ] photos_zip = zipfile.ZipFile(photos_zip) paste_data = album_source.cutObjects(ids=[pic['portal'] for pic in pics]) album_destination.pasteObjects(cp_data=paste_data) for pic in pics: self.failIf(pic['portal'] not in album_destination.objectIds(), '%s not in destination.' % pic['portal']) self.browser.go('http://localhost/%s/%s/view?display=Original' % (album_destination.absolute_url(1), pic['portal'])) self.failUnlessEqual(photos_zip.read(pic['zip']), self.browser.get_html(), '%s contents doesn\'t match original.' % pic['portal'])
def test_download_zip_all(self): myphoto1 = load_test_file('data/pink.png', globals()) self.portal.myfolder.mygallery.myalbum.myphoto1.update_data(myphoto1) myphoto2 = load_test_file('data/test.gif', globals()) self.portal.myfolder.mygallery.myalbum.myphoto2.update_data(myphoto2) import transaction; transaction.commit() self.browser.go('http://localhost/portal/myfolder/mygallery/myalbum') form = self.browser.get_form(3) form['download'] = ['all'] self.browser.clicked(form, 'downloadObjects:method') self.browser.submit() photo_zip = zipfile.ZipFile(StringIO(self.browser.get_html())) self.failUnlessEqual(photo_zip.namelist(), ['myalbum.zip/myphoto1', 'myalbum.zip/myphoto2']) self.failUnlessEqual(photo_zip.read('myalbum.zip/myphoto1'), myphoto1.getvalue()) self.failUnlessEqual(photo_zip.read('myalbum.zip/myphoto2'), myphoto2.getvalue())
def test_add(self): self.browser_do_login('admin', '') self.browser.go('http://localhost/portal/myfolder/mygallery/photofolder_add_html') self.failUnless('<h1>Submit album</h1>' in self.browser.get_html()) form = self.browser.get_form('frmAdd') expected_controls = set([ 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'coverage:utf8:ustring', 'keywords:utf8:ustring', 'releasedate', 'discussion:boolean', 'author:utf8:ustring', 'source:utf8:ustring', 'file', ]) found_controls = set(c.name for c in form.controls) self.failUnless(expected_controls.issubset(found_controls), 'Missing form controls: %s' % repr(expected_controls - found_controls)) form['title:utf8:ustring'] = 'test_create_album' form['description:utf8:ustring'] = 'test_album_description' form['coverage:utf8:ustring'] = 'test_album_coverage' form['keywords:utf8:ustring'] = 'keyw1, keyw2' form['author:utf8:ustring'] = 'test_album_author' form['source:utf8:ustring'] = 'test_album_source' picture = load_test_file('data/pink.png', globals()) form.find_control('file').add_file(picture, filename="albumphoto.png", content_type='image/png') self.browser.clicked(form, self.browser.get_form_field(form, 'title')) self.browser.submit() html = self.browser.get_html() self.failUnlessEqual(self.browser.get_url(), 'http://localhost/portal/myfolder/mygallery') self.failUnless('test_create_album' in html) album = self.portal.myfolder.mygallery['testcreatealbum'] self.failUnlessEqual(album.description, 'test_album_description') self.failUnlessEqual(album.coverage, 'test_album_coverage') self.failUnlessEqual(album.keywords, 'keyw1, keyw2') self.failUnlessEqual(album.author, 'test_album_author') self.failUnlessEqual(album.source, 'test_album_source') self.browser.go('http://localhost/portal/myfolder/mygallery/testcreatealbum') html = self.browser.get_html() self.failUnless(re.search(r'<h1>.*test_create_album.*</h1>', html, re.DOTALL)) self.failUnless('albumphoto.png' in html) self.failUnless('albumphoto.png' in album.objectIds()) self.browser_do_logout()
def test_photo_thumbnails(self): import StringIO from PIL import Image picture = load_test_file('data/pink.png', globals()) self.portal.myfolder.g.f.myphoto.update_data(picture) import transaction; transaction.commit() picture.seek(0) picture = Image.open(picture) self.browser.go('http://localhost/portal/myfolder/g/f/myphoto/view?display=Gallery') gallery_picture = StringIO.StringIO(self.browser.get_html()) gallery_picture.seek(0) gallery_picture = Image.open(gallery_picture) self.failUnlessEqual(gallery_picture.tostring(), picture.resize((200, 200)).tostring()) self.browser.go('http://localhost/portal/myfolder/g/f/myphoto/view?display=Album') album_picture = StringIO.StringIO(self.browser.get_html()) album_picture.seek(0) album_picture = Image.open(album_picture) self.failUnlessEqual(album_picture.tostring(), picture.resize((100, 100)).tostring()) picture_formats = [ {'size': 'XSmall', 'width': 200, 'height': 200}, {'size': 'Small', 'width': 320, 'height': 320}, {'size': 'Medium', 'width': 480, 'height': 480}, {'size': 'Large', 'width': 768, 'height': 768}, {'size': 'XLarge', 'width': 1024, 'height': 1024}, {'size': 'Original', 'width': 5, 'height': 5} ] for format in picture_formats: self.browser.go('http://localhost/portal/myfolder/g/f/myphoto/?display=%s&view%%3Amethod=View' % format['size']) pic = StringIO.StringIO(self.browser.get_html()) pic.seek(0) pic = Image.open(pic) self.failUnlessEqual(pic.tostring(), picture.resize((format['width'], format['height'])).tostring())
def test_restrict_original(self): # first make sure the photo object has a photo picture_file = load_test_file('data/pink.png', globals()) picture_data = picture_file.getvalue() gallery = self.portal.myfolder.g gallery.f.myphoto.update_data(picture_file) transaction.commit() photo_url = 'http://localhost/portal/myfolder/g/f/myphoto' # download the photo, making sure it's public by default self.browser.go(photo_url + '/view') self.assertEqual(picture_data, self.browser.get_html()) # also get a thumbnail self.browser.go(photo_url + '/view?display=Small') picture_data_small = self.browser.get_html() self.assertTrue(picture_data_small.startswith('\x89PNG')) self.assertNotEqual(picture_data_small, picture_data) # restrict access to original photo gallery.f.restrict_original = True transaction.commit() # try to download original and thumbnail self.browser.go(photo_url + '/view') self.assertNotEqual(picture_data, self.browser.get_html()) self.assertTrue(self.browser.get_url().startswith( 'http://localhost/portal/login_html')) self.browser.go(photo_url + '/view?display=Small') self.assertEqual(picture_data_small, self.browser.get_html()) # log in, try to download it again self.browser_do_login('admin', '') self.browser.go(photo_url + '/view') self.assertEqual(picture_data, self.browser.get_html()) self.browser_do_logout()