Changeset 284
- Timestamp:
- 06/12/09 10:02:52 (4 years ago)
- Location:
- enpraxis.staticsite/trunk/enpraxis/staticsite
- Files:
-
- 3 edited
-
tests/testDeploy.py (modified) (1 diff)
-
tests/test_unit_staticutility.py (modified) (3 diffs)
-
utilities/staticsiteutility.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
enpraxis.staticsite/trunk/enpraxis/staticsite/tests/testDeploy.py
r273 r284 1 1 from base import StaticSiteTestCase 2 from enpraxis.staticsite.utilities.interfaces import IStaticSiteUtility 3 from zope.component import getUtility 4 from os.path import join as os_join 5 from os.path import split as os_split 6 import Globals 7 import os 2 8 3 9 class TestDeploy(StaticSiteTestCase): 4 10 5 def testExample(self): 6 """ Placeholder for integration test """ 7 pass 11 12 def afterSetUp(self): 13 """ Create some dummy objects """ 14 import pdb; pdb.set_trace() 15 self.setRoles('Manager') 16 # self.folder = getattr(self.portal, 'test-folder', None) 17 # self.doc = self.folder.invokeFactory('Document', 'test-page') 18 # self.file = self.folder.invokeFactory('File', 'test-file') 19 # self.image = self.folder.invokeFactory('Image', 'test-image') 20 # os.chdir('tests') 21 # os.mkdir('tmp') 22 # os.chdir('tmp') 23 24 25 def testWriteFile(self): 26 """ Integration test for writing a file """ 27 import pdb; pdb.set_trace() 28 filepathlist =['test-folder','test-folder','test-file'] 29 ssutil = getUtility(IStaticSiteUtility) 30 file_path = '%s' %(os_join(filepathlist)) 31 fdata = '<html><test-page></test-page></html>' 32 # ssutil._writeFile(file_path, fdata) 33 # file = open(file_path, 'r') 34 # ndata = file.read() 35 # file.close() 36 # self.assertEqual(ndata, fdata) 37 # # Try writing data over the top 38 # fdata = '<html><test-doc></test-doc></html>' 39 # ssutil._writeFile(file_path, fdata) 40 # file = open(file_path, 'r') 41 # ndata = file.read() 42 # file.close() 43 # self.assertEqual(ndata, fdata) 44 45 def testCreateDirectory(self): 46 """ Integration test for _createDirectory method """ 47 fldrpathlist = ['test-folder','test-folder-2'] 48 ssutil = getUtility(IStaticSiteUtility) 49 folder_path = '%s' %(os_join(fldrpathlist)) 50 # ssutil._createDirectory(folder_path) 51 # # Run again to verify that folder can be overwritten 52 # ssutil._createDirectory(folder_path) 53 54 def testGetObjPath(self): 55 """ Integration test for _getObjPath method """ 56 ssutil = getUtility(IStaticSiteUtility) 57 filepathlist =['test-folder','test-folder'] 58 url = 'http://localhost:8080/site/test-folder/test-file' 59 portal_url = 'http://localhost:8080/site' 60 dpath = ssutil._getObjPath(url, portal_url, os_join(filepathlist)) 61 self.assertEqual(dpath, dpath) 62 63 def beforeTearDown(self): 64 """ Remove the tmp directory inside tests directory """ 65 # os.rmdir('tmp') 66 67 8 68 9 69 def test_suite(): -
enpraxis.staticsite/trunk/enpraxis/staticsite/tests/test_unit_staticutility.py
r272 r284 1 1 import unittest 2 import Globals 3 from mocker import KWARGS, ARGS, ANY 2 4 from plone.mocktestcase import MockTestCase 5 from enpraxis.staticsite.utilities.staticsiteutility import StaticSiteUtility 6 7 from enpraxis.staticsite.utilities.interfaces import IStaticSiteUtility 8 from zope.component import getUtility 3 9 4 10 class TestStaticUtility(MockTestCase): … … 7 13 def test_deploySite(self): 8 14 """ test the deploySite method """ 9 15 10 16 def test_traverse(self): 11 17 """ test the traverse method """ 18 19 12 20 13 21 def test_deployObject(self): 14 22 """ test the deployObject method """ 15 23 purlfunc = lambda: 'http://localhost:8080/site' 24 dummy1 = self.create_dummy(portal_url = purlfunc, is_folderish = True, Type = ['page']) 25 ss_mock = self.mocker.proxy(StaticSiteUtility(u'testtype')) 26 self.expect(ss_mock._getObjPath(ARGS)).result('/test-folder/test-folder-1') 27 self.expect(ss_mock._createDirectory(ARGS)).result(None) 28 self.expect(ss_mock._httpget(ARGS)).result(None) 29 self.expect(ss_mock.runFilters(ARGS)).result(None) 30 self.mock_utility(ss_mock, IStaticSiteUtility, name=u'testtype') 31 self.mocker.replay() 32 ssutil = getUtility(IStaticSiteUtility, name = u'testtype') 33 ssutil.deployObject('http://localhost:8080/site', dummy1, 'test-folder/test-folder', 'http://www.plone.org') 34 35 # def runTestUtility(self, dummy): 36 # """ helper class for running utility """ 37 # ssutil = getUtility(IStaticSiteUtility, name = u'testtype') 38 # ssutil.deployObject('http://localhost:8080/site', dummy, 'test-folder/test-folder', 'http://www.plone.org') 39 16 40 def test_runFilters(self): 17 41 """ test the runFilters method """ … … 19 43 def test_getDeploymentPath(self): 20 44 """ test the _getDeploymentPath method """ 45 Globals.BobobaseName = '/test-root/zope/dev/test/var/Data.fs' 46 ssu = StaticSiteUtility() 47 dspath = ssu._getDeploymentPath('test-path') 48 self.assertEqual(dspath, '/test-root/zope/dev/test/var/test-path') 21 49 22 50 def test_getObjPath(self): -
enpraxis.staticsite/trunk/enpraxis/staticsite/utilities/staticsiteutility.py
r283 r284 80 80 raw = self._httpget(url) 81 81 self._writeFile(path, raw) 82 #process rdf for the object 83 self._deployRDF(brain, url, path) 84 #process document actions 82 85 if soup: 83 self._deployDocumentActions(brain, path, soup) 86 self._deployDocumentActions(brain, portal_url, path, soup) 87 88 def _deployRDF(self, brain, url, path): 89 """ Deploy the RDF for an object """ 90 rdfurl = '%s/rdf' %url 91 rdfpath = '%s-rdf' %path 92 if brain.Type in ['Page', 'Course', 'Division', 'Folder', 'File', 'Image']: 93 rdfraw = self._httpget(rdfurl) 94 self._writeFile(rdfpath, rdfraw) 84 95 85 96 def runFilters(self, soup, filterchain, portal_url, domain): … … 155 166 self._writeFile(path, raw) 156 167 157 def _deployDocumentActions(self, brain, p ath, soup):168 def _deployDocumentActions(self, brain, portal_url, path, soup): 158 169 """ Deploys the document actions for the site """ 159 170 doc_actions = brain.portal_actions.document_actions.listActions() 160 171 for doc_action in doc_actions: 161 if doc_action.id in ['skinless', 's5'] and self._findDocActionUrl(soup, doc_action.id): 162 action_url = self._findDocActionUrl(soup, doc_action.id) 163 writepath = '%s-%s.html' %(path, doc_action.id) 164 raw = self._httpget(action_url) 165 self._writeFile(writepath, raw) 166 167 def _findDocActionUrl(self, soup, id): 172 if doc_action.id in ['skinless', 's5']: 173 action_url = self._findDocActionUrl(portal_url, soup, doc_action.id) 174 if action_url: 175 writepath = '%s-%s.html' %(path, doc_action.id) 176 raw = self._httpget(action_url) 177 self._writeFile(writepath, raw) 178 elif doc_action.id in ['rss', 'rss_front']: 179 if doc_action.id == 'rss_front': 180 action_url = self._findDocActionUrl(portal_url, soup, doc_action.id) 181 if action_url: 182 writepath = '%s-%s' %(path, doc_action.id) 183 raw = self._httpget(action_url) 184 self._writeFile(writepath, raw) 185 186 187 def _findDocActionUrl(self, portal_url, soup, id): 168 188 """ Parse document soup to find a document action """ 169 189 docdivs = soup.body.findAll('div') … … 176 196 if anchor and anchor.has_key('href'): 177 197 action_url = anchor['href'] 198 if action_url.find(portal_url) == -1: 199 action_url = '%s/%s' %(portal_url, action_url) 178 200 break 179 201 return action_url
Note: See TracChangeset
for help on using the changeset viewer.
