Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toutpt committed Apr 30, 2013
1 parent 3125f10 commit d2a7b23
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 4 deletions.
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ scripts = zopepy

[versions]
etherpad = 1.2.7
plone.app.collection = 2.0b5

[apache-config]
recipe=collective.recipe.template
Expand Down
10 changes: 10 additions & 0 deletions collective/etherpad/dexterity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ def __init__(self, context, request):
super(EtherpadSyncForm, self).__init__(context, request)
self.dexterity_fti = None

def save(self):
#get the content from etherpad
html = self.etherpad.getHTML(padID=self.padID)
if html and 'html' in html:
setattr(
self.context,
self.field.getName(),
self.field.fromUnicode(html['html'])
)


class EtherpadEditView(archetypes.EtherpadEditView):
"""Implement etherpad for Archetypes content types"""
Expand Down
25 changes: 25 additions & 0 deletions collective/etherpad/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
import collective.etherpad


class DexterityLayer(PloneWithPackageLayer):
def applyProfiles(self, portal):
self.applyProfile(portal, 'plone.app.contenttypes:default')
super(DexterityLayer, self).applyProfiles(portal)

def setUpZCMLFiles(self):
super(DexterityLayer, self).setUpZCMLFiles()
import plone.app.contenttypes
self.loadZCML("configure.zcml", package=plone.app.contenttypes)


FIXTURE = PloneWithPackageLayer(
zcml_filename="configure.zcml",
zcml_package=collective.etherpad,
Expand All @@ -12,10 +23,24 @@
name="collective.etherpad:FIXTURE"
)


INTEGRATION = IntegrationTesting(
bases=(FIXTURE,), name="collective.etherpad:Integration"
)

FUNCTIONAL = FunctionalTesting(
bases=(FIXTURE,), name="collective.etherpad:Functional"
)


DEXTERITY_FIXTURE = DexterityLayer(
zcml_filename="configure.zcml",
zcml_package=collective.etherpad,
additional_z2_products=[],
gs_profile_id='collective.etherpad:default',
name="collective.etherpad:DxFIXTURE"
)

DEXTERITY_INTEGRATION = IntegrationTesting(
bases=(DEXTERITY_FIXTURE,), name="collective.etherpad:DxIntegration"
)
11 changes: 10 additions & 1 deletion collective/etherpad/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import transaction
import unittest2 as unittest
from plone.app.testing import TEST_USER_ID, setRoles
from collective.etherpad.testing import INTEGRATION, FUNCTIONAL
from collective.etherpad.testing import (
INTEGRATION,
FUNCTIONAL,
DEXTERITY_INTEGRATION
)


class UnitTestCase(unittest.TestCase):
Expand All @@ -27,6 +31,11 @@ def setRole(self, role="Member"):
setRoles(self.portal, TEST_USER_ID, [role])


class DxIntegrationTestCase(IntegrationTestCase):

layer = DEXTERITY_INTEGRATION


class FunctionalTestCase(IntegrationTestCase):

layer = FUNCTIONAL
Expand Down
9 changes: 9 additions & 0 deletions collective/etherpad/tests/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,12 @@ def render(self):

def update(self):
self.udpated = True


class FakeFTI(object):

def __init__(self, _schema):
self.schema = _schema

def lookupSchema(self):
return self.schema
123 changes: 123 additions & 0 deletions collective/etherpad/tests/test_dexterity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from datetime import datetime
import unittest2 as unittest
from collective.etherpad.tests import base, fake
from collective.etherpad.dexterity import EtherpadEditView, EtherpadSyncForm


class UnitTestDexterity(base.UnitTestCase):
"""Lets test the api module"""

def setUp(self):
super(UnitTestDexterity, self).setUp()
self.context = fake.FakeContext()
self.request = fake.FakeRequest()
self.view = EtherpadEditView(self.context, self.request)
self.load_fake()

def load_fake(self):
self.view.etherpad = fake.FakeEtherpad()
self.view.embed_settings = fake.FakeEtherpadEmbedSettings()
self.view.etherpad_settings = fake.FakeEtherpadSettings()
self.view.portal_state = fake.FakePortalState()
self.view.portal_registry = fake.FakeRegistry()
self.view.padName = 'UUID03295830259'
self.view.authorMapper = 'toutpt'
self.view.form_instance = fake.FakeEtherpadSyncForm()
self.view._portal = fake.FakePortal()
# self.view.model = fake.FakeModel
self.view.dexterity_fti = fake.FakeFTI(fake.FakeModel)

def test_update(self):
self.view.update()
self.assertEqual(self.view.field.getName(), 'text')
url = 'http://nohost.com/pad/p/g.aDAO30LjIDJWvyTU$UUID03295830259'
url += '?lang=fr&alwaysShowChat=true&useMonospaceFont=false'
url += '&showChat=true&showControls=true&showLineNumbers=true'
self.assertEqual(self.view.etherpad_iframe_url, url)
self.assertEqual(self.view.authorID, 'a.pocAeG7Fra31WvnO')
self.assertEqual(self.view.groupID, 'g.aDAO30LjIDJWvyTU')
self.assertEqual(self.view.sessionID, 's.lHo0Q9krIb1OCFOI')
self.assertEqual(self.view.padID, 'g.aDAO30LjIDJWvyTU$UUID03295830259')
validUntil = self.view.validUntil
self.assertTrue(validUntil.isdigit())
validUntil_datetime = datetime.fromtimestamp(int(validUntil))
now = datetime.now()
self.assertTrue(validUntil_datetime > now)

cookies = self.view.request.response.cookies
self.assertIn('sessionID', cookies)
session = cookies['sessionID']
self.assertEqual(session['path'], '/plone/pad/')
self.assertEqual(session['quoted'], False)
self.assertEqual(session['value'], 's.lHo0Q9krIb1OCFOI')


class IntegrationTestDexterity(base.DxIntegrationTestCase):
"""Here we test integration with Plone, not with etherpad"""

def setUp(self):
super(IntegrationTestDexterity, self).setUp()
self.view = EtherpadEditView(self.document, self.request)
self.view.etherpad = fake.FakeEtherpad()

def test_update(self):
self.view.update()
#lets check plone related dependencies are well loaded
self.assertIsNotNone(self.view.portal_state)
self.assertIsNotNone(self.view.portal_registry)
self.assertIsNotNone(self.view.embed_settings)
self.assertIsNotNone(self.view.etherpad_settings)
self.assertEqual(self.view.authorMapper, 'test_user_1_')
uid = self.document.UID()
self.assertEqual(self.view.padName, uid)
self.assertEqual(self.view.groupMapper, uid)
padID = 'g.aDAO30LjIDJWvyTU$%s' % uid
self.assertEqual(self.view.padID, padID)

#replay the unittest here
self.assertEqual(self.view.field.getName(), 'text')
url = 'http://nohost/plone/pad/p/' + padID
url += '?lang=en&alwaysShowChat=true&useMonospaceFont=false'
url += '&showChat=true&showControls=true&showLineNumbers=true'
self.assertEqual(self.view.etherpad_iframe_url, url)
self.assertEqual(self.view.authorID, 'a.pocAeG7Fra31WvnO')
self.assertEqual(self.view.groupID, 'g.aDAO30LjIDJWvyTU')
self.assertEqual(self.view.sessionID, 's.lHo0Q9krIb1OCFOI')
validUntil = self.view.validUntil
self.assertTrue(validUntil.isdigit())
validUntil_datetime = datetime.fromtimestamp(int(validUntil))
now = datetime.now()
self.assertTrue(validUntil_datetime > now)

cookies = self.view.request.response.cookies
self.assertIn('sessionID', cookies)
session = cookies['sessionID']
self.assertEqual(session['path'], '/plone/pad/')
self.assertEqual(session['quoted'], False)
self.assertEqual(session['value'], 's.lHo0Q9krIb1OCFOI')

def test_EtherpadSyncForm(self):
form = EtherpadSyncForm(self.document, self.request)
etherpad = fake.FakeEtherpad()
etherpad.pads['mypad'] = {'html': 'my html'}
form.padID = 'g.aDAO30LjIDJWvyTU$mypad'
html = self.document.text
self.assertEqual(html, None)
form.etherpad = etherpad
form.padID = 'mypad'
from zope import component
from zope import schema
from plone.dexterity.interfaces import IDexterityFTI
dexterity_fti = component.getUtility(
IDexterityFTI,
name="Document"
)
form.field = schema.getFields(dexterity_fti.lookupSchema())['text']
form.save()

html = self.document.text
self.assertEqual(html.output, 'my html')


def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
],
extras_require=dict(
test=['plone.app.testing',
'plone.app.dexterity',
'plone.app.textfield'
],
'plone.app.contenttypes',
],
),
entry_points="""
# -*- Entry points: -*-
Expand Down

0 comments on commit d2a7b23

Please sign in to comment.