Ejemplo n.º 1
0
    def test_leaderboard_foo_dash_key_current_user_window(self):
        """Test JOB leaderboard returns users for foo-dash key with current user and
        window."""
        UserFactory.create_batch(10, info={'foo-dash': 0})
        UserFactory.create_batch(10, info={'foo-dash': 2})
        UserFactory.create_batch(10, info={'foo-dash': 2}, restrict=True)
        users = []
        for score in range(11, 22):
            users.append(UserFactory.create(info={'foo-dash': score}))
        myself = UserFactory.create(info={'foo-dash': 1})

        leaderboard(info='foo-dash')

        top_users = get_leaderboard(user_id=myself.id,
                                    info='foo-dash',
                                    window=5)

        assert len(top_users) == 20 + 5 + 1 + 5, len(top_users)
        assert top_users[25]['name'] == myself.name
        assert top_users[25]['score'] == myself.info.get('foo-dash')
        assert top_users[24]['score'] >= myself.info.get('foo-dash')
        assert top_users[26]['score'] <= myself.info.get('foo-dash')

        results = db.session.execute('select * from "users_rank_foo-dash"')
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 2
0
 def test_anon_week(self):
     """Test JOB leaderboard returns anon active week runs."""
     users = UserFactory.create_batch(20)
     for user in users:
         TaskRunFactory.create(user=user)
     leaderboard()
     top_users = get_leaderboard()
     assert len(top_users) == 20, len(top_users)
 def test_anon_week(self):
     """Test JOB leaderboard returns anon active week runs."""
     users = UserFactory.create_batch(20)
     for user in users:
         TaskRunFactory.create(user=user)
     leaderboard()
     top_users = get_leaderboard()
     assert len(top_users) == 20, len(top_users)
Ejemplo n.º 4
0
 def test_leaderboard_foo_key(self):
     """Test JOB leaderboard returns users for foo key."""
     users = []
     for score in range(1, 11):
         users.append(UserFactory.create(info=dict(foo=score)))
     leaderboard(info='foo')
     top_users = get_leaderboard(info='foo')
     assert len(top_users) == 10, len(top_users)
     score = 10
     for user in top_users:
         user['score'] == score, user
         score = score - 1
 def test_leaderboard_foo_key(self):
     """Test JOB leaderboard returns users for foo key."""
     users = []
     for score in range(1, 11):
         users.append(UserFactory.create(info=dict(foo=score)))
     leaderboard(info='foo')
     top_users = get_leaderboard(info='foo')
     assert len(top_users) == 10, len(top_users)
     score = 10
     for user in top_users:
         user['score'] == score, user
         score = score - 1
Ejemplo n.º 6
0
 def test_leaderboard_foo_key_current_user(self):
     """Test JOB leaderboard returns users for foo key with current user."""
     users = []
     for score in range(1, 11):
         users.append(UserFactory.create(info=dict(foo=score)))
     leaderboard(info='foo')
     top_users = get_leaderboard(user_id=users[0].id, info='foo')
     assert len(top_users) == 11, len(top_users)
     score = 10
     for user in top_users[0:10]:
         user['score'] == score, user
         score = score - 1
     assert top_users[-1]['name'] == users[0].name
     assert top_users[-1]['score'] == users[0].info.get('foo')
 def test_leaderboard_foo_key_current_user(self):
     """Test JOB leaderboard returns users for foo key with current user."""
     users = []
     for score in range(1, 11):
         users.append(UserFactory.create(info=dict(foo=score)))
     leaderboard(info='foo')
     top_users = get_leaderboard(user_id=users[0].id, info='foo')
     assert len(top_users) == 11, len(top_users)
     score = 10
     for user in top_users[0:10]:
         user['score'] == score, user
         score = score - 1
     assert top_users[-1]['name'] == users[0].name
     assert top_users[-1]['score'] == users[0].info.get('foo')
