Example #1
0
def test_cake_type():
    meta = MetaData()
    tbl = Table(
        "mytable", meta,
        Column("guid",
               StringCast(ids.Cake),
               primary_key=True,
               default=lambda: ids.Cake.new_portal()),
        Column('name', types.String()),
        Column("attachment", StringCast(ids.Cake), nullable=True))
    tbl2 = Table(
        "mytable2", meta,
        Column("guid",
               StringCast(ids.Cake),
               primary_key=True,
               default=lambda: ids.Cake.new_portal()),
        Column('name', types.String()),
        Column("attachment", StringCast(ids.Cake), nullable=True))

    #'sqlite:///:memory:'

    dbf = Dbf(meta, test.file_path('test.sqlite3'))

    def run_scenario(dbf, tbl):
        with dbf.connect() as conn:
            r = conn.execute(tbl.insert().values(name='abc'))
            guid1 = r.last_inserted_params()['guid']
            log.debug(guid1)
            r = conn.execute(tbl.insert().values(name='xyz', attachment=None))
            guid2 = r.last_inserted_params()['guid']
            log.debug(guid2)
        dbf.execute(tbl.update().where(tbl.c.guid == guid1).values(
            name='ed', attachment=ids.Cake.from_bytes(b'asdf')))
        fetch = dbf.execute(select([tbl])).fetchall()
        attach = {r.guid: r.attachment for r in fetch}
        return attach, guid1, guid2

    ok_(not dbf.exists())
    dbf.ensure_db()
    attach, guid1, guid2 = run_scenario(dbf, tbl)
    eq_(attach[guid1], ids.Cake('01ME5Mi'))
    eq_(attach[guid2], None)
    attach, guid1, guid2 = run_scenario(dbf, tbl2)
    eq_(attach[guid1], ids.Cake('01ME5Mi'))
    eq_(attach[guid2], None)
    tbl.drop(dbf.engine())
    eq_(dbf.engine().table_names(), ['mytable2'])
    dbf = Dbf(meta, test.file_path('test.sqlite3'))
    eq_(dbf.engine().table_names(), ['mytable2'])
    dbf.ensure_db()
    eq_(dbf.engine().table_names(), ['mytable', 'mytable2'])
Example #2
0
class VolatileTree(NameIt, ReprIt, CakeShardBase):
    portal_id = Column(None, ForeignKey('portal.id'), primary_key=True)
    path = Column(String, nullable=False, primary_key=True)
    parent_path = Column(String, nullable=False)
    cake = Column(StringCast(Cake), nullable=True)
    size = Column(Integer, nullable=True)
    file_type = Column(String, nullable=True)
    mime = Column(String, nullable=True)
    start_by = Column(StringCast(Cake), nullable=False)
    end_by = Column(StringCast(Cake), nullable=True)
    start_dt = Column(DateTime,
                      nullable=False,
                      primary_key=True,
                      default=datetime.datetime.utcnow)
    end_dt = Column(DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
Example #3
0
class Permission(PortalPkWithSynapseDefault, NameIt, Cdt, Udt, GlueBase):
    user_id = Column(None, ForeignKey('user.id'))
    cake = Column(StringCast(Cake), nullable=True)
    permission_type = Column(IntCast(PermissionType, lambda pt: pt.code),
                             nullable=False)
    user = relationship("User", back_populates="permissions")

    def expanded_acls(self):
        for pt in self.permission_type.expands:
            yield Acl(None, pt, self.cake)
Example #4
0
class User(PortalPkWithSynapseDefault, NameIt, Cdt, Udt, ReprIt, GlueBase):
    email = Column(String, nullable=False)
    user_state = Column(IntCast(UserState), nullable=False)
    user_type = Column(IntCast(UserType),
                       nullable=False,
                       default=UserType.normal)
    passwd = Column(StringCast(SaltedSha), nullable=False)
    full_name = Column(String, nullable=True)
    permissions = relationship("Permission",
                               order_by="Permission.id",
                               back_populates="user")

    def acls(self, force_refresh=False):
        if force_refresh or not hasattr(self, '_acls'):
            self._acls = set()
            for p in self.permissions:
                self._acls.update(p.expanded_acls())
        return self._acls
Example #5
0
class ServersMixin(NameIt, Cdt, Udt):
    id = Column(StringCast(Cake), primary_key=True)
    server_url = Column(String)
    secret = Column(StringCast(SaltedSha), nullable=False)
Example #6
0
 class PortalPk:
     id = Column(StringCast(Cake),
                 primary_key=True,
                 default=lambda: Cake.new_portal(**ch_kwargs))
Example #7
0
class CakePk:
    id = Column(StringCast(Cake), primary_key=True)
Example #8
0
class DirEntry(NameIt, ReprIt, ScanBase):
    name = Column(String, primary_key=True)
    file_type = Column(IntCast(FileType), nullable=False)
    cake = Column(StringCast(Cake), nullable=False)
    size = Column(Integer, nullable=True)
    modtime = Column(Integer, nullable=True)
Example #9
0
class DirKey(DirSingleton, ScanBase):
    last_backup_path = Column(StringCast(CakePath), nullable=True)
Example #10
0
class Blob(NameIt, ReprIt, Cdt, BlobBase):
    blob_id = Column(Integer, primary_key=True, autoincrement=True)
    file_id = Column(StringCast(ContentAddress), nullable=False)
    content = Column(LargeBinary)
Example #11
0
class BackLink(CakePk, NameIt, Cdt, Udt, CakeShardBase):
    referrer = Column(StringCast(Cake), nullable=False)
Example #12
0
class ServerKey(Singleton, ServerConfigBase):
    secret = Column(StringCast(Cake), default=Cake.new_portal())
    external_ip = Column(StringCast(InetAddress), nullable=True)
    port = Column(Integer, nullable=False)
    num_cake_shards = Column(Integer, nullable=False)
Example #13
0
class PortalHistory(NameIt, Cdt, CakeShardBase):
    portal_id = Column(None, ForeignKey('portal.id'), primary_key=True)
    dt = Column(DateTime, primary_key=True, default=datetime.datetime.utcnow)
    by = Column(StringCast(Cake), nullable=False)
    cake = Column(StringCast(Cake), nullable=False)
Example #14
0
class Portal(CakePk, NameIt, Cdt, Udt, CakeShardBase):
    latest = Column(StringCast(Cake), nullable=True)
    active = Column(Boolean, nullable=False, default=True)
Example #15
0
 class NewSingleton(NameIt, ReprIt):
     single = Column(Integer, primary_key=True, default=1)
     id = Column(StringCast(Cake), nullable=False, default=new_dmount)
Example #16
0
class UserSession(PortalPkWithSynapseDefault, NameIt, Cdt, Udt, ReprIt,
                  ServerConfigBase):
    user = Column(StringCast(Cake), nullable=False)
    client = Column(StringCast(SaltedSha), nullable=True)
    remote_host = Column(String, nullable=True)
    active = Column(Boolean, nullable=False)
Example #17
0
class Incoming(NameIt, ReprIt, Cdt, Udt, IncomingBase):
    incoming_id = Column(Integer, primary_key=True, autoincrement=True)
    file_id = Column(StringCast(ContentAddress), nullable=True)
    new = Column(Boolean)