コード例 #1
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_get_user(self):
        write_test_data()
        session = connection.get_session()
        user_api = UserApi(session)
        user = user_api.get_user(user_id="1")
        assert user.get("name") == "test_user1"

        try:
            user = user_api.get_user(user_id="10")
        except exception.UserNotFound as e:
            assert isinstance(e, exception.UserNotFound)
コード例 #2
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_list_users(self):
        # test the empty user table
        session = connection.get_session()
        user_api = UserApi(session)
        users = user_api.list_users()
        assert isinstance(users, list)
        assert len(users) == 0

        write_test_data()
        users = user_api.list_users()
        assert isinstance(users, list)
        assert len(users) == 5
コード例 #3
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_delete_project(self):
        write_domain_data()
        write_project_data()
        session = connection.get_session()
        project_api = ProjectApi(session)
        projects = project_api.list_projects()
        assert len(projects) == 4
        for i in get_project_data():
            project_api.delete_project(i.to_dict().get("id"))
        projects = project_api.list_projects()
        assert len(projects) == 0

        write_project_data()
        write_user_data()
        try:
            project_api.delete_project(project_id="1")
        except exception.Constraint as e:
            assert isinstance(e, exception.Constraint)
        else:
            pass
            # raise Exception("Constraint didn't happen")
        user_api = UserApi(session)
        users = user_api.list_users()
コード例 #4
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_delete_user(self):
        write_domain_data()
        write_project_data()
        write_group_data()
        write_user_data()
        write_role_data()

        session = connection.get_session()
        user_api = UserApi(session)
        users = get_user_data()
        for user in users:
            user_id = user.to_dict().get("id")
            user_api.delete_user(user_id)
        users = user_api.list_users()
        assert len(users) == 0

        try:
            user_api.delete_user(user_id="1")
        except exception.UserNotFound as e:
            assert isinstance(e, exception.UserNotFound)
        else:
            raise Exception("Delete user failed didn't happen")

        write_user_data()
        write_user_group_membership()
        write_user_role_membership()
        write_group_role_membership()

        with session.begin():
            ugms = session.query(default_model.UserGroupMembership).filter_by(user_id="1").all()
            assert len(ugms) != 0

        user_api.delete_user(user_id="1")

        with session.begin():
            ugms = session.query(default_model.UserGroupMembership).filter_by(user_id="1").all()
            assert len(ugms) == 0
コード例 #5
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_update_user(self):
        write_test_data()
        session = connection.get_session()
        user_api = UserApi(session)

        user = {"name": "test_user20"}
        user_api.update_user(user_id="2", user=user)
        u = user_api.get_user(user_id="2")
        assert u.get("name") == "test_user20"

        user = {"name": "test_user3"}
        try:
            user_api.update_user(user_id="1", user=user)
        except exception.Conflict as e:
            assert isinstance(e, exception.Conflict)
        else:
            raise Exception("Conflict didn't happen")
コード例 #6
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
    def test_create_user(self):
        write_domain_data()
        write_project_data()
        session = connection.get_session()

        user_api = UserApi(session)
        for user in get_user_data():
            user = user.to_dict()
            user_api.create_user(user)
        users = user_api.list_users()
        assert len(users) == 5

        for user in get_user_data():
            try:
                user = user.to_dict()
                user_api.create_user(user)
            except Exception as e:
                assert isinstance(e, exception.Conflict)
コード例 #7
0
ファイル: test_model_sql.py プロジェクト: chenbillcat/AuthDog
 def test_list_user_role_membership(self):
     write_test_data()
     session = connection.get_session()
     user_api = UserApi(session)
     urms = user_api.list_user_role_membership(user_id="1")
     assert len(urms) == 2