Skip to content
Permalink
Browse files

Move some tests to doctests.

  • Loading branch information...
dukebody committed May 21, 2011
1 parent 63daa28 commit 40e25697521bfe5fea08def1d6d3acd3f59f294d
Showing with 153 additions and 89 deletions.
  1. +150 −0 collective/libreorganizacion/test_workflow.txt
  2. +3 −89 collective/libreorganizacion/tests.py
@@ -0,0 +1,150 @@
Proposal workflow
====================

This doctest describes the common workflow of a proposal, from its
creation to its archive, including its promotion to plenary and voting.

The graph is as follows:
'Draft' → 'Pending',
'Pending' → 'Plenary',
'Plenary' → 'Voting',
'Voting' → 'Archived'.


Let's get to work. First, we set up the machinery:

>>> from plone.app.testing import setRoles, login, TEST_USER_NAME
>>> portal = layer['portal']
>>> wt = portal.portal_workflow
>>> setRoles(portal, TEST_USER_NAME, ['Manager', 'Member'])
>>> login(portal, TEST_USER_NAME)
>>> def getPermissions(obj, role):
... return [p['name'] for p in obj.permissionsOfRole(role) if p['selected']]

A proposal is a certain topic to be discussed within the
organization. Let's create one:

>>> dummy = layer['folder'].invokeFactory('collective.libreorganizacion.proposal', 'proposal')
>>> proposal = layer['folder']['proposal']

The proposal starts as a draft, only visible by its creator:

>>> wt.getInfoFor(proposal, 'review_state')
'draft'
>>> 'View' in getPermissions(proposal, 'Anonymous')
False


In this state, Electors can't comment:

>>> 'Reply to item' in getPermissions(proposal, 'Elector')
False

The creator can edit it, but not the rest of the electors:

>>> 'Modify portal content' in getPermissions(proposal, 'Owner')
True
>>> 'Modify portal content' in getPermissions(proposal, 'Elector')
False


Once the creator decides that the proposal is ready, she/he publishes it:

>>> wt.doActionFor(proposal, 'submit')

It now becomes visible to everyone, but can't be modified anymore by
its owner:

>>> 'View' in getPermissions(proposal, 'Anonymous')
True
>>> 'Modify portal content' in getPermissions(proposal, 'Owner')
False

Before the proposal is accepted for debate and it must receive enough support from
the electors. The supporting is managed through a plone.contentratings
category, and only Electors can show support:

>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Elector')
True
>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Reader')
False
>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Editor')
False
>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Reviewer')
False

Also, Electors can now comment on the proposal to argue about why it
should be supported or not:

>>> 'Reply to item' in getPermissions(proposal, 'Elector')
True


Once the proposal gets enough upvotes, it is promoted to Plenary for
everyone to debate about it before the voting starts:

>>> wt.doActionFor(proposal, 'promote')

In this state, showing support is no longer allowed, since it's
already in the Plenary:

>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Elector')
False

But we can still comment and debate of course:

>>> 'Reply to item' in getPermissions(proposal, 'Elector')
True

After a while, the debate is over and we decide to vote:

>>> wt.doActionFor(proposal, 'start_voting')
>>> 'Reply to item' in getPermissions(proposal, 'Elector')
False
>>> 'Popoll: Vote' in getPermissions(proposal, 'Elector')
True


The proposal can't be supported or modified while voting:

>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Elector')
False
>>> 'Modify portal content' in getPermissions(proposal, 'Owner')
False
>>> 'Modify portal content' in getPermissions(proposal, 'Elector')
False


Voting is finished! We can't vote anymore:

>>> wt.doActionFor(proposal, 'archive')
>>> 'Popoll: Vote' in getPermissions(proposal, 'Elector')
False

But the proposal remains visible:
>>> 'View' in getPermissions(proposal, 'Anonymous')
True



Not so popular proposals
-------------------------

Some proposals don't gain enough support and they never reach the Plenary.

>>> dummy = layer['folder'].invokeFactory('collective.libreorganizacion.proposal', 'proposal2')
>>> proposal = layer['folder']['proposal2']

>>> wt.doActionFor(proposal, 'submit')
>>> wt.doActionFor(proposal, 'expire')

The proposal remains visible:
>>> 'View' in getPermissions(proposal, 'Anonymous')
True

But it can't be supported after expired, nor can we discuss about it:
>>> 'Content Ratings: User Rate' in getPermissions(proposal, 'Elector')
False
>>> 'Reply to item' in getPermissions(proposal, 'Elector')
False

