コード例 #1
0
    def test_assignment(self):
        b = UserBadge.create(u'all users - ' + tt_make_str(), u'', False, u'')

        t = Treatment.create(tt_make_str(), source_badges=[b], variant_count=2)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) == 0
        assert len(ass2) == 0
        assert len(unassigned) == 0

        first_users = [tt_make_user() for _ in range(5)]
        for u in first_users:
            b.assign(u, u)
        # sanity check
        assert set(u.id for u in b.users) == set(u.id for u in first_users)

        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) == 0
        assert len(ass2) == 0
        assert len(unassigned) == len(first_users)

        assert assign_users(t)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users)
        assert (len(ass1) == len(ass2) - 1) or (len(ass1) == len(ass2) + 1)
        assert len(unassigned) == 0

        assert not assign_users(t)

        new_users = [tt_make_user() for _ in range(5)]
        for u in new_users:
            b.assign(u, u)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users)
        assert (len(ass1) == len(ass2) - 1) or (len(ass1) == len(ass2) + 1)
        assert len(unassigned) == len(new_users)

        assert assign_users(t)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users) + len(new_users)

        # The following assert is disabled as it fails non-deterministically
        # (see #601). It can be reenabled once this issue is fixed.

        #assert len(ass1) == len(ass2)

        assert len(unassigned) == 0

        assert not assign_users(t)
コード例 #2
0
ファイル: test_treatment.py プロジェクト: alkadis/vcv
    def test_assignment(self):
        b = UserBadge.create(u'all users - ' + tt_make_str(), u'', False, u'')

        t = Treatment.create(tt_make_str(), source_badges=[b], variant_count=2)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) == 0
        assert len(ass2) == 0
        assert len(unassigned) == 0

        first_users = [tt_make_user() for _ in range(5)]
        for u in first_users:
            b.assign(u, u)
        # sanity check
        assert set(u.id for u in b.users) == set(u.id for u in first_users)

        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) == 0
        assert len(ass2) == 0
        assert len(unassigned) == len(first_users)

        assert assign_users(t)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users)
        assert (len(ass1) == len(ass2) - 1) or (len(ass1) == len(ass2) + 1)
        assert len(unassigned) == 0

        assert not assign_users(t)

        new_users = [tt_make_user() for _ in range(5)]
        for u in new_users:
            b.assign(u, u)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users)
        assert (len(ass1) == len(ass2) - 1) or (len(ass1) == len(ass2) + 1)
        assert len(unassigned) == len(new_users)

        assert assign_users(t)
        sb, assignments, unassigned = get_assignments_by_source_badge(t)[0]
        assert sb == b
        ass1, ass2 = assignments
        assert len(ass1) + len(ass2) == len(first_users) + len(new_users)

        # The following assert is disabled as it fails non-deterministically
        # (see #601). It can be reenabled once this issue is fixed.

        # assert len(ass1) == len(ass2)

        assert len(unassigned) == 0

        assert not assign_users(t)
コード例 #3
0
ファイル: treatment.py プロジェクト: alkadis/vcv
    def assign(self, key):
        treatment = model.Treatment.find(key)
        if not treatment:
            return ret_abort(_("Could not find the entity '%s'") % id,
                             code=404)

        if assign_users(treatment):
            model.meta.Session.commit()

            h.flash(_("All users have been assigned to their respective "
                      "treatment badges."), 'success')
        else:
            h.flash(_("All users are already assigned to their respective "
                      "treatment badges."))
        return redirect(h.base_url('/admin/treatment/'))
コード例 #4
0
    def assign(self, key):
        treatment = model.Treatment.find(key)
        if not treatment:
            return ret_abort(_("Could not find the entity '%s'") % id,
                             code=404)

        if assign_users(treatment):
            model.meta.Session.commit()

            h.flash(
                _("All users have been assigned to their respective "
                  "treatment badges."), 'success')
        else:
            h.flash(
                _("All users are already assigned to their respective "
                  "treatment badges."))
        return redirect(h.base_url('/admin/treatment/'))