Esempio n. 1
0
 def test_compute_draft_order_incorrect_size(self):
     """Tests that an AssertionError is raised when a list of incorrect
 size is passed in."""
     for pool_size in (1, 4, 7, 8, 9, 10):
         user_ids = range(pool_size)
         with self.assertRaises(AssertionError):
             Pool.compute_draft_order(user_ids)
Esempio n. 2
0
    def create_test_pool(self, name=None, max_size=None):
        """Creates a mock Pool object."""
        name = 'My Cool Pool' if name is None else name
        max_size = 5 if max_size is None else max_size

        pool = Pool(name=name, max_size=max_size)
        pool.save()

        return pool
Esempio n. 3
0
    def test_compute_draft_order_size_three(self):
        """Tests the expected draft order with three users."""
        user_ids = [10001, 20002, 30003]
        user_ids_by_draft_order = Pool.compute_draft_order(user_ids)

        # -1. Sanity check the dictionary passed back.
        self._sanity_check_draft_order_dict(user_ids, user_ids_by_draft_order)

        # 0. Verify the expected draft order for each user.
        self._verify_expected_draft_order(
            user_ids_by_draft_order, 1, [1, 6, 8, 12, 13, 18, 19, 24, 26, 30])
        self._verify_expected_draft_order(
            user_ids_by_draft_order, 2, [2, 5, 7, 11, 14, 17, 20, 23, 25, 29])
        self._verify_expected_draft_order(
            user_ids_by_draft_order, 3, [3, 4, 9, 10, 15, 16, 21, 22, 27, 28])
Esempio n. 4
0
    def test_compute_draft_order_size_six(self):
        """Tests the expected draft order with six users."""
        user_ids = [10001, 20002, 30003, 40004, 50005, 60006]
        user_ids_by_draft_order = Pool.compute_draft_order(user_ids)

        # -1. Sanity check the dictionary passed back.
        self._sanity_check_draft_order_dict(user_ids, user_ids_by_draft_order)

        # 0. Verify the expected draft order for each user.
        self._verify_expected_draft_order(user_ids_by_draft_order, 1,
                                          [1, 12, 18, 24, 30])
        self._verify_expected_draft_order(user_ids_by_draft_order, 2,
                                          [2, 11, 14, 22, 29])
        self._verify_expected_draft_order(user_ids_by_draft_order, 3,
                                          [3, 10, 16, 23, 28])
        self._verify_expected_draft_order(user_ids_by_draft_order, 4,
                                          [4, 9, 15, 21, 27])
        self._verify_expected_draft_order(user_ids_by_draft_order, 5,
                                          [5, 8, 13, 19, 26])
Esempio n. 5
0
    def update_from_data(pool_id, pool_member_data):
        """
    Adds a new member whose username is in `pool_data`.

    Args:
      pool_id: The pool id of an existing pool
      pool_data: Expected to be in the format:
        {"username": <username of new member>}

    Raises:
      User.DoesNotExist: If the user within `pool_data` doesn't exist.
      Pool.DoesNotExist: If the pool doesn't exist.
      TooManyMembersException: If we attempt to add more users than the pool
        can handle.
    """
        # 0. Validate the `pool_data` and `pool_id`.
        assert pool_id.isdigit()
        assert "username" in pool_member_data
        member_username = pool_member_data["username"]
        pool_id = long(pool_id)

        # 1. Validate that a user exists with `member_username`
        user = User.objects.get(username=member_username)
        if not user:
            raise User.DoesNotExist()

        # 2. Attempt to fetch the Pool.
        pool = Pool.objects.get(id=pool_id)
        if not pool:
            raise Pool.DoesNotExist()

        logger.info('pool: %s' % pool)
        # 3. Add the new member to the pool.
        pool.add_member(user)

        logger.info('pool after adding member: %s' % pool.members.all())

        return pool.members.all()