def test_get_image_info_as_json(self): session = Client().session() album = Album(name='cow shots') session.add(album) session.flush() image = Image(filename='deadbeef', description='one time I saw a dead cow', title='dead beef', album_id=album.album_id) session.add(image) image.add_tags(['cow', 'dead']) session.flush() response = self.app.get('/image/%d.json' % image.image_id) eq_(json.loads(response.data), { 'description': 'one time I saw a dead cow', 'title': 'dead beef', 'album_id': album.album_id, 'tags': [ 'cow', 'dead', ], 'source_url': 'https://s3.amazonaws.com/snapcats/deadbeef', 'camera': None, 'photographed_at': None, 'focal_length': None, 'aperture': None, 'shutter_speed': None, 'iso': None, })
def add(request_format): tag_names = request.form['tags'].split(' ') url = request.form['url'] if url: print 'fetching from remote url' truck = ImageTruck.new_from_url(url) elif request.files['file']: image = request.files['file'] truck = ImageTruck.new_from_stream(image.stream, image.mimetype) else: abort(400) metadata = ImageMetadata.image_metadata(truck.contents) print 'potentially reorienting' truck.contents = ReorientImage.reorient_image(truck.contents) print 'uploading to s3' truck.upload() session = Client().session() image = Image(filename=truck.calculate_filename(), source_url=url, description=request.form.get('description'), title=request.form.get('title'), **metadata) album_id = request.form['album'] if album_id: image.album_id = album_id session.add(image) image.add_tags(tag_names) ResizeImage.make_resizes(image, truck) if request_format == 'html': return redirect(url_for('show_image', image_id=image.image_id)) elif request_format == 'json': return {'url': truck.url()}
def test_caption__falls_back_to_tags(self): session = Client().session() image = Image(title='', filename='') session.add(image) image.add_tags(['cat', 'awesome']) eq_(image.caption(), 'awesome cat')
def test_caption__defaults_to_title(self): session = Client().session() image = Image(title='the title', filename='') session.add(image) image.add_tags(['cat', 'awesome']) eq_(image.caption(), 'the title')
def test_add_tags_creates_tag_row_if_necessary(self): session = Client().session() image = Image(filename='baba15') session.add(image) image.add_tags(['booya']) tag = session.query(Tag).\ filter(Tag.name=='booya').\ first() assert tag, 'no tag was created'
def test_add_tags_adds_image_tag_rows(self): session = Client().session() tag = Tag(name='booya') session.add(tag) image = Image(filename='baba15') session.add(image) image.add_tags(['booya']) image_tag = session.query(ImageTag).\ filter(ImageTag.image_id == image.image_id).\ filter(ImageTag.tag_id == tag.tag_id).\ first() assert image_tag, 'no image/tag mapping was created'
def test_remove_last_tag(self): session = Client().session() pic = Image(filename="tagged", title="Untagged Picture") session.add(pic) session.flush() pic.add_tags(['one']) session.flush() self.visit_url('/image/{0}'.format(pic.image_id)) self.browser.click_link_by_text('Edit') remove_tag = self.browser.find_by_css('a.remove-tag') remove_tag.click() self.browser.click_link_by_text('Stop Editing') tag_button = self.browser.find_by_id('tag-button') assert tag_button.has_class("disabled"), \ "Tag button enabled without tags!"
def test_remove_last_tag(self): session = Client().session() pic = Image(filename="tagged", title="Untagged Picture") session.add(pic) session.flush() pic.add_tags(['one']) session.flush() self.visit_url('/image/{0}'.format(pic.image_id)) self.browser.click_link_by_text('Edit') remove_tag = self.browser.find_by_css('a.remove-tag') remove_tag.click() self.browser.click_link_by_text('Stop Editing') tag_button = self.browser.find_by_id('tag-button') tag_button.click() tag_list = self.browser.find_by_css('ul.view-tags') assert not tag_list.visible, "Popped up an empty tag dropdown!"
def test_edit_tags(self): session = Client().session() pic = Image(filename="silly", title="Silly Picture") session.add(pic) session.flush() pic.add_tags(['goofy', 'silly']) session.flush() self.visit_url('/image/{0}'.format(pic.image_id)) tag_button = self.browser.find_by_id('tag-button') assert tag_button, "Couldn't find a button for listing tags!" tag_button.click() tags = self.browser.find_by_css('li.tag') assert all([t.visible for t in tags]), "Tag listing was not visible!" eq_([t.text for t in tags], ['goofy', 'silly']) self.browser.click_link_by_text('Edit') assert all([not t.visible for t in tags]), "Tag listing didn't disappear!" tag_removes = self.browser.find_by_css('a.remove-tag') eq_([t.text for t in tag_removes], ['goofy', 'silly']) assert all([t.visible for t in tag_removes]), "Remove tag controls weren't visible!" add_tag = self.browser.find_by_css('a.add-tag') eq_(add_tag.text, 'Add tag') assert add_tag.visible, "Add tag control wasn't visible!" tag_removes[0].click() eq_(list(pic.get_tags()), ['silly']) tag_removes = self.browser.find_by_css('a.remove-tag') eq_([t.text for t in tag_removes], ['silly']) self.browser.click_link_by_text('Stop Editing') tag_button.click() tags = self.browser.find_by_css('li.tag') assert all([t.visible for t in tags]), "Tag listing was not visible!" eq_([t.text for t in tags], ['silly']) self.browser.click_link_by_text('Edit') add_tag.click() focused_input = self.browser.find_by_css('input:focus').first tag_input = self.browser.find_by_id('tag').first eq_(focused_input['id'], 'tag', "Add-tag input wasn't automatically focused!") tag_input.fill('funny\n') tag_removes = self.browser.find_by_css('a.remove-tag') eq_([t.text for t in tag_removes], ['silly', 'funny']) eq_(list(pic.get_tags()), ['silly', 'funny']) self.browser.click_link_by_text('Stop Editing') tag_button.click() tags = self.browser.find_by_css('li.tag') assert all([t.visible for t in tags]), "Tag listing was not visible!" eq_([t.text for t in tags], ['silly', 'funny']) self.browser.click_link_by_text('Edit') tag_removes[1].click() eq_(list(pic.get_tags()), ['silly'])