Exemplo n.º 1
0
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
Exemplo n.º 2
0
    def test_value(self):
        session = self.session
        content = b'content'
        b = Blob(content)

        tr = session.begin(nested=True)
        session.add(b)
        tr.commit()

        assert repository.get(b.uuid) is None
        assert session_repository.get(b, b.uuid).open('rb').read() == content
        assert b.value == content

        session.commit()
        assert repository.get(b.uuid).open('rb').read() == content
        assert b.value == content

        session.begin(nested=True)  # match session.rollback

        with session.begin(nested=True):
            session.delete(b)
            # object marked for deletion, but instance attribute should still be
            # readable
            fd = session_repository.get(
                b,
                b.uuid,
            ).open('rb')
            assert fd.read() == content

        # commit in transaction: session_repository has no content, 'physical'
        # repository still has content
        assert session_repository.get(b, b.uuid) is None
        assert repository.get(b.uuid).open('rb').read() == content

        # rollback: session_repository has content again
        session.rollback()
        assert session_repository.get(b, b.uuid).open('rb').read() == content

        session.delete(b)
        session.flush()
        assert session_repository.get(b, b.uuid) is None
        assert repository.get(b.uuid).open('rb').read() == content

        session.commit()
        assert repository.get(b.uuid) is None
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def test_value(app, db):
    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
Exemplo n.º 5
0
  def test_value(self):
    session = self.session
    content = b'content'
    b = Blob(content)

    tr = session.begin(nested=True)
    session.add(b)
    tr.commit()

    self.assertIs(repository.get(b.uuid), None)
    self.assertEquals(session_repository.get(b, b.uuid).open('rb').read(),
                      content)
    self.assertEquals(b.value, content)

    session.commit()
    self.assertEquals(repository.get(b.uuid).open('rb').read(), content)
    self.assertEquals(b.value, content)

    tr = session.begin(nested=True)
    session.delete(b)
    # object marked for deletion, but instance attribute should still be
    # readable
    self.assertEquals(session_repository.get(b, b.uuid).open('rb').read(),
                      content)
    tr.commit()

    self.assertIs(session_repository.get(b, b.uuid), None)
    self.assertEquals(repository.get(b.uuid).open('rb').read(), content)

    session.rollback()
    self.assertEquals(session_repository.get(b, b.uuid).open('rb').read(),
                      content)

    session.delete(b)
    session.flush()
    self.assertIs(session_repository.get(b, b.uuid), None)
    self.assertEquals(repository.get(b.uuid).open('rb').read(), content)

    session.commit()
    self.assertIs(repository.get(b.uuid), None)
Exemplo n.º 6
0
 def file(self):
   """
   Return :class:`pathlib.Path` object used for storing value
   """
   return repository.get(self, self.uuid)