示例#1
0
    def test_userflags(self):
        """Ensure user flags are set as expected.

        """
        user1 = create_account('user1', '*****@*****.**', 'Password')
        self.assertIsNotNone(user1)

        # Not active by default
        self.assertFalse(get_user(user1).get('active'))
        # TTL should be set
        self.assertIsNotNone(get_user(user1).get('ttl'))
        # Activate
        self.assertTrue(activate(user1))
        self.assertTrue(get_user(user1).get('active'))
        self.assertIsNone(get_user(user1).get('ttl'))
        # Deactivate
        self.assertTrue(activate(user1, False))
        self.assertFalse(get_user(user1).get('active'))
        # Invalid
        self.assertFalse(activate(None))
        self.assertFalse(activate(K.NIL_VALUE))

        # Banning, not by default
        self.assertFalse(get_user(user1).get('banned'))
        # Ban
        self.assertTrue(ban(user1))
        self.assertTrue(get_user(user1).get('banned'))
        # Un-ban
        self.assertTrue(ban(user1, False))
        self.assertFalse(get_user(user1).get('banned'))
        # Invalid
        self.assertFalse(ban(None))
        self.assertFalse(ban(K.NIL_VALUE))

        # OP (Over powered or Operator?) Account should not be op
        self.assertFalse(get_user(user1).get('op'))
        # Bite
        self.assertTrue(bite(user1))
        self.assertTrue(get_user(user1).get('op'))
        # Un-bite
        self.assertTrue(bite(user1, False))
        self.assertFalse(get_user(user1).get('op'))
        # Invalid
        self.assertFalse(bite(None))
        self.assertFalse(bite(K.NIL_VALUE))

        # Muted, can't post, not by default
        self.assertFalse(get_user(user1).get('muted'))
        # Mute
        self.assertTrue(mute(user1))
        self.assertTrue(get_user(user1).get('muted'))
        # Un-mute
        self.assertTrue(mute(user1, False))
        self.assertFalse(get_user(user1).get('muted'))
        # Invalid
        self.assertFalse(mute(None))
        self.assertFalse(mute(K.NIL_VALUE))
示例#2
0
    def test_userflags(self):
        """Ensure user flags are set as expected.

        """
        user1 = create_account('user1', '*****@*****.**', 'Password')
        self.assertIsNotNone(user1)

        # Not active by default
        self.assertFalse(get_user(user1).get('active'))
        # TTL should be set
        self.assertIsNotNone(get_user(user1).get('ttl'))
        # Activate
        self.assertTrue(activate(user1))
        self.assertTrue(get_user(user1).get('active'))
        self.assertIsNone(get_user(user1).get('ttl'))
        # Deactivate
        self.assertTrue(activate(user1, False))
        self.assertFalse(get_user(user1).get('active'))
        # Invalid
        self.assertFalse(activate(None))
        self.assertFalse(activate(K.NIL_VALUE))

        # Banning, not by default
        self.assertFalse(get_user(user1).get('banned'))
        # Ban
        self.assertTrue(ban(user1))
        self.assertTrue(get_user(user1).get('banned'))
        # Un-ban
        self.assertTrue(ban(user1, False))
        self.assertFalse(get_user(user1).get('banned'))
        # Invalid
        self.assertFalse(ban(None))
        self.assertFalse(ban(K.NIL_VALUE))

        # OP (Over powered or Operator?) Account should not be op
        self.assertFalse(get_user(user1).get('op'))
        # Bite
        self.assertTrue(bite(user1))
        self.assertTrue(get_user(user1).get('op'))
        # Un-bite
        self.assertTrue(bite(user1, False))
        self.assertFalse(get_user(user1).get('op'))
        # Invalid
        self.assertFalse(bite(None))
        self.assertFalse(bite(K.NIL_VALUE))

        # Muted, can't post, not by default
        self.assertFalse(get_user(user1).get('muted'))
        # Mute
        self.assertTrue(mute(user1))
        self.assertTrue(get_user(user1).get('muted'))
        # Un-mute
        self.assertTrue(mute(user1, False))
        self.assertFalse(get_user(user1).get('muted'))
        # Invalid
        self.assertFalse(mute(None))
        self.assertFalse(mute(K.NIL_VALUE))
