示例#1
0
 def test_is_in_state_unvalid_names(self):
     with self.statefull_stuff() as (req, wf_entity, rset, adapter):
         selector = is_in_state("unknown")
         with self.assertRaises(ValueError) as cm:
             selector(None, req, rset=rset)
         self.assertEqual(str(cm.exception),
                          "wf_test: unknown state(s): unknown")
         selector = is_in_state("weird", "unknown", "created", "weird")
         with self.assertRaises(ValueError) as cm:
             selector(None, req, rset=rset)
         self.assertEqual(str(cm.exception),
                          "wf_test: unknown state(s): unknown,weird")
示例#2
0
class ExpenseAcceptedView(notification.StatusChangeMixIn,
                          notification.NotificationView):
    __select__ = is_instance('Expense') & is_in_state('accepted')
    content = _("""
The expense ``%(title)s`` has been accepted :

Description
-----------
%(description)s

Detail
-----
%(detail)s

URL
---
%(url)s
""")

    def subject(self):
        entity = self.cw_rset.get_entity(0, 0)
        return u'%s %s' % (self._cw._('expense accepted: '), entity.title)

    def context(self, **kwargs):
        context = super(ExpenseAcceptedView, self).context(**kwargs)
        entity = self.cw_rset.complete_entity(0, 0)
        description = entity.printable_value('description', format='text/plain')
        description = normalize_text(description, 80)
        detail = u'\n'.join(line.view('textoutofcontext') for line in entity.has_lines)
        context.update({'description': description,
                        'title': entity.title,
                        'url': entity.absolute_url(),
                        'detail': detail, })
        return context
示例#3
0
    def test_is_in_state(self):
        with self.statefull_stuff() as (req, wf_entity, rset, adapter):
            for state in ('created', 'validated', 'abandoned'):
                selector = is_in_state(state)
                self.assertEqual(selector(None, req, rset=rset),
                                 state == "created")

            adapter.fire_transition('validate')
            req.cnx.commit()
            wf_entity.cw_clear_all_caches()
            self.assertEqual(adapter.state, 'validated')

            clear_cache(rset, 'get_entity')

            selector = is_in_state('created')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated')
            self.assertEqual(selector(None, req, rset=rset), 1)
            selector = is_in_state('validated', 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)
            selector = is_in_state('abandoned')
            self.assertEqual(selector(None, req, rset=rset), 0)

            adapter.fire_transition('forsake')
            req.cnx.commit()
            wf_entity.cw_clear_all_caches()
            self.assertEqual(adapter.state, 'abandoned')

            clear_cache(rset, 'get_entity')

            selector = is_in_state('created')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated', 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)
            self.assertEqual(adapter.state, 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)