@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-

import unittest2 as unittest
import doctest

from AccessControl import Unauthorized

from plone.testing import z2
from plone.testing import layered
from plone.app.testing.layers import IntegrationTesting
from plone.app.testing.layers import FunctionalTesting
from plone.app.testing import PLONE_FIXTURE
@@ -117,98 +119,10 @@ def testNonElectorsCantCommentOnProposals(self):
portal = self.layer['portal']
self.assertFalse('Reply to item' in self.getPermissions(portal, 'Member'))

def testProposalWorkflowChain(self):
"""Check the whole Proposal workflow chain for a proposal
that gets to plenary.
"""

portal = self.layer['portal']
wt = portal.portal_workflow

setRoles(portal, TEST_USER_NAME, ['Manager', 'Member'])
login(portal, TEST_USER_NAME)
self.layer['folder'].invokeFactory('collective.libreorganizacion.proposal', 'proposal')
proposal = self.layer['folder']['proposal']

# It starts as a draft
self.assertEqual(wt.getInfoFor(proposal, 'review_state'), 'draft')
# In this state, Electors can't comment
self.assertFalse('Reply to item' in self.getPermissions(proposal, 'Elector'))
# and noone else can see the item
self.assertFalse('View' in self.getPermissions(proposal, 'Anonymous'))
# The creator can edit it, but not the rest of electors
self.assertTrue('Modify portal content' in self.getPermissions(proposal, 'Owner'))
self.assertFalse('Modify portal content' in self.getPermissions(proposal, 'Elector'))

# After submitting, the proposal becomes visible
wt.doActionFor(proposal, 'submit')
self.assertTrue('View' in self.getPermissions(proposal, 'Anonymous'))
# and can be supported by electors, but not by other users
self.assertTrue('Content Ratings: User Rate' in self.getPermissions(proposal, 'Elector'))
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Reader'))
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Editor'))
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Reviewer'))
# It's no longer editable by its owner
self.assertFalse('Modify portal content' in self.getPermissions(proposal, 'Owner'))
# Comments are enabled now for electors
self.assertTrue('Reply to item' in self.getPermissions(proposal, 'Elector'))


# Once the proposal gets enough upvotes, it is promoted to plenary.
wt.doActionFor(proposal, 'promote')
# In this state, supporting votes are no longer allowed
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Elector'))
# but we can still comment
self.assertTrue('Reply to item' in self.getPermissions(proposal, 'Elector'))


# Voting is started! No more bla bla
wt.doActionFor(proposal, 'start_voting')
self.assertFalse('Reply to item' in self.getPermissions(proposal, 'Elector'))
# nor can we support the proposal
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Elector'))
# or edit it
self.assertFalse('Modify portal content' in self.getPermissions(proposal, 'Owner'))
self.assertFalse('Modify portal content' in self.getPermissions(proposal, 'Elector'))

# but we can vote, of course
self.assertTrue('Popoll: Vote' in self.getPermissions(proposal, 'Elector'))


# Voting is finished! We can't vote anymore
wt.doActionFor(proposal, 'archive')
self.assertFalse('Popoll: Vote' in self.getPermissions(proposal, 'Elector'))
# but the proposal remains visible
self.assertTrue('View' in self.getPermissions(proposal, 'Anonymous'))


def testProposalExpired(self):
"""Check the Proposal workflow chain expired state
for a proposal that doesn't get enough support and expires.
"""

portal = self.layer['portal']
wt = portal.portal_workflow

setRoles(portal, TEST_USER_NAME, ['Manager', 'Member'])
login(portal, TEST_USER_NAME)
self.layer['folder'].invokeFactory('collective.libreorganizacion.proposal', 'proposal')
proposal = self.layer['folder']['proposal']

wt.doActionFor(proposal, 'submit')
wt.doActionFor(proposal, 'expire')

# The proposal remains visible
self.assertTrue('View' in self.getPermissions(proposal, 'Anonymous'))
# But it can't be supported
self.assertFalse('Content Ratings: User Rate' in self.getPermissions(proposal, 'Elector'))

# And we can't discuss about it
self.assertFalse('Reply to item' in self.getPermissions(proposal, 'Elector'))


def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(TestProductInstall))
suite.addTest(layered(doctest.DocFileSuite('test_workflow.txt'), LIBREORGANIZACION_INTEGRATION_TESTING))
return suite

0 comments on commit 40e2569

Please sign in to comment.
You can’t perform that action at this time.