示例#3
0
    def test_flag_control(self):
        """Ensure flagged posts appear in the dashboard"""
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')

        # Make user1 OP
        bite(user1)
        activate(user1)

        post1 = create_post(user2, 'user2', 'post1')
        post2 = create_post(user2, 'user2', 'post2')

        comment1 = create_post(user2, 'user2', 'comment1', post1)
        comment2 = create_post(user2, 'user2', 'comment2', post1)

        # Flag all the posts
        flag_post(user1, post1)
        flag_post(user1, post2)
        flag_post(user1, comment1)
        flag_post(user1, comment2)

        self.client.post(url_for('auth.signin'), data={
            'username': '******',
            'password': '******'
        })
        resp = self.client.get(url_for('dashboard.dashboard'))

        s = '{0} - <a href="{1}">{2}</a>: <a href="{3}">{4}</a> ' + \
            '[<a href="{5}">Unflag</a>]'

        self.assertIn(s.format(
            1,
            url_for('users.profile',
                    username='******'),
            'user2',
            url_for('posts.view_post',
                    username='******',
                    post_id=post1),
            post1,
            url_for('posts.unflag_post', post_id=post1)
        ), resp.data)

        self.assertIn(s.format(
            1,
            url_for('users.profile',
                    username='******'),
            'user2',
            url_for('posts.view_post',
                    username='******',
                    post_id=post1),
            comment1,
            url_for('posts.unflag_post', post_id=comment1)
        ) + ' (comment)', resp.data)
示例#4
0
    def test_dashboard_view(self):
        """Ensure basic stats show in dashboard"""
        user1 = create_account('user1', '*****@*****.**', 'Password')
        activate(user1)

        # Ensure we can't hit the endpoint not logged in
        # We WONT be redirected to login
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 403)

        # Log in
        self.client.post(url_for('auth.signin'),
                         data={
                             'username': '******',
                             'password': '******'
                         })

        # Ensure we can't hit the endpoint if we are logged in but not op
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 403)

        # Make the user OP
        bite(user1)

        # Check
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 200)

        # Ensure there are some stats for the different libraries we expect
        # 'Server' is provided by the dashboard itself
        self.assertIn('Server', resp.data)

        # We can further check the 'Server' section as we need to anyway.
        self.assertIn('Hostname', resp.data)
        self.assertIn('Uname', resp.data)
        self.assertIn('Time UTC', resp.data)
        self.assertIn('Timestamp', resp.data)

        # Check the values we can
        self.assertIn(' '.join(os.uname()), resp.data)
        self.assertIn(socket.gethostname(), resp.data)

        # 'Auth' is provided by pjuu.auth
        self.assertIn('Auth', resp.data)

        # 'Posts' is provided by pjuu.posts
        self.assertIn('Posts', resp.data)
示例#5
0
    def test_dashboard_view(self):
        """Ensure basic stats show in dashboard"""
        user1 = create_account('user1', '*****@*****.**', 'Password')
        activate(user1)

        # Ensure we can't hit the endpoint not logged in
        # We WONT be redirected to login
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 403)

        # Log in
        self.client.post(url_for('auth.signin'), data={
            'username': '******',
            'password': '******'
        })

        # Ensure we can't hit the endpoint if we are logged in but not op
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 403)

        # Make the user OP
        bite(user1)

        # Check
        resp = self.client.get(url_for('dashboard.dashboard'))
        self.assertEqual(resp.status_code, 200)

        # Ensure there are some stats for the different libraries we expect
        # 'Server' is provided by the dashboard itself
        self.assertIn('Server', resp.data)

        # We can further check the 'Server' section as we need to anyway.
        self.assertIn('Hostname', resp.data)
        self.assertIn('Uname', resp.data)
        self.assertIn('Time UTC', resp.data)
        self.assertIn('Timestamp', resp.data)

        # Check the values we can
        self.assertIn(' '.join(os.uname()), resp.data)
        self.assertIn(socket.gethostname(), resp.data)

        # 'Auth' is provided by pjuu.auth
        self.assertIn('Auth', resp.data)

        # 'Posts' is provided by pjuu.posts
        self.assertIn('Posts', resp.data)
