コード例 #1
0
def create_society(sess: SQLASession,
                   name: str,
                   description: str,
                   admins: Set[str],
                   role_email: str = None) -> Result[Society]:
    """
    Register or update a society in the database.
    """
    try:
        soc = get_society(name, sess)
    except KeyError:
        soc = Society(society=name,
                      description=description,
                      admins=get_members(sess, *admins),
                      role_email=role_email)
        sess.add(soc)
        state = State.success
    else:
        if admins != soc.admin_crsids:
            raise ValueError("Admins for {!r} are {}, expecting {}".format(
                name, soc.admin_crsids, admins))
        soc.description = description
        soc.role_email = role_email
        state = State.success if sess.is_modified(soc) else State.unchanged
    return Result(state, soc)
コード例 #2
0
ファイル: bespoke.py プロジェクト: SRCF/srcf-python
def _update_society(sess: SQLASession, society: Society, description: str,
                    role_email: Optional[str]) -> Result[Unset]:
    society.description = description
    society.role_email = role_email
    if not sess.is_modified(society):
        return Result(State.unchanged)
    LOG.debug("Updated society record: %r", society)
    return Result(State.success)
コード例 #3
0
ファイル: utils.py プロジェクト: SRCF/srcf-python
def create_test_session() -> Session:
    """
    Populate a test replica of the sysadmins' membership databases, and connect the default session
    for `srcf.database.queries`.
    """
    url = os.getenv("TEST_DB_URL")
    if not url:
        raise unittest.SkipTest("Requires test database, must set TEST_DB_URL")
    engine = create_engine(url)
    cls = sessionmaker(bind=engine)
    sess = cls(autocommit=True)
    queries._global_session = sess
    queries._auto_create_global_session = False
    if list(queries.list_members(sess)) or list(queries.list_societies(sess)):
        raise unittest.SkipTest("Test member database is not empty")
    sess.begin()
    mem = Member(crsid="spqr2", preferred_name="Preferred Names", surname="Surname",
                 email="*****@*****.**", mail_handler=MailHandler.forward.name,
                 member=True, user=True)
    sess.add(mem)
    soc = Society(society="unittest", description="Unit Testing Society",
                  role_email="*****@*****.**")
    soc.admins.add(mem)
    sess.add(soc)
    sess.commit()
    return sess
コード例 #4
0
 def test_create_society(self):
     name = "test"
     description = "Test Society {}".format(self.now)
     role_email = "sysadmins-python-unittest-{}@srcf.net".format(self.now)
     soc = Society(society=name, description=description, role_email=role_email)
     sess.add(soc)
     sess.flush()
     got = queries.get_society(name, sess)
     self.assertIs(soc, got)
     self.assertIsInstance(soc.uid, int)
     self.assertIsInstance(soc.gid, int)
コード例 #5
0
ファイル: bespoke.py プロジェクト: SRCF/srcf-python
def _create_society(sess: SQLASession,
                    name: str,
                    description: str,
                    role_email: Optional[str] = None) -> Result[Society]:
    society = Society(society=name,
                      description=description,
                      role_email=role_email)
    sess.add(society)
    # Populate UID and GID from the database.
    sess.flush()
    LOG.debug("Created society record: %r", society)
    return Result(State.created, society)
コード例 #6
0
 def test_website_society(self):
     society = Society(society="test")
     self.assertEqual(owner_website(society), "https://test.soc.srcf.net")
コード例 #7
0
 def test_desc_society_admins(self):
     society = Society(description="Test Society")
     self.assertEqual(owner_desc(society, True), "Test Society admins")
コード例 #8
0
 def test_desc_society(self):
     society = Society(description="Test Society")
     self.assertEqual(owner_desc(society), "Test Society")
コード例 #9
0
 def test_name_society(self):
     society = Society(society="test")
     self.assertEqual(owner_name(society), "test")