Ejemplo n.º 8
0
    def test_leaderboard_foo_dash_key(self):
        """Test JOB leaderboard returns users for foo-dash key."""
        users = []
        for score in range(1, 11):
            users.append(UserFactory.create(info={'foo-dash': score}))
        users.append(UserFactory.create(restrict=True, info={'foo-dash': 11}))
        leaderboard(info='foo-dash')
        top_users = get_leaderboard(info='foo-dash')
        assert len(top_users) == 10, len(top_users)
        score = 10
        for user in top_users:
            user['score'] == score, user
            score = score - 1

        results = db.session.execute('select * from "users_rank_foo-dash"');
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 9
0
    def test_leaderboard_foo_key(self):
        """Test JOB leaderboard returns users for foo key."""
        users = []
        for score in range(1, 11):
            users.append(UserFactory.create(info=dict(foo=score)))
        users.append(UserFactory.create(restrict=True, info=dict(foo=11)))
        leaderboard(info='foo')
        top_users = get_leaderboard(info='foo')
        assert len(top_users) == 10, len(top_users)
        score = 10
        for user in top_users:
            user['score'] == score, user
            score = score - 1

        results = db.session.execute('select * from users_rank_foo')
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 10
0
    def test_anon_week(self):
        """Test JOB leaderboard returns anon active week runs."""
        db.session.execute('''delete from "user";''')
        from pybossa.core import user_repo
        users = UserFactory.create_batch(20)
        restricted = UserFactory.create(restrict=True)
        users.append(restricted)
        for user in users:
            TaskRunFactory.create(user=user)
        leaderboard()
        top_users = get_leaderboard()
        assert len(top_users) == 20, len(top_users)
        for u in top_users:
            assert u['name'] != restricted.name, u

        results = db.session.execute('select * from users_rank');
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 11
0
    def test_anon_week(self):
        """Test JOB leaderboard returns anon active week runs."""
        db.session.execute('''delete from "user";''')
        from pybossa.core import user_repo
        users = UserFactory.create_batch(20)
        restricted = UserFactory.create(restrict=True)
        users.append(restricted)
        for user in users:
            TaskRunFactory.create(user=user)
        leaderboard()
        top_users = get_leaderboard()
        assert len(top_users) == 20, len(top_users)
        for u in top_users:
            assert u['name'] != restricted.name, u

        results = db.session.execute('select * from users_rank')
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 12
0
    def test_leaderboard_foo_key_current_user_window(self):
        """Test JOB leaderboard returns users for foo key with current user and
        window."""
        UserFactory.create_batch(10, info=dict(n=0))
        UserFactory.create_batch(10, info=dict(n=2))
        users = []
        for score in range(11, 22):
            users.append(UserFactory.create(info=dict(n=score)))
        myself = UserFactory.create(info=dict(n=1))

        leaderboard(info='n')

        top_users = get_leaderboard(user_id=myself.id, info='n', window=5)

        assert len(top_users) == 20 + 5 + 1 + 5, len(top_users)
        assert top_users[25]['name'] == myself.name
        assert top_users[25]['score'] == myself.info.get('n')
        assert top_users[24]['score'] >= myself.info.get('n')
        assert top_users[26]['score'] <= myself.info.get('n')
    def test_leaderboard_foo_key_current_user_window(self):
        """Test JOB leaderboard returns users for foo key with current user and
        window."""
        UserFactory.create_batch(10, info=dict(n=0))
        UserFactory.create_batch(10, info=dict(n=2))
        users = []
        for score in range(11, 22):
            users.append(UserFactory.create(info=dict(n=score)))
        myself = UserFactory.create(info=dict(n=1))

        leaderboard(info='n')

        top_users = get_leaderboard(user_id=myself.id, info='n', window=5)

        assert len(top_users) == 20 + 5 + 1 + 5, len(top_users)
        assert top_users[25]['name'] == myself.name
        assert top_users[25]['score'] == myself.info.get('n')
        assert top_users[24]['score'] >= myself.info.get('n')
        assert top_users[26]['score'] <= myself.info.get('n')
Ejemplo n.º 14
0
    def test_leaderboard_foo_dash_key_current_user(self):
        """Test JOB leaderboard returns users for foo-dash key with current user."""
        users = []
        for score in range(1, 11):
            users.append(UserFactory.create(info={'foo-dash': score}))

        users.append(UserFactory.create(restrict=True, info={'foo-dash': 11}))

        leaderboard(info='foo-dash')
        top_users = get_leaderboard(user_id=users[0].id, info='foo-dash')
        assert len(top_users) == 11, len(top_users)
        score = 10
        for user in top_users[0:10]:
            user['score'] == score, user
            score = score - 1
        assert top_users[-1]['name'] == users[0].name
        assert top_users[-1]['score'] == users[0].info.get('foo-dash')

        results = db.session.execute('select * from "users_rank_foo-dash"');
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 15
0
    def test_leaderboard_foo_key_current_user(self):
        """Test JOB leaderboard returns users for foo key with current user."""
        users = []
        for score in range(1, 11):
            users.append(UserFactory.create(info=dict(foo=score)))

        users.append(UserFactory.create(restrict=True, info=dict(foo=11)))

        leaderboard(info='foo')
        top_users = get_leaderboard(user_id=users[0].id, info='foo')
        assert len(top_users) == 11, len(top_users)
        score = 10
        for user in top_users[0:10]:
            user['score'] == score, user
            score = score - 1
        assert top_users[-1]['name'] == users[0].name
        assert top_users[-1]['score'] == users[0].info.get('foo')

        results = db.session.execute('select * from users_rank_foo')
        for r in results:
            assert r.restrict is False, r
Ejemplo n.º 16
0
    def test_leaderboard_foo_dash_key_current_user_window(self):
        """Test JOB leaderboard returns users for foo-dash key with current user and
        window."""
        UserFactory.create_batch(10, info={'foo-dash': 0})
        UserFactory.create_batch(10, info={'foo-dash': 2})
        UserFactory.create_batch(10, info={'foo-dash': 2}, restrict=True)
        users = []
        for score in range(11, 22):
            users.append(UserFactory.create(info={'foo-dash': score}))
        myself = UserFactory.create(info={'foo-dash': 1})

        leaderboard(info='foo-dash')

        top_users = get_leaderboard(user_id=myself.id, info='foo-dash', window=5)

        assert len(top_users) == 20 + 5 + 1 + 5, len(top_users)
        assert top_users[25]['name'] == myself.name
        assert top_users[25]['score'] == myself.info.get('foo-dash')
        assert top_users[24]['score'] >= myself.info.get('foo-dash')
        assert top_users[26]['score'] <= myself.info.get('foo-dash')

        results = db.session.execute('select * from "users_rank_foo-dash"');
        for r in results:
            assert r.restrict is False, r