def test_nonzero(app: Flask, db: SQLAlchemy) -> None: blob = Blob("test md5") assert bool(blob) # change uuid: repository will return None for blob.file blob.uuid = uuid.uuid4() assert not bool(blob)
def test_nonzero(app: Flask, db: SQLAlchemy) -> None: blob = Blob("test md5") assert bool(blob) # change uuid: repository will return None for blob.file # pyre-fixme[8]: Attribute has type `Column`; used as `UUID`. blob.uuid = uuid.uuid4() assert not bool(blob)
def test_auto_uuid() -> None: blob = Blob() assert blob.uuid is not None assert isinstance(blob.uuid, uuid.UUID) # test provided uuid is not replaced by a new one u = uuid.UUID("4f80f02f-52e3-4fe2-b9f2-2c3e99449ce9") blob = Blob(uuid=u) assert isinstance(blob.uuid, uuid.UUID) assert blob.uuid, u
def test_value(app: Flask, db: SQLAlchemy) -> None: session = db.session content = b"content" blob = Blob(content) tr = session.begin(nested=True) session.add(blob) tr.commit() # pyre-fixme[6]: Expected `UUID` for 1st param but got `Column`. assert repository.get(blob.uuid) is None # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 2nd param but got `Column`. assert session_repository.get(blob, blob.uuid).open("rb").read() == content assert blob.value == content session.commit() # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 1st param but got `Column`. assert repository.get(blob.uuid).open("rb").read() == content assert blob.value == content session.begin(nested=True) # match session.rollback with session.begin(nested=True): session.delete(blob) # object marked for deletion, but instance attribute should still be # readable # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 2nd param but got `Column`. fd = session_repository.get(blob, blob.uuid).open("rb") assert fd.read() == content # commit in transaction: session_repository has no content, 'physical' # repository still has content # pyre-fixme[6]: Expected `UUID` for 2nd param but got `Column`. assert session_repository.get(blob, blob.uuid) is None # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 1st param but got `Column`. assert repository.get(blob.uuid).open("rb").read() == content # rollback: session_repository has content again session.rollback() # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 2nd param but got `Column`. assert session_repository.get(blob, blob.uuid).open("rb").read() == content session.delete(blob) session.flush() # pyre-fixme[6]: Expected `UUID` for 2nd param but got `Column`. assert session_repository.get(blob, blob.uuid) is None # pyre-fixme[16]: Optional type has no attribute `open`. # pyre-fixme[6]: Expected `UUID` for 1st param but got `Column`. assert repository.get(blob.uuid).open("rb").read() == content session.commit() # pyre-fixme[6]: Expected `UUID` for 1st param but got `Column`. assert repository.get(blob.uuid) is None
def update_feuille_de_cout(model, html): id = model["id"] demande = db.session.query(Demande).get(id) if not demande: raise NotFound() if not feuille_cout_editable(demande): raise Forbidden() demande.feuille_cout = model html = re.sub('id="feuille-cout"', 'id="feuille-cout" class="print"', html) demande.data[ "fdc_html"] = f'<!DOCTYPE html><html lang="fr-FR">{html}</html>' db.session.commit() root = Path(current_app.root_path) static = root / "static" css = static / "css" css1 = CSS(filename=str(first(css.glob("chunk*")))) css2 = CSS(filename=str(first(css.glob("app*")))) css3 = CSS(string=PRINT_CSS) s = HTML(string=html).write_pdf(stylesheets=[css3, css1, css2, css3]) assert s blob = Blob(s) db.session.add(blob) db.session.flush() d = { "name": "Feuille de coût.pdf", "date": datetime.utcnow().isoformat(), "blob_id": blob.id, } if demande.documents_generes: docs = list(demande.documents_generes) docs.append(d) demande.documents_generes = docs else: demande.documents_generes = [d] db.session.commit()
def test_value(app: Flask, db: SQLAlchemy) -> None: session = db.session content = b"content" blob = Blob(content) tr = session.begin(nested=True) session.add(blob) tr.commit() assert repository.get(blob.uuid) is None assert session_repository.get(blob, blob.uuid).open("rb").read() == content assert blob.value == content session.commit() assert repository.get(blob.uuid).open("rb").read() == content assert blob.value == content session.begin(nested=True) # match session.rollback with session.begin(nested=True): session.delete(blob) # object marked for deletion, but instance attribute should still be # readable fd = session_repository.get(blob, blob.uuid).open("rb") assert fd.read() == content # commit in transaction: session_repository has no content, 'physical' # repository still has content assert session_repository.get(blob, blob.uuid) is None assert repository.get(blob.uuid).open("rb").read() == content # rollback: session_repository has content again session.rollback() assert session_repository.get(blob, blob.uuid).open("rb").read() == content session.delete(blob) session.flush() assert session_repository.get(blob, blob.uuid) is None assert repository.get(blob.uuid).open("rb").read() == content session.commit() assert repository.get(blob.uuid) is None
def __init__(self, **kw): self.has_documents = True self.membership_count = 0 self.document_count = 0 self.members_can_send_by_email = False Entity.__init__(self, **kw) if self.has_documents and not self.folder: #FIXME: this should be done in documents by using signals name = self.name if not name: # during creation, we may have to provide a temporary name for # subfolder, we don't want empty names on folders since they must be # unique among siblings name = u'{}_{}-{}'.format(self.__class__.__name__, str(self.id), time.asctime()) self.folder = repository.root_folder.create_subfolder(name) #if not self.group: # self.group = Group(name=self.name) if not self.image: fn = join(dirname(__file__), "data", "community.png") self.image = Blob(open(fn, 'rb').read())
def upload(request: Request, db: SQLAlchemy): user = get_current_profile() form = request.form demande_id = form["demande_id"] demande = db.session.query(Demande).get(demande_id) check_can_add_pj(demande) files = request.files for file in files.values(): file_name = file.filename data = file.read() blob = Blob(data) db.session.add(blob) db.session.flush() demande.attachments[file_name] = { "date": datetime.now().isoformat(), "id": blob.id, "creator": user.login, } db.session.commit() return "OK"
def test_mimetype(app: Flask, db: SQLAlchemy) -> None: content = StringIO("test") content.content_type = "text/plain" blob = Blob(content) assert "mimetype" in blob.meta assert blob.meta["mimetype"] == "text/plain"
def test_filename(app: Flask, db: SQLAlchemy) -> None: content = StringIO("test") content.filename = "test.txt" blob = Blob(content) assert "filename" in blob.meta assert blob.meta["filename"] == "test.txt"
def test_size(app: Flask, db: SQLAlchemy) -> None: blob = Blob("test") assert blob.size == 4
def test_md5(app: Flask, db: SQLAlchemy) -> None: blob = Blob("test md5") assert "md5" in blob.meta assert blob.meta["md5"] == "0e4e3b2681e8931c067a23c583c878d5"
def test_meta() -> None: blob = Blob() assert blob.meta == {}
def text(self, value): assert isinstance(value, text_type) self.text_blob = Blob() self.text_blob.value = value.encode("utf8")
def pdf(self, value): assert isinstance(value, bytes) self.pdf_blob = Blob() self.pdf_blob.value = value
def content(self, value): assert isinstance(value, bytes) self.content_blob = Blob() self.content_blob.value = value self.content_length = len(value)