| 1 | import unittest |
|---|
| 2 | |
|---|
| 3 | from zope.interface import alsoProvides |
|---|
| 4 | from zope.schema.interfaces import IField |
|---|
| 5 | from zope.component import queryMultiAdapter |
|---|
| 6 | from zope.publisher.browser import TestRequest |
|---|
| 7 | |
|---|
| 8 | from z3c.form.interfaces import IFormLayer |
|---|
| 9 | from z3c.form.interfaces import IValidator |
|---|
| 10 | from z3c.form.interfaces import IFieldWidget |
|---|
| 11 | from z3c.form.interfaces import IErrorViewSnippet |
|---|
| 12 | |
|---|
| 13 | from Products.Five import zcml |
|---|
| 14 | from Products.Five import fiveconfigure |
|---|
| 15 | from Testing import ZopeTestCase as ztc |
|---|
| 16 | from Products.PloneTestCase.layer import onsetup |
|---|
| 17 | from Products.PloneTestCase import PloneTestCase as ptc |
|---|
| 18 | |
|---|
| 19 | from quintagroup.z3cform.captcha import Captcha |
|---|
| 20 | from quintagroup.z3cform.captcha import CaptchaWidget |
|---|
| 21 | from quintagroup.z3cform.captcha.widget import CaptchaWidgetFactory |
|---|
| 22 | |
|---|
| 23 | @onsetup |
|---|
| 24 | def setup_product(): |
|---|
| 25 | fiveconfigure.debug_mode = True |
|---|
| 26 | # Register z3c namespace first |
|---|
| 27 | import z3c.form |
|---|
| 28 | zcml.load_config('meta.zcml', z3c.form) |
|---|
| 29 | # Now register quintagroup.z3cform.captcha package |
|---|
| 30 | import quintagroup.captcha.core |
|---|
| 31 | import quintagroup.z3cform.captcha |
|---|
| 32 | zcml.load_config('configure.zcml', quintagroup.z3cform.captcha) |
|---|
| 33 | fiveconfigure.debug_mode = False |
|---|
| 34 | ztc.installPackage('quintagroup.captcha.core') |
|---|
| 35 | |
|---|
| 36 | setup_product() |
|---|
| 37 | ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default',]) |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | class TestRegistrations(ptc.PloneTestCase): |
|---|
| 41 | |
|---|
| 42 | def afterSetUp(self): |
|---|
| 43 | super(TestRegistrations, self).afterSetUp() |
|---|
| 44 | self.request = self.app.REQUEST |
|---|
| 45 | alsoProvides(self.request, IFormLayer) |
|---|
| 46 | |
|---|
| 47 | def testCaptchaFieldInterface(self): |
|---|
| 48 | self.assertEqual(IField.implementedBy(Captcha), True) |
|---|
| 49 | |
|---|
| 50 | def testCaptchaWidgetInterface(self): |
|---|
| 51 | self.assertEqual(IFieldWidget.implementedBy(CaptchaWidgetFactory), True) |
|---|
| 52 | |
|---|
| 53 | def testWidgetRegistration(self): |
|---|
| 54 | cfield = Captcha() |
|---|
| 55 | cwidget = queryMultiAdapter((cfield, self.request), IFieldWidget) |
|---|
| 56 | self.assertNotEqual(cwidget, None) |
|---|
| 57 | |
|---|
| 58 | def testValidatorRegistration(self): |
|---|
| 59 | cfield = Captcha() |
|---|
| 60 | cvalidator = queryMultiAdapter((None, self.request, None, cfield, None), |
|---|
| 61 | IValidator) |
|---|
| 62 | self.assertNotEqual(cvalidator, None) |
|---|
| 63 | |
|---|
| 64 | def testErrorViewRegistration(self): |
|---|
| 65 | cfield = Captcha() |
|---|
| 66 | cwidget = queryMultiAdapter((cfield, self.request), IFieldWidget) |
|---|
| 67 | error = ValueError() |
|---|
| 68 | eview = queryMultiAdapter( |
|---|
| 69 | (error, self.request, cwidget, cfield, None, None), |
|---|
| 70 | IErrorViewSnippet) |
|---|
| 71 | self.assertNotEqual(eview, None) |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | def test_suite(): |
|---|
| 75 | suite = unittest.TestSuite() |
|---|
| 76 | suite.addTest(unittest.makeSuite(TestRegistrations)) |
|---|
| 77 | return suite |
|---|