def test_role_as_json(self): resources = [{'name': 'resource1', 'permissions': ['create']}, {'name': 'resource2', 'permissions': ['create']}, {'name': 'resource3', 'permissions': ['create']}] role = Role(name='test', description='desc', resources=resources) role_json = role.as_json() self.assertSetEqual(set(role_json.keys()), {'name', 'description', 'resources', 'id'}) self.assertEqual(role_json['name'], 'test') self.assertEqual(role_json['description'], 'desc') self.assertEqual(len(role_json['resources']), len(resources))
def test_role_as_json(self): resources = [{'name': 'resource1', 'permissions': ['create']}, {'name': 'resource2', 'permissions': ['create']}, {'name': 'resource3', 'permissions': ['create']}] role = Role(name='test', description='desc', resources=resources) role_json = role.as_json() self.assertSetEqual(set(role_json.keys()), {'name', 'description', 'resources', 'id'}) self.assertEqual(role_json['name'], 'test') self.assertEqual(role_json['description'], 'desc') self.assertEqual(len(role_json['resources']), len(resources))
def test_roles_as_json_with_users_one_user(self): role = Role('role1') db.session.add(role) db.session.commit() user = User('username', 'password') db.session.add(user) user.set_roles([role.id]) expected = {'name': 'role1', 'description': '', 'resources': [], 'users': ['username']} role_json = role.as_json(with_users=True) role_json.pop('id') self.assertDictEqual(role_json, expected)