示例#6
0
    def test_stats(self):
        """Ensure the ``pjuu.auth.stats``s exposed stats are correct.

        """
        stats = dict(get_stats())

        self.assertEqual(stats.get('Total users'), 0)
        self.assertEqual(stats.get('Total active users'), 0)
        self.assertEqual(stats.get('Total banned users'), 0)
        self.assertEqual(stats.get('Total muted users'), 0)
        self.assertEqual(stats.get('Total OP users'), 0)
        self.assertEqual(stats.get('Newest users'), [])

        create_account('user1', '*****@*****.**', 'Password')

        user2 = create_account('user2', '*****@*****.**', 'Password')
        activate(user2)

        user3 = create_account('user3', '*****@*****.**', 'Password')
        activate(user3)
        ban(user3)

        user4 = create_account('user4', '*****@*****.**', 'Password')
        activate(user4)
        mute(user4)

        user5 = create_account('user5', '*****@*****.**', 'Password')
        bite(user5)

        # Turn in to dict for easier checking.
        stats = dict(get_stats())

        # URL string to ensure links are being added in to newest users
        self.assertEqual(stats.get('Total users'), 5)
        self.assertEqual(stats.get('Total active users'), 3)
        self.assertEqual(stats.get('Total banned users'), 1)
        self.assertEqual(stats.get('Total muted users'), 1)
        self.assertEqual(stats.get('Total OP users'), 1)

        user_list = ['user5', 'user4', 'user3', 'user2', 'user1']
        newest_users = stats.get('Newest users')

        for i in xrange(len(newest_users)):
            self.assertIn(user_list[i], newest_users[i])
示例#7
0
    def test_stats(self):
        """Ensure the ``pjuu.auth.stats``s exposed stats are correct.

        """
        stats = dict(get_stats())

        self.assertEqual(stats.get('Total users'), 0)
        self.assertEqual(stats.get('Total active users'), 0)
        self.assertEqual(stats.get('Total banned users'), 0)
        self.assertEqual(stats.get('Total muted users'), 0)
        self.assertEqual(stats.get('Total OP users'), 0)
        self.assertEqual(stats.get('Newest users'), [])

        create_account('user1', '*****@*****.**', 'Password')

        user2 = create_account('user2', '*****@*****.**', 'Password')
        activate(user2)

        user3 = create_account('user3', '*****@*****.**', 'Password')
        activate(user3)
        ban(user3)

        user4 = create_account('user4', '*****@*****.**', 'Password')
        activate(user4)
        mute(user4)

        user5 = create_account('user5', '*****@*****.**', 'Password')
        bite(user5)

        # Turn in to dict for easier checking.
        stats = dict(get_stats())

        # URL string to ensure links are being added in to newest users
        self.assertEqual(stats.get('Total users'), 5)
        self.assertEqual(stats.get('Total active users'), 3)
        self.assertEqual(stats.get('Total banned users'), 1)
        self.assertEqual(stats.get('Total muted users'), 1)
        self.assertEqual(stats.get('Total OP users'), 1)

        user_list = ['user5', 'user4', 'user3', 'user2', 'user1']
        newest_users = stats.get('Newest users')

        for i in xrange(len(newest_users)):
            self.assertIn(user_list[i], newest_users[i])
示例#8
0
    def test_flag_control(self):
        """Ensure flagged posts appear in the dashboard"""
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')

        # Make user1 OP
        bite(user1)
        activate(user1)

        post1 = create_post(user2, 'user2', 'post1')
        post2 = create_post(user2, 'user2', 'post2')

        comment1 = create_post(user2, 'user2', 'comment1', post1)
        comment2 = create_post(user2, 'user2', 'comment2', post1)

        # Flag all the posts
        flag_post(user1, post1)
        flag_post(user1, post2)
        flag_post(user1, comment1)
        flag_post(user1, comment2)

        self.client.post(url_for('auth.signin'),
                         data={
                             'username': '******',
                             'password': '******'
                         })
        resp = self.client.get(url_for('dashboard.dashboard'))

        s = '{0} - <a href="{1}">{2}</a>: <a href="{3}">{4}</a> ' + \
            '[<a href="{5}">Unflag</a>]'

        self.assertIn(
            s.format(
                1, url_for('users.profile', username='******'), 'user2',
                url_for('posts.view_post', username='******', post_id=post1),
                post1, url_for('posts.unflag_post', post_id=post1)), resp.data)

        self.assertIn(
            s.format(
                1, url_for('users.profile', username='******'), 'user2',
                url_for('posts.view_post', username='******', post_id=post1),
                comment1, url_for('posts.unflag_post', post_id=comment1)) +
            ' (comment)', resp.data)