source: trunk/tests/testAssets.py @ 66

Revision 66, 4.6 KB checked in by tarmo, 14 years ago (diff)

Changed the svn:eol-style property to "native", since
people aren't using unix line feeds uniformally.

  • Property svn:eol-style set to native
Line 
1#
2# Test case for Asset content
3#
4
5import os, sys, re
6if __name__ == '__main__':
7    execfile(os.path.join(sys.path[0], 'framework.py'))
8
9from Testing import ZopeTestCase
10from Testing.ZopeTestCase.functional import Functional
11from ToolboxTestCase import ToolboxTestCase
12from Products.Toolbox.BaseAsset import BaseAsset
13from Products.Archetypes.public import PrimaryFieldMarshaller
14
15types = ('ImageAsset','AudioAsset','HTMLTextAsset',)
16
17class TestAssets(ToolboxTestCase,Functional):
18
19    def afterSetUp(self):
20        self.types=self.portal.portal_types
21
22    def construct2(self, portal_type, id, folder):
23        fti = self.types.getTypeInfo(portal_type)
24        fti.constructInstance(folder, id=id)
25        self.failUnless(id in folder.objectIds())
26        return getattr(folder, id)
27
28    def testExistence(self):
29        for pt in types:
30            ob = self.construct(pt,pt,self.folder)
31            self.failUnlessEqual(ob._getPortalTypeName(),pt)
32            self.failUnlessEqual(ob.portal_type,pt)
33
34            id2 = "%s2" % pt
35            ob = self.construct(pt,id2,self.folder)
36            self.failUnlessEqual(ob._getPortalTypeName(),pt)
37            self.failUnlessEqual(ob.portal_type,pt)
38
39    def testBaseAssetAbstractness(self):
40        self.assertRaises(ValueError,self.construct,'BaseAsset','test',self.folder)
41   
42
43class TestImageAsset(TestAssets):
44
45    def afterSetUp(self):
46        self.content = self.construct('ImageAsset', 'TestAsset', self.folder)
47
48    def testCompatibilityFileAccess(self):
49        # Use an actual file, because if Python Imaging Library is installed, it
50        # will complain when non-files are used as image data.
51        file_text = open("../skins/toolbox/toolbox_banner.png","r").read()
52        self.content.edit(file=file_text)
53        self.failUnlessEqual(self.content.data, file_text)
54        self.failUnlessEqual(self.content.get_data(), file_text)
55
56    def test_schema_marshall(self):
57        schema = self.content.Schema()
58        marshall = schema.getLayerImpl('marshall')
59        self.failUnless(isinstance(marshall, PrimaryFieldMarshaller), marshall)
60
61#    def testWCAGLogo(self):
62#        ID='image'
63#        ob=self.construct('ImageAsset', ID ,self.folder)
64#        path='/'.join((self.folder.absolute_url_path(),ID))
65#        result=self.publish(path).getBody()
66#        self.failUnless(re.search("Explanation of Level Double-A Conformance", result))
67
68class TestAudioAsset(TestAssets):
69
70    def afterSetUp(self):
71        self.content = self.construct('AudioAsset', 'TestAsset', self.folder)
72
73    def testEditing(self):
74        TITLE='Test'
75        self.content.edit(title=TITLE)
76        self.assertEqual(self.content.Title(), TITLE)
77
78    def testWCAGLogo(self):
79        ID='audio'
80        ob=self.construct('AudioAsset', ID ,self.folder)
81        path='/'.join((self.folder.absolute_url_path(),ID))
82        result=self.publish(path).getBody()
83        self.failUnless(re.search("Explanation of Level Double-A Conformance", result))
84
85class TestHTMLTextAsset(TestAssets):
86
87    def testEditing(self):
88        ID='htmltext'
89        TITLE='Test'
90        BODY='<p>Test paragraph</p>'
91        ob=self.construct('HTMLTextAsset', ID ,self.folder)
92        ob.edit(title=TITLE, body=BODY)
93        self.assertEqual(ob.Title(), TITLE)
94        self.assertEqual(ob.getBody(), BODY)
95
96    def testEditHTMLzation(self):
97        ID='htmltext'
98        TITLE='Test'
99        BODY='Test paragraph'
100        BODYHTML='<p>Test paragraph</p>'
101        ob=self.construct('HTMLTextAsset', ID ,self.folder)
102        ob.edit(title=TITLE, body=BODY)
103        self.assertEqual(ob.Title(), TITLE)
104        self.assertEqual(ob.getBody(), BODYHTML)
105
106    def testView(self):
107        ID='htmltext'
108        TITLE='Test'
109        BODY='<p>Test paragraph</p><p>And another!</p>'
110        ob=self.construct('HTMLTextAsset', ID ,self.folder)
111        ob.edit(title=TITLE, body=BODY)
112        path='/'.join((self.folder.absolute_url_path(),ID))
113        result=self.publish(path).getBody()
114        self.failUnless(re.search(BODY, result))
115   
116    def testWCAGLogo(self):
117        ID='htmltext'
118        ob=self.construct('HTMLTextAsset', ID ,self.folder)
119        path='/'.join((self.folder.absolute_url_path(),ID))
120        result=self.publish(path).getBody()
121        self.failUnless(re.search("Explanation of Level Double-A Conformance", result))
122       
123def test_suite():
124    from unittest import TestSuite, makeSuite
125    suite = TestSuite()
126    suite.addTest(makeSuite(TestAssets))
127    suite.addTest(makeSuite(TestImageAsset))
128    suite.addTest(makeSuite(TestAudioAsset))
129    suite.addTest(makeSuite(TestHTMLTextAsset))
130    return suite
131
132if __name__ == '__main__':
133    framework()
Note: See TracBrowser for help on using the repository browser.