Skip to content

Commit

Permalink
collective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriyanshagro committed Jul 11, 2018
1 parent 2729d48 commit b658d12
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 27 deletions.
70 changes: 70 additions & 0 deletions src/collective/ifttt/tests/test_content_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
from collective.ifttt.actions.ifttt import PAYLOAD_DESCRIPTION
from collective.ifttt.testing import COLLECTIVE_IFTTT_INTEGRATION_TESTING
from plone.app.contentrules.conditions.wfstate import WorkflowStateCondition
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.contentrules.engine.interfaces import IRuleStorage
from Products.CMFCore.interfaces._events import IActionSucceededEvent
from zope.component import getMultiAdapter
from zope.component import getUtility

import unittest


class TestActionMenu(unittest.TestCase):
layer = COLLECTIVE_IFTTT_INTEGRATION_TESTING

def setUp(self):

self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.request = self.layer['request']

def test_view(self):
# Check existence of IFTTT Action Menu

self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_content_trigger')
actions_view = self.view()
self.assertIn('including the description of content', actions_view)

def test_add(self):

self.request.method = 'POST'
self.request.form['form.widgets.ifttt_event_name'] = 'Test'
self.request.form['form.widgets.content_types'] = [
'Document', 'News Item'
]
self.request.form['form.widgets.workflow_transitions'] = [
'publish', 'reject'
]
self.request.form['form.buttons.add'] = u'Add'
self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_content_trigger')
self.view()

storage = getUtility(IRuleStorage)

# check that rule has been successfully created
self.assertEqual(1, len(storage))
self.assertEqual(IActionSucceededEvent, storage.values()[0].event)
# workflow_state to be published is
# default condition of content_trigger
self.assertEqual(5, len(storage.values()[0].conditions))
self.assertEqual(
WorkflowStateCondition,
storage.values()[0].conditions[-1].__class__
)
self.assertEqual(
'Test',
storage.values()[0].actions[0].ifttt_event_name
)
self.assertEqual(
'plone.actions.Ifttt',
storage.values()[0].actions[0].element
)
self.assertEqual(
PAYLOAD_DESCRIPTION,
storage.values()[0].actions[0].payload_option
)
72 changes: 72 additions & 0 deletions src/collective/ifttt/tests/test_event_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
from collective.ifttt.actions.ifttt import PAYLOAD_START
from collective.ifttt.testing import COLLECTIVE_IFTTT_INTEGRATION_TESTING
from plone.app.contentrules.conditions.portaltype import PortalTypeCondition
from plone.app.contentrules.conditions.wfstate import WorkflowStateCondition
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.contentrules.engine.interfaces import IRuleStorage
from Products.CMFCore.interfaces._events import IActionSucceededEvent
from zope.component import getMultiAdapter
from zope.component import getUtility

import unittest


class TestActionMenu(unittest.TestCase):
layer = COLLECTIVE_IFTTT_INTEGRATION_TESTING

def setUp(self):

self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.request = self.layer['request']

def test_view(self):
# Check existence of IFTTT Action Menu

self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_event_trigger')
actions_view = self.view()
self.assertIn('including the datetime of event', actions_view)

def test_add(self):

self.request.method = 'POST'
self.request.form['form.widgets.ifttt_event_name'] = 'Test'
self.request.form['form.widgets.workflow_transitions'] = [
'publish', 'reject'
]
self.request.form['form.buttons.add'] = u'Add'
self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_event_trigger')
self.view()

storage = getUtility(IRuleStorage)

# check that rule has been successfully created
self.assertEqual(1, len(storage))
self.assertEqual(IActionSucceededEvent, storage.values()[0].event)
# workflow_state to be published and content_types to be events
# is default condition of content_trigger
self.assertEqual(4, len(storage.values()[0].conditions))
self.assertEqual(
WorkflowStateCondition,
storage.values()[0].conditions[-1].__class__
)
self.assertEqual(
PortalTypeCondition,
storage.values()[0].conditions[0].__class__
)
self.assertEqual(
'Test',
storage.values()[0].actions[0].ifttt_event_name
)
self.assertEqual(
'plone.actions.Ifttt',
storage.values()[0].actions[0].element
)
self.assertEqual(
PAYLOAD_START,
storage.values()[0].actions[0].payload_option
)
27 changes: 0 additions & 27 deletions src/collective/ifttt/tests/test_menu.py

This file was deleted.

63 changes: 63 additions & 0 deletions src/collective/ifttt/tests/test_user_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
from collective.ifttt.actions.ifttt import PAYLOAD_USERNAME
from collective.ifttt.testing import COLLECTIVE_IFTTT_INTEGRATION_TESTING
from plone.app.contentrules.conditions.wfstate import WorkflowStateCondition # noqa
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.contentrules.engine.interfaces import IRuleStorage
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.lifecycleevent.interfaces import IObjectModifiedEvent

import unittest


class TestActionMenu(unittest.TestCase):
layer = COLLECTIVE_IFTTT_INTEGRATION_TESTING

def setUp(self):

self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.request = self.layer['request']

def test_view(self):
# Check existence of IFTTT Action Menu

self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_user_trigger')
actions_view = self.view()
self.assertIn(
'including the information of who changed it', actions_view
)

def test_add(self):

self.request.method = 'POST'
self.request.form['form.widgets.ifttt_event_name'] = 'Test'
self.request.form['form.widgets.content_types'] = [
'Document', 'News Item'
]
self.request.form['form.buttons.add'] = u'Add'
self.view = getMultiAdapter((self.portal, self.request),
name='ifttt_user_trigger')
self.view()

storage = getUtility(IRuleStorage)

# check that rule has been successfully created
self.assertEqual(1, len(storage))
self.assertEqual(IObjectModifiedEvent, storage.values()[0].event)
self.assertEqual(2, len(storage.values()[0].conditions))
self.assertEqual(
'Test',
storage.values()[0].actions[0].ifttt_event_name
)
self.assertEqual(
'plone.actions.Ifttt',
storage.values()[0].actions[0].element
)
self.assertEqual(
PAYLOAD_USERNAME,
storage.values()[0].actions[0].payload_option
)

0 comments on commit b658d12

Please sign in to comment.