def test_queries(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        d1to2 = Delegation(user1, user2, proposal)
        model.meta.Session.add(d1to2)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        self.assertEqual(len(dn.outbound()), 1)

        dn = DelegationNode(user1, proposal)
        self.assertEqual(len(dn.outbound()), 1)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()), 1)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()), 1)

        d3to2 = Delegation(user3, user2, proposal)
        model.meta.Session.add(d3to2)
        model.meta.Session.flush()

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()), 2)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound(recurse=False)), 2)
    def test_propagate(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()
        user4 = tt_make_user()
        userA = tt_make_user()

        d2to1 = Delegation(user2, user1, proposal)
        model.meta.Session.add(d2to1)

        dAto1 = Delegation(userA, user1, proposal)
        model.meta.Session.add(dAto1)

        d3to2 = Delegation(user3, user2, proposal)
        model.meta.Session.add(d3to2)

        d4to3 = Delegation(user4, user3, proposal)
        model.meta.Session.add(d4to3)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 2

        def inp(user, deleg, edge):
            return "foo"

        assert len(dn.propagate(inp)) == 5
Esempio n. 3
0
 def setUp(self):
     super(TestInteractionOfDelegationOnDifferentLevels, self).setUp()
     voter_group = Group.by_code(Group.CODE_VOTER)
     self.me = tt_make_user(instance_group=voter_group)
     self.first = tt_make_user(instance_group=voter_group)
     self.second = tt_make_user(instance_group=voter_group)
     self.proposal = tt_make_proposal(voting=True)
    def test_queries(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        d1to2 = Delegation(user1, user2, proposal)
        model.meta.Session.add(d1to2)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        self.assertEqual(len(dn.outbound()), 1)

        dn = DelegationNode(user1, proposal)
        self.assertEqual(len(dn.outbound()),  1)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()),  1)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()),  1)

        d3to2 = Delegation(user3, user2, proposal)
        model.meta.Session.add(d3to2)
        model.meta.Session.flush()

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound()),  2)

        dn = DelegationNode(user2, proposal)
        self.assertEqual(len(dn.inbound(recurse=False)), 2)
 def setUp(self):
     super(TestInteractionOfDelegationOnDifferentLevels, self).setUp()
     voter_group = Group.by_code(Group.CODE_VOTER)
     self.me = tt_make_user(instance_group=voter_group)
     self.first = tt_make_user(instance_group=voter_group)
     self.second = tt_make_user(instance_group=voter_group)
     self.proposal = tt_make_proposal(voting=True)
    def test_propagate(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()
        user4 = tt_make_user()
        userA = tt_make_user()

        d2to1 = Delegation(user2, user1, proposal)
        model.meta.Session.add(d2to1)

        dAto1 = Delegation(userA, user1, proposal)
        model.meta.Session.add(dAto1)

        d3to2 = Delegation(user3, user2, proposal)
        model.meta.Session.add(d3to2)

        d4to3 = Delegation(user4, user3, proposal)
        model.meta.Session.add(d4to3)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 2

        def inp(user, deleg, edge):
            return "foo"
        assert len(dn.propagate(inp)) == 5
 def setUp(self):
     self.me = tt_make_user()
     self.first = tt_make_user()
     self.second = tt_make_user()
     self.proposal = tt_make_proposal(voting=True)
     self.poll = Poll.create(self.proposal, self.proposal.creator,
                             Poll.ADOPT)
     self.instance = tt_get_instance()
Esempio n. 8
0
    def test_login_redirect(self):
        from adhocracy.lib.helpers import login_redirect_url

        proposal = tt_make_proposal(title=u'testproposal')
        url = login_redirect_url(proposal)
        expected = (u'http://test.test.lan/login?came_from='
                    u'http%3A%2F%2Ftest.test.lan%2Fproposal%2F2-testproposal')
        self.assertEqual(url, expected)
 def setUp(self):
     self.me = tt_make_user()
     self.first = tt_make_user()
     self.second = tt_make_user()
     self.proposal = tt_make_proposal(voting=True)
     self.poll = Poll.create(self.proposal, self.proposal.creator,
                             Poll.ADOPT)
     self.instance = tt_get_instance()
Esempio n. 10
0
    def test_login_redirect(self):
        from adhocracy.lib.helpers import login_redirect_url

        proposal = tt_make_proposal(title=u'testproposal')
        url = login_redirect_url(proposal)
        expected = (u'http://test.test.lan/login?came_from='
                    u'http%3A%2F%2Ftest.test.lan%2Fproposal%2F2-testproposal')
        self.assertEqual(url, expected)
Esempio n. 11
0
    def test_can_delegate_via_forward_on_user(self):

        proposal = tt_make_proposal(voting=True)

        voter_group = Group.by_code(Group.CODE_VOTER)
        me = tt_make_user(instance_group=voter_group)
        delegate = tt_make_user(instance_group=voter_group)

        Delegation.create(me, delegate, proposal)
        self.assertEqual(delegate.number_of_votes_in_scope(proposal), 2)
Esempio n. 12
0
    def test_can_delegate_via_forward_on_user(self):

        proposal = tt_make_proposal(voting=True)

        voter_group = Group.by_code(Group.CODE_VOTER)
        me = tt_make_user(instance_group=voter_group)
        delegate = tt_make_user(instance_group=voter_group)

        Delegation.create(me, delegate, proposal)
        self.assertEqual(delegate.number_of_votes_in_scope(proposal), 2)
Esempio n. 13
0
    def setUp(self):
        self.me = tt_make_user(name='me')
        self.high_delegate = tt_make_user(name='high_delegate')
        self.low_delegate = tt_make_user(name='low_delegate')

        self.proposal = tt_make_proposal(creator=self.me, voting=True)
        self.poll = Poll.create(self.proposal, self.proposal.creator,
                                Poll.ADOPT)
        self.decision = Decision(self.me, self.poll)
        self.instance = tt_get_instance()
Esempio n. 14
0
 def test_vote_by_creator(self):
     from adhocracy.lib.democracy import Decision
     proposal = tt_make_proposal(voting=True)
     poll = proposal.polls[0]
     self.assertEqual(0, len(list(poll.votes)))
     decision = Decision(proposal.creator, poll)
     votes = decision.make(Vote.YES)
     self.assertEqual(len(votes), 1)
     self.assertEqual(len(decision.votes), 1)
     self.assertEqual(votes[0].orientation, Vote.YES)
     self.assertEqual(votes[0].user, proposal.creator)
Esempio n. 15
0
 def test_vote_by_creator(self):
     from adhocracy.lib.democracy import Decision
     proposal = tt_make_proposal(voting=True)
     poll = proposal.polls[0]
     self.assertEqual(0, len(list(poll.votes)))
     decision = Decision(proposal.creator, poll)
     votes = decision.make(Vote.YES)
     self.assertEqual(len(votes), 1)
     self.assertEqual(len(decision.votes), 1)
     self.assertEqual(votes[0].orientation, Vote.YES)
     self.assertEqual(votes[0].user, proposal.creator)
Esempio n. 16
0
    def setUp(self):
        super(TestDecisionWithDelegation, self).setUp()
        self.me = tt_make_user(name='me')
        self.high_delegate = tt_make_user(name='high_delegate')
        self.low_delegate = tt_make_user(name='low_delegate')

        self.proposal = tt_make_proposal(creator=self.me, voting=True)
        self.poll = Poll.create(self.proposal, self.proposal.creator,
                                Poll.ADOPT)
        self.decision = Decision(self.me, self.poll)
        self.instance = tt_get_instance()
Esempio n. 17
0
 def test_export_proposal(self):
     p = testtools.tt_make_proposal(creator=self.u1)
     e = importexport.export_data(
         {u"include_instance": True, u"include_instance_proposal": True, u"include_users": True}
     )
     idata = e[u"instance"][p.instance.key]
     self.assertTrue(u"proposals" in idata)
     pdata = idata[u"proposals"][str(p.id)]
     assert u"comments" not in pdata
     self.assertEqual(pdata[u"title"], p.title)
     self.assertEqual(pdata[u"description"], p.description)
     self.assertEqual(pdata[u"adhocracy_type"], u"proposal")
Esempio n. 18
0
    def test_vote_by_other_user(self):
        from adhocracy.lib.democracy import Decision
        proposal = tt_make_proposal(voting=True)
        poll = proposal.polls[0]
        self.assertEqual(0, len(list(poll.votes)))

        # make a new user and let him vote
        new_user = tt_make_user()
        decision = Decision(new_user, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 1)
        self.assertEqual(len(poll.votes), 1)
        self.assertEqual(votes[0].orientation, Vote.YES)
Esempio n. 19
0
    def test_vote_by_other_user(self):
        from adhocracy.lib.democracy import Decision
        proposal = tt_make_proposal(voting=True)
        poll = proposal.polls[0]
        self.assertEqual(0, len(list(poll.votes)))

        # make a new user and let him vote
        new_user = tt_make_user()
        decision = Decision(new_user, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 1)
        self.assertEqual(len(poll.votes), 1)
        self.assertEqual(votes[0].orientation, Vote.YES)
Esempio n. 20
0
 def test_export_proposal(self):
     p = testtools.tt_make_proposal(creator=self.u1)
     e = importexport.export_data({
         u"include_instance": True,
         u"include_instance_proposal": True,
         u"include_users": True,
     })
     idata = e[u'instance'][p.instance.key]
     self.assertTrue(u'proposals' in idata)
     pdata = idata[u'proposals'][str(p.id)]
     assert u'comments' not in pdata
     self.assertEqual(pdata[u'title'], p.title)
     self.assertEqual(pdata[u'description'], p.description)
     self.assertEqual(pdata[u'adhocracy_type'], u'proposal')
Esempio n. 21
0
    def test_second_identical_vote(self):
        from adhocracy.lib.democracy import Decision
        proposal = tt_make_proposal(voting=True)
        poll = proposal.polls[0]
        self.assertEqual(0, len(list(poll.votes)))
        decision = Decision(proposal.creator, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 1)
        self.assertEqual(len(poll.votes), 1)

        # a second, identical vote by the same user
        decision = Decision(proposal.creator, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 2)
        self.assertEqual(len(poll.votes), 2)
Esempio n. 22
0
    def test_second_identical_vote(self):
        from adhocracy.lib.democracy import Decision
        proposal = tt_make_proposal(voting=True)
        poll = proposal.polls[0]
        self.assertEqual(0, len(list(poll.votes)))
        decision = Decision(proposal.creator, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 1)
        self.assertEqual(len(poll.votes), 1)

        # a second, identical vote by the same user
        decision = Decision(proposal.creator, poll)
        votes = decision.make(Vote.YES)
        self.assertEqual(len(votes), 1)
        self.assertEqual(len(decision.votes), 2)
        self.assertEqual(len(poll.votes), 2)
    def test_filter(self):
        # FIXME: refactor this test. we don't have issues anymore
        return
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        small = Delegation(user1, user2, proposal)
        model.meta.Session.add(small)

        large = Delegation(user1, user3, proposal.issue)
        model.meta.Session.add(large)
        model.meta.Session.flush()

        res = DelegationNode.filter_less_specific_delegations([small, large])
        assert small in res
        assert large not in res
    def test_filter(self):
        # FIXME: refactor this test. we don't have issues anymore
        return
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        small = Delegation(user1, user2, proposal)
        model.meta.Session.add(small)

        large = Delegation(user1, user3, proposal.issue)
        model.meta.Session.add(large)
        model.meta.Session.flush()

        res = DelegationNode.filter_less_specific_delegations([small, large])
        assert small in res
        assert large not in res
Esempio n. 25
0
    def test_export_comments(self):
        p = testtools.tt_make_proposal(creator=self.u1, with_description=True)
        desc1 = testtools.tt_make_str()
        desc2 = testtools.tt_make_str()
        c1 = model.Comment.create(
            text=desc1,
            user=self.u1,
            topic=p.description,
            reply=None,
            variant=u'HEAD',
            sentiment=1)
        c2 = model.Comment.create(
            text=desc2,
            user=self.u2,
            topic=p.description,
            reply=c1,
            variant=u'HEAD',
            sentiment=-1)
        assert p.description.comments

        e = importexport.export_data({
            "include_instance": True,
            "include_instance_proposal": True,
            "include_instance_proposal_comment": True,
            "include_users": True,
        })
        idata = e[u'instance'][p.instance.key]
        pdata = idata[u'proposals'][str(p.id)]
        assert u'comments' in pdata

        self.assertEqual(len(pdata[u'comments']), 1)
        cdata = next(iter(pdata[u'comments'].values()))
        self.assertEqual(cdata[u'text'], desc1)
        self.assertEqual(cdata[u'creator'], str(self.u1.id))
        self.assertEqual(cdata[u'sentiment'], 1)
        self.assertEqual(cdata[u'adhocracy_type'], u'comment')

        self.assertEqual(len(cdata[u'comments']), 1)
        cdata2 = next(iter(cdata[u'comments'].values()))
        self.assertEqual(cdata2[u'text'], desc2)
        self.assertEqual(cdata2[u'creator'], str(self.u2.id))
        self.assertEqual(cdata2[u'sentiment'], -1)
        self.assertEqual(cdata2[u'adhocracy_type'], u'comment')
    def test_detach(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        d2to1 = Delegation(user2, user1, proposal)
        model.meta.Session.add(d2to1)

        d3to1 = Delegation(user3, user1, proposal)
        model.meta.Session.add(d3to1)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 2

        user1.revoke_delegations(tt_get_instance())

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 0
    def test_detach(self):
        proposal = tt_make_proposal(voting=True)
        user1 = tt_make_user()
        user2 = tt_make_user()
        user3 = tt_make_user()

        d2to1 = Delegation(user2, user1, proposal)
        model.meta.Session.add(d2to1)

        d3to1 = Delegation(user3, user1, proposal)
        model.meta.Session.add(d3to1)
        model.meta.Session.flush()

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 2

        user1.revoke_delegations(tt_get_instance())

        dn = DelegationNode(user1, proposal)
        assert len(dn.inbound()) == 0
Esempio n. 28
0
    def test_export_comments(self):
        p = testtools.tt_make_proposal(creator=self.u1, with_description=True)
        desc1 = testtools.tt_make_str()
        desc2 = testtools.tt_make_str()
        c1 = model.Comment.create(
            text=desc1, user=self.u1, topic=p.description, reply=None, variant=u"HEAD", sentiment=1
        )
        c2 = model.Comment.create(
            text=desc2, user=self.u2, topic=p.description, reply=c1, variant=u"HEAD", sentiment=-1
        )
        assert p.description.comments

        e = importexport.export_data(
            {
                "include_instance": True,
                "include_instance_proposal": True,
                "include_instance_proposal_comment": True,
                "include_users": True,
            }
        )
        idata = e[u"instance"][p.instance.key]
        pdata = idata[u"proposals"][str(p.id)]
        assert u"comments" in pdata

        self.assertEqual(len(pdata[u"comments"]), 1)
        cdata = next(iter(pdata[u"comments"].values()))
        self.assertEqual(cdata[u"text"], desc1)
        self.assertEqual(cdata[u"creator"], str(self.u1.id))
        self.assertEqual(cdata[u"sentiment"], 1)
        self.assertEqual(cdata[u"adhocracy_type"], u"comment")

        self.assertEqual(len(cdata[u"comments"]), 1)
        cdata2 = next(iter(cdata[u"comments"].values()))
        self.assertEqual(cdata2[u"text"], desc2)
        self.assertEqual(cdata2[u"creator"], str(self.u2.id))
        self.assertEqual(cdata2[u"sentiment"], -1)
        self.assertEqual(cdata2[u"adhocracy_type"], u"comment")
Esempio n. 29
0
 def _make_proposal(self, voting=False):
     creator = tt_make_user('creator')
     proposal = tt_make_proposal(creator=creator, voting=voting)
     return (proposal, creator)
 def test_if_proposal_has_no_poll_no_direct_vote_overides_delegations(self):
     proposal_without_poll = tt_make_proposal()
     self._do_delegate(self.first, self.second, proposal_without_poll)
     node = DelegationNode(self.second, proposal_without_poll)
     self.assertEqual(node.number_of_delegations(), 1)
Esempio n. 31
0
 def test_begin_end(self):
     proposal = tt_make_proposal(voting=False)
     poll = Poll.create(proposal, proposal.creator, Poll.ADOPT)
     poll.end()
     self.assertTrue(poll.has_ended())
 def test_if_proposal_has_no_poll_no_direct_vote_overides_delegations(self):
     proposal_without_poll = tt_make_proposal()
     self._do_delegate(self.first, self.second,
                                          proposal_without_poll)
     node = DelegationNode(self.second, proposal_without_poll)
     self.assertEqual(node.number_of_delegations(), 1)
Esempio n. 33
0
 def setUp(self):
     super(TestDecisionWithoutDelegation, self).setUp()
     self.proposal = tt_make_proposal(voting=True)
     self.poll = Poll.create(self.proposal, self.proposal.creator,
                             Poll.ADOPT)
     self.decision = Decision(self.proposal.creator, self.poll)
 def setUp(self):
     voter_group = Group.by_code(Group.CODE_VOTER)
     self.me = tt_make_user(instance_group=voter_group)
     self.first = tt_make_user(instance_group=voter_group)
     self.second = tt_make_user(instance_group=voter_group)
     self.proposal = tt_make_proposal(voting=True)
Esempio n. 35
0
 def setUp(self):
     super(TestDecisionWithoutDelegation, self).setUp()
     self.proposal = tt_make_proposal(voting=True)
     self.poll = Poll.create(self.proposal, self.proposal.creator,
                             Poll.ADOPT)
     self.decision = Decision(self.proposal.creator, self.poll)
Esempio n. 36
0
 def test_begin_end(self):
     proposal = tt_make_proposal(voting=False)
     poll = Poll.create(proposal, proposal.creator, Poll.ADOPT)
     poll.end()
     self.assertTrue(poll.has_ended())
 def setUp(self):
     voter_group = Group.by_code(Group.CODE_VOTER)
     self.me = tt_make_user(instance_group=voter_group)
     self.first = tt_make_user(instance_group=voter_group)
     self.second = tt_make_user(instance_group=voter_group)
     self.proposal = tt_make_proposal(voting=True)
Esempio n. 38
0
 def _make_proposal(self, voting=False):
     creator = tt_make_user('creator')
     proposal = tt_make_proposal(creator=creator, voting=voting)
     return (proposal, creator)
Esempio n. 39
0
 def setUp(self):
     self.proposal = tt_make_proposal(voting=True)
     self.poll = Poll.create(self.proposal, self.proposal.creator,
                             Poll.ADOPT)
     self.decision = Decision(self.proposal.creator, self.poll)