Ejemplo n.º 1
0
    def test_get_filenames(self):
        session = Client().session()
        dog = Image(filename='D06')
        cat = Image(filename='CA7')
        session.add(dog)
        session.add(cat)
        pet = Tag(name='pet')
        session.add(pet)
        session.flush()
        session.add(ImageTag(image_id=cat.image_id, tag_id=pet.tag_id))
        session.add(ImageTag(image_id=dog.image_id, tag_id=pet.tag_id))
        session.flush()

        filenames = pet.get_filenames()
        eq_(list(filenames), ['D06', 'CA7'])
Ejemplo n.º 2
0
 def test_multiple_tags(self):
     (dog, cat, stegosaurus) = self.setup_test_data()
     image_data = Tag.get_image_data(['pet','cool'])
     eq_(list(image_data), [
             ('57E60', stegosaurus.image_id, 'cool'),
             ('CA7',   cat.image_id,         'pet cool'),
             ('D06',   dog.image_id,         'my dog')])
Ejemplo n.º 3
0
def find(request_format):
    tag_names = request.args['tags'].strip().split(' ')
    image_structs = []
    image_data = Tag.get_image_data(tag_names)
    for filename, image_id, caption in image_data:
        image_structs.append({
            'source_url': ImageTruck.url_for_filename(filename),
            'url': url_for('show_image', image_id=image_id),
            'caption': caption,
        })
    if request_format == 'html':
        return render_template('find.html.jinja', images=image_structs)
    elif request_format == 'json':
        return image_structs
Ejemplo n.º 4
0
 def test_a_simple_query(self):
     (dog, cat, stegosaurus) = self.setup_test_data()
     image_data = Tag.get_image_data(['pet'])
     eq_(list(image_data), [
             ('CA7', cat.image_id, 'pet cool'),
             ('D06', dog.image_id, 'my dog')])