示例#1
0
    def runTest(self):
        """ Tests the User object """
        try:
            User(username='******',
                 fullname='test test',
                 email='*****@*****.**',
                 super_admin=True,
                 disabled=False)
        except DuplicateEntryError:
            assert_true(False)
        b = User.selectBy(username="******").getOne()

        assert_not_equal(b, None)
        assert_equal(b.username, "test")
        try:
            b.set(username="******")
        except DuplicateEntryError:
            assert_true(False)
        assert_equal(b.username, "newName")
        b.set(username="******")
        l = b.get_subscriptions_of_owned_screens()
        assert_true(l.count() >= 0)
        una = User(username='******',
                   fullname='testnoadmin test',
                   email='*****@*****.**',
                   super_admin=False,
                   disabled=False)
        l = una.get_subscriptions_of_owned_screens()
        assert_true(l.count() >= 0)
        User.delete(una.id)
        b.set(disabled=True)
        assert_equal(b.disabled, True)
        t = b.owns_screen()
        assert_equal(t, False)
        b = User.selectBy(username="******").getOne()
        b.addScreen(Screen(name='A', building=Building(name='A')))
        t = b.owns_screen()
        assert_equal(t, True)
        b = User.selectBy(username="******").getOne()
        t = User.delete(b.id)
        assert_equal(t, None)
        b = User.selectBy(username="******").getOne(None)
        assert_true(None == b)
示例#2
0
    def runTest(self):
        """ Tests the User SQLObject """
        user = User(username='******', fullname='fullname', email='email')
        fake_plugin = Plugin(name='fake_plugin', activated='notfound')
        plugin_channel = PluginChannel(plugin=fake_plugin,
                                       name='Channel',
                                       subscription_right='public')
        building = Building(name='building')
        screen = Screen(name='Screen', building=building)
        screen.subscribe_to(user, plugin_channel)

        # Miscellaneous test
        assert user.log_name == 'fullname (%d)' % user.id
        user.fullname = None
        assert user.log_name == 'email (%d)' % user.id
        user.fullname = 'fullname'
        assert user.log_name == 'fullname (%d)' % user.id
        assert user.readable_name == 'fullname'
        user.fullname = None
        assert user.readable_name == 'username'
        user.username = None
        assert user.readable_name == 'email'

        # Test permissions
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == []

        plugin_channel.give_permission_to_user(
            user, UserPermissions.channel_contributor)
        assert user.highest_permission_level == UserPermissions.channel_contributor
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == [plugin_channel]
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == []

        plugin_channel.give_permission_to_user(
            user, UserPermissions.channel_administrator)
        assert user.highest_permission_level == UserPermissions.channel_administrator
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_contributor)) == []
        assert list(
            user.get_channels_with_permission_level(
                UserPermissions.channel_administrator)) == [plugin_channel]

        plugin_channel.remove_permission_to_user(user)
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []

        user.admin = True
        assert user.highest_permission_level == UserPermissions.administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        user.admin = False
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []
        user.super_admin = True
        assert user.highest_permission_level == UserPermissions.super_administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        user.super_admin = False
        assert user.highest_permission_level == UserPermissions.no_permission
        assert list(user.get_subscriptions_of_owned_screens()) == []

        screen.safe_add_user(user)
        assert user.highest_permission_level == UserPermissions.screen_administrator
        assert list(user.get_subscriptions_of_owned_screens()) == list(
            screen.subscriptions)
        screen.removeUser(user)
        assert list(user.get_subscriptions_of_owned_screens()) == []
        assert user.highest_permission_level == UserPermissions.no_permission