Exemple #1
0
    def test_group_get(self):
        rv = self.client.get('/groups/1')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/groups/1')
        assert_equal(rv.json['name'], AdminGroup['name'])
Exemple #2
0
    def test_user_get(self):
        rv = self.client.get('/users/1')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/users/1')
        user = rv.json
        assert_equal(user['username'], USER1['username'])
Exemple #3
0
    def test_user_get(self):
        rv = self.client.get('/users/1')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/users/1')
        user = rv.json
        assert_equal(user['username'], USER1['username'])
Exemple #4
0
    def test_groups_get(self):
        rv = self.client.get('/groups/')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/groups/')
        adminGroup, guestGroup = rv.json
        assert_equal(adminGroup['name'], AdminGroup['name'])
        assert_equal(guestGroup['name'], GuestGroup['name'])
Exemple #5
0
    def test_user_put(self):
        data = {'username': '******'}
        rv = self.client.post('users/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        user = db.session.query(UserModel).filter_by(id=1).one()
        assert_equal(user.username, 'Airead')
Exemple #6
0
    def test_group_put(self):
        data = {'group_id': 1}
        rv = self.client.post('user_groups/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('user_groups/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        group = db.session.query(UserGroupModel).filter_by(id=1).one()
        assert_equal(group.group_id, 1)
    def test_group_delete(self):
        rv = self.client.post('group_permissions/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('group_permissions/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        groups = db.session.query(GroupPermissionModel).all()
        assert_equal(len(groups), 1)
        group = groups[0]
        assert_equal(group.permission_id, GroupPerm2['permission_id'])
Exemple #8
0
    def _test_permission_delete(self):
        rv = self.client.post('permissions/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('permissions/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        ps = db.session.query(PermissionModel).all()
        assert_equal(len(ps), 1)
        p = ps[0]
        assert_equal(p.name, Perm2['name'])
Exemple #9
0
    def test_users_get(self):
        rv = self.client.get('/users/')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/users/')

        user1, user2 = rv.json
        assert_equal(user1['id'], 1)
        assert_equal(user1['username'], 'user1')
        assert_equal(user2['id'], 2)
        assert_equal(user2['username'], 'user2')
Exemple #10
0
    def test_group_delete_by_user_group_id(self):
        rv = self.client.post('/user_groups/1/2?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('/user_groups/1/2?at=delete')
        assert_equal(rv.json, SuccessRet)

        groups = db.session.query(UserGroupModel).all()
        assert_equal(len(groups), 1)
        group = groups[0]
        assert_equal(group.group_id, UserGroup2['group_id'])
    def test_group_delete_by_user_group_id(self):
        rv = self.client.post('/user_groups/1/2?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('/user_groups/1/2?at=delete')
        assert_equal(rv.json, SuccessRet)

        groups = db.session.query(UserGroupModel).all()
        assert_equal(len(groups), 1)
        group = groups[0]
        assert_equal(group.group_id, UserGroup2['group_id'])
Exemple #12
0
    def test_user_delete(self):
        rv = self.client.post('users/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        users = db.session.query(UserModel).all()
        assert_equal(len(users), 1)
        user = users[0]
        assert_equal(user.username, USER2['username'])
Exemple #13
0
    def test_groups_post(self):
        data = {'group_id': 2, 'permission_id': 2}

        rv = self.client.post('group_permissions/', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('group_permissions/', data=data)
        assert_equal(rv.json['uri'], '/group_permissions/3')

        groups = db.session.query(GroupPermissionModel).all()
        assert_equal(len(groups), 3)
Exemple #14
0
    def test_group_delete(self):
        rv = self.client.post('groups/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('groups/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        groups = db.session.query(GroupModel).all()
        assert_equal(len(groups), 1)
        group = groups[0]
        assert_equal(group.name, GuestGroup['name'])
Exemple #15
0
    def test_groups_post(self):
        data = {'user_id': 1, 'group_id': 1}

        rv = self.client.post('user_groups/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('user_groups/?at=post', data=data)
        assert_equal(rv.json['uri'], '/user_groups/3')

        groups = db.session.query(UserGroupModel).all()
        assert_equal(len(groups), 3)
Exemple #16
0
    def test_user_delete(self):
        rv = self.client.post('users/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        users = db.session.query(UserModel).all()
        assert_equal(len(users), 1)
        user = users[0]
        assert_equal(user.username, USER2['username'])
Exemple #17
0
    def test_users_get(self):
        rv = self.client.get('/users/')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.get('/users/')

        user1, user2 = rv.json
        assert_equal(user1['id'], 1)
        assert_equal(user1['username'], 'user1')
        assert_equal(user2['id'], 2)
        assert_equal(user2['username'], 'user2')
Exemple #18
0
    def test_group_delete(self):
        rv = self.client.post('group_permissions/1?at=delete')
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('group_permissions/1?at=delete')
        assert_equal(rv.json, SuccessRet)

        groups = db.session.query(GroupPermissionModel).all()
        assert_equal(len(groups), 1)
        group = groups[0]
        assert_equal(group.permission_id, GroupPerm2['permission_id'])
Exemple #19
0
    def test_user_put(self):
        data = {
            'username': '******'
        }
        rv = self.client.post('users/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        user = db.session.query(UserModel).filter_by(id=1).one()
        assert_equal(user.username, 'Airead')
Exemple #20
0
    def _test_permission_put(self):
        data = {
            'tag': 'stupidAdmin'
        }
        rv = self.client.post('permissions/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('permissions/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        group = db.session.query(PermissionModel).filter_by(id=1).one()
        assert_equal(group.tag, 'stupidAdmin')
Exemple #21
0
    def test_group_put(self):
        data = {
            'name': '笨蛋管理员'
        }
        rv = self.client.post('groups/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('groups/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        group = db.session.query(GroupModel).filter_by(id=1).one()
        assert_equal(group.name, u'笨蛋管理员')
    def test_group_put(self):
        data = {
            'permission_id': 1
        }
        rv = self.client.post('group_permissions/1?at=put', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('group_permissions/1?at=put', data=data)
        assert_equal(rv.json, SuccessRet)

        group = db.session.query(GroupPermissionModel).filter_by(id=1).one()
        assert_equal(group.permission_id, 1)
    def test_groups_post(self):
        data = {
            'group_id': 2,
            'permission_id': 2
        }

        rv = self.client.post('group_permissions/', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('group_permissions/', data=data)
        assert_equal(rv.json['uri'], '/group_permissions/3')

        groups = db.session.query(GroupPermissionModel).all()
        assert_equal(len(groups), 3)
    def test_groups_post(self):
        data = {
            'user_id': 1,
            'group_id': 1
        }

        rv = self.client.post('user_groups/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('user_groups/?at=post', data=data)
        assert_equal(rv.json['uri'], '/user_groups/3')

        groups = db.session.query(UserGroupModel).all()
        assert_equal(len(groups), 3)
Exemple #25
0
    def test_groups_post(self):
        data = {
            'name': '超级管理员',
        }

        rv = self.client.post('groups/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('groups/?at=post', data=data)
        print rv.json
        assert_equal(rv.json['uri'], '/groups/3')

        groups = db.session.query(GroupModel).all()
        assert_equal(len(groups), 3)
Exemple #26
0
    def _test_permissions_post(self):
        data = {
            'name': '超级管理员',
            'tag': 'superAdmin',
        }

        rv = self.client.post('permissions/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('permissions/?at=post', data=data)
        print rv.json
        assert_equal(rv.json['uri'], '/permissions/3')

        permissions = db.session.query(PermissionModel).all()
        assert_equal(len(permissions), 3)
Exemple #27
0
    def test_users_post(self):
        data = {
            'username': '******',
            'first_name': 'us',
            'last_name': 'er3',
            'email': '*****@*****.**',
            'password': '******',
            'is_staff': True,
            'is_active': True,
            'is_superuser': True,
            'last_login': get_string_from_datetime(datetime.now()),
            'date_joined': get_string_from_datetime(datetime.now())
        }
        rv = self.client.post('users/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/?at=post', data=data)
        assert_equal(rv.json['uri'], '/users/3')

        users = db.session.query(UserModel).all()
        assert_equal(len(users), 3)
Exemple #28
0
    def test_users_post(self):
        data = {
            'username': '******',
            'first_name': 'us',
            'last_name': 'er3',
            'email': '*****@*****.**',
            'password': '******',
            'is_staff': True,
            'is_active': True,
            'is_superuser': True,
            'last_login': get_string_from_datetime(datetime.now()),
            'date_joined': get_string_from_datetime(datetime.now())
        }
        rv = self.client.post('users/?at=post', data=data)
        self.assert403(rv)

        with role_set(Roles.admin):
            rv = self.client.post('users/?at=post', data=data)
        assert_equal(rv.json['uri'], '/users/3')

        users = db.session.query(UserModel).all()
        assert_equal(len(users), 3)
Exemple #29
0
 def test_user_info_get(self):
     with role_set(Roles.admin):
         rv = self.client.get('/users/infos/1')
         print rv.data
Exemple #30
0
 def test_cur_identity(self):
     with role_set(Roles.admin):
         rv = self.client.get('/login/cur_identity')
     print rv.data
Exemple #31
0
 def test_user_info_get(self):
     with role_set(Roles.admin):
         rv = self.client.get('/users/infos/1')
         print rv.data
Exemple #32
0
 def test_cur_identity(self):
     with role_set(Roles.admin):
         rv = self.client.get('/login/cur_identity')
     print rv.data