Example #1
0
def test_role(test_db):
    username = "******"
    group_id = "abcd-1234"

    App.get_or_create(default_appname, git=default_git, apptype="web")
    app = App.get_by_name(default_appname)
    assert app.name == default_appname

    rolename = f"app-{default_appname}-reader"
    role = Role.create(rolename, [app], [RBACAction.GET])
    assert Role.get_by_name("134haha") is None
    assert Role.get(role.id + 100000) is None

    role = Role.get(role.id)
    assert role.name == rolename

    UserRoleBinding.create(username, role)
    GroupRoleBinding.create(group_id, role)

    roles = UserRoleBinding.get_roles_by_name(username)
    assert len(roles) == 1
    assert roles[0].name == rolename

    roles = GroupRoleBinding.get_roles_by_id(group_id)
    assert len(roles) == 1
    assert roles[0].name == rolename

    role.delete()
    roles = UserRoleBinding.get_roles_by_name(username)
    assert len(roles) == 0

    roles = GroupRoleBinding.get_roles_by_id(group_id)
    assert len(roles) == 0
Example #2
0
def test_app(test_db):
    App.get_or_create(default_appname, git=default_git, apptype="web")
    app = App.get_by_name(default_appname)
    assert app.name == default_appname

    app.delete()
    app = App.get_by_name(default_appname)
    assert app is None
Example #3
0
def prepare(appname, username, group_id):
    App.get_or_create(appname, git=default_git, apptype="web")
    app = App.get_by_name(appname)
    assert app.name == appname

    app_reader_name, app_writer_name, app_admin_name = f"app-{app.name}-reader", f"app-{app.name}-writer", f"app-{app.name}-admin"

    app_reader = Role.create(app_reader_name, [app], [RBACAction.GET])
    app_writer = Role.create(app_writer_name, [app], [RBACAction.GET])
    app_admin = Role.create(app_admin_name, [app], [RBACAction.GET])

    UserRoleBinding.create(username, app_admin)
    GroupRoleBinding.create(group_id, app_reader)
Example #4
0
def test_app(test_db):
    u = User.get_by_username(FAKE_USER['username'])
    assert u is not None
    App.get_or_create(default_appname,
                      git=default_git,
                      apptype="web",
                      subscribers=[u])
    app = App.get_by_name(default_appname)
    assert app.name == default_appname
    assert len(app.subscriber_list) == 1
    assert app.subscriber_list[0].username == FAKE_USER['username']

    app.delete()
    app = App.get_by_name(default_appname)
    assert app is None
Example #5
0
def test_release(test_db):
    app = App.get_or_create(default_appname, git=default_git, apptype="web")
    Release.create(app, default_tag, default_specs_text)