Ejemplo n.º 1
0
def post_image():
    data = request.get_json() or {}
    if 'image_url' not in data or 'image_filename' not in data:
        return bad_request('image json needs to be in data ')
    image = Image()
    image.from_dict(data)
    db.session.add(image)
    db.session.commit()
    response = jsonify(image.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('get_image',
                                           filename=image.image_filename)
    return response
Ejemplo n.º 2
0
 def test_name_is_unique(self, image_session):
     image_session.add(self.image)
     image_session.commit()
     im1 = Image.query.first()
     with pytest.raises(IntegrityError):
         new_im = Image.from_dict(im1.to_dict())
         image_session.add(new_im)
         image_session.commit()
Ejemplo n.º 3
0
 def test_from_dict(self):
     im = Image.from_dict({
         'Name': 'foobar',
         'URL': 'baz',
         'Sol': '42',
         'CameraID': 1,
         'ProductTypeID': 1,
         'fake': 'value',
         'DetatchedLabel': True,
     })
     assert im.Name == 'foobar'
     assert im.URL == 'baz'
     assert im.Sol == 42
     assert im.CameraID == 1
     assert im.ProductTypeID == 1
     assert im.DetatchedLabel
Ejemplo n.º 4
0
    def test_many_to_one_relationships(self, image_session):
        image_session.add(self.image)
        image_session.commit()
        im1 = Image.query.first()
        # Also have the same product type id and camera id
        new_im = Image.from_dict(im1.to_dict())
        new_im.Name = 'agentp'
        image_session.add(new_im)
        image_session.commit()
        ims = Image.query.filter().all()
        assert len(ims) == 2
        im2 = ims[1]
        assert im1.ProductTypeID == 1
        assert im1.CameraID == 1
        assert im2.ProductTypeID == 1
        assert im2.CameraID == 1

        # Check the one to many relationships as well
        pt = ProductType.query.first()
        assert len(pt.images) == 2
        cam = Camera.query.first()
        assert len(cam.images) == 2