Esempio n. 1
0
def bootstrap(dbinfo):
    # Initialize the db layer
    config = testing.setUp()
    settings = config.get_settings()
    here = "/".join(os.path.dirname(__file__).split("/")[:-2])
    global_settings = {
        "__file__": os.path.join(here, "test/testing.ini"),
        "here": here,
        "venv": CONFIG.venv()
    }
    web.init(global_settings, settings, dbinfo)

    # Sync the database with mishmash
    __main__.main(["-D", dbinfo.url, "-c", "test/testing.ini", "sync"])

    # Create test users
    session = dbinfo.SessionMaker()
    user = models.addUser(session, "test", "test", auth.Roles.def_user_roles)
    user.avatar = 3
    session.add(user)
    session.commit()
    session.close()

    # Load the users
    models.load()
Esempio n. 2
0
def testDelUser(lsession):
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "adduser", "sue", "pass",
        "role1", "role2"
    ]
    ret = __main__.main()
    assert ret == 0
    sys.argv = ["unsonic", "-c", "test/testing2.ini", "deluser", "sue"]
    ret = __main__.main()
    assert ret == 0
    row = lsession.query(User).filter(User.name == "sue").all()
    assert len(row) == 0
Esempio n. 3
0
def testConfigGetGlobal(lsession):
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "config", "-s", "test1=val1"
    ]
    ret = __main__.main()
    assert ret == 0
    row = lsession.query(Config).filter(Config.key == "test1").all()
    assert len(row) == 1
    assert row[0].key == "test1"
    assert row[0].value == "val1"
    assert row[0].modified is not None

    sys.argv = ["unsonic", "-c", "test/testing2.ini", "config", "-g", "test1"]
    ret = __main__.main()
    assert ret == 0
Esempio n. 4
0
def testConfigSetGlobalBadKey(lsession):
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "config", "-s", "badkey=val1"
    ]
    ret = __main__.main()
    assert ret != 0
    row = lsession.query(Config).filter(Config.key == "badkey").all()
    assert len(row) == 0
Esempio n. 5
0
def testAddUserTwice(lsession):
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "adduser", "sue", "pass",
        "role1", "role2"
    ]
    ret = __main__.main()
    assert ret == 0
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "adduser", "sue", "pass",
        "role1", "role2"
    ]
    ret = __main__.main()
    assert ret == -1
    row = lsession.query(User).filter(User.name == "sue").all()
    assert len(row) == 1
    assert row[0].name == "sue"
    assert row[0].password == "pass"
    roles = [r.name for r in row[0].roles]
    assert "role1" in roles
    assert "role2" in roles
Esempio n. 6
0
def testConfigSetUser(lsession):
    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "adduser", "sue", "pass",
        "role1", "role2"
    ]
    ret = __main__.main()
    assert ret == 0

    sys.argv = [
        "unsonic", "-c", "test/testing2.ini", "config", "-s", "test1=val1",
        "sue"
    ]
    ret = __main__.main()
    assert ret == 0
    user = lsession.query(User).filter(User.name == "sue").one()
    row = lsession.query(UserConfig).filter(User.id == user.id,
                                            UserConfig.key == "test1").all()
    assert len(row) == 1
    assert row[0].user_id == user.id
    assert row[0].key == "test1"
    assert row[0].value == "val1"
    assert row[0].modified is not None
Esempio n. 7
0
def testConfigGetGlobalMissing(lsession):
    sys.argv = ["unsonic", "-c", "test/testing2.ini", "config", "-g", "test1"]
    ret = __main__.main()
    assert ret != 0