-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_zcml.py
91 lines (71 loc) · 3.28 KB
/
test_zcml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from ftw.logo.interfaces import IIconConfig
from ftw.logo.interfaces import ILogoConfig
from ftw.logo.testing import META_ZCML
from unittest2 import TestCase
from zope.component import getMultiAdapter
from zope.configuration.xmlconfig import ZopeXMLConfigurationError
from zope.interface import implementer
from zope.interface import Interface
from zope.interface.verify import verifyObject
import os
source_path = os.path.join(os.path.dirname(__file__), 'fixtures')
logo = os.path.join(source_path, 'logo.svg')
icon = os.path.join(source_path, 'logo.svg')
custom = os.path.join(source_path, 'custom.svg')
logo_img = os.path.join(source_path, 'logo.png')
mobile_img = os.path.join(source_path, 'mobile.png')
class IDummyLayer(Interface):
pass
@implementer(IDummyLayer)
class DummyRequest(object):
pass
class TestZCML(TestCase):
layer = META_ZCML
def test_logo_component(self):
self.load_zcml('<logo:logo base="{}" />'.format(logo))
registry = getMultiAdapter((None, None), ILogoConfig)
verifyObject(ILogoConfig, registry)
def test_logo_component_with_other_image_attr(self):
self.load_zcml('<logo:logo base="{}" logo="{}" />'.format(logo, logo_img))
registry = getMultiAdapter((None, None), ILogoConfig)
verifyObject(ILogoConfig, registry)
self.load_zcml('<logo:logo base="{}" mobile="{}" />'.format(logo, mobile_img))
registry = getMultiAdapter((None, None), ILogoConfig)
verifyObject(ILogoConfig, registry)
def test_logo_component_is_overwriteable(self):
self.load_zcml(
'<logo:logo base="{}" />'.format(logo),
'<logo:logo base="{}"'.format(custom),
' layer="ftw.logo.tests.test_zcml.IDummyLayer" />')
registry = getMultiAdapter((object(), DummyRequest()), ILogoConfig)
verifyObject(ILogoConfig, registry)
def test_icon_component(self):
self.load_zcml(
'<logo:icon base="{}" />'.format(icon))
registry = getMultiAdapter((None, None), IIconConfig)
verifyObject(IIconConfig, registry)
def test_icon_component_is_overwriteable(self):
self.load_zcml(
'<logo:icon base="{}" />'.format(icon),
'<logo:icon base="{}"'.format(custom),
' layer="ftw.logo.tests.test_zcml.IDummyLayer" />')
registry = getMultiAdapter((object(), DummyRequest()), IIconConfig)
verifyObject(IIconConfig, registry)
def load_zcml(self, *lines):
self.layer.load_zcml_string('\n'.join((
'<configure ',
' xmlns:logo="https://namespaces.4teamwork.ch/ftw.logo"',
' i18n_domain="my.package"',
' package="ftw.logo.tests">',
) + lines + (
'</configure>',
)))
def test_fail_to_load_if_no_valid_attr_is_present(self):
with self.assertRaises(ZopeXMLConfigurationError):
self.load_zcml('<logo:logo />'.format(logo))
with self.assertRaises(ZopeXMLConfigurationError):
self.load_zcml('<logo:logo dummy="nothing" />'.format(logo))
with self.assertRaises(ZopeXMLConfigurationError):
self.load_zcml('<logo:icon />'.format(logo))
with self.assertRaises(ZopeXMLConfigurationError):
self.load_zcml('<logo:icon dummy="nothing" />'.format(logo))