Permalink
Browse files

add tests

  • Loading branch information...
1 parent b71bd03 commit d23981e8ddb72952d6be67ba0984553fab18658a @toutpt toutpt committed Apr 26, 2012
View
@@ -1,6 +1,7 @@
[buildout]
extends =
http://svn.plone.org/svn/collective/buildout/plonetest/test-4.1.x.cfg
+ https://github.com/toutpt/mypythontools/raw/master/test-xml.cfg
package-name = collective.linguasitemap
package-extras = [tests]
@@ -35,7 +35,7 @@ def publishTraverse(self, request, name):
return sitemap_view
def extractLanguage(self, name):
-
+ if type(name) not in (str, unicode): return
if name.startswith('sitemap') and len(name)>11 and '_' in name:
sitemap = name.split('.')[0]
lang = str(sitemap.split('_')[1])
@@ -4,14 +4,32 @@
from collective.linguasitemap.tests import base, utils
from plone.testing.z2 import Browser
-class UnitTestSiteMap(unittest.TestCase):
+class UnitTestSiteMapView(unittest.TestCase):
def test_language(self):
from collective.linguasitemap.browser import sitemap
sm = sitemap.SiteMapView(utils.FakeContext(), None)
self.assertTrue(hasattr(sm, 'language'))
self.assertEqual(sm.language, 'all')
+class UnitTestSiteMapTraverser(unittest.TestCase):
+
+ def test_extractLanguage(self):
+ from collective.linguasitemap.browser import sitemap
+ traverser = sitemap.SiteMapTraverser(None, None)
+ self.assertTrue(traverser.extractLanguage('notsitemap') is None)
+ self.assertTrue(traverser.extractLanguage('sitemap.xml.gz') is None)
+ self.assertTrue(traverser.extractLanguage(None) is None)
+ self.assertTrue(traverser.extractLanguage('sitemap_fr.xml.gz') =='fr')
+ self.assertTrue(traverser.extractLanguage('sitemap_xx.xml.gz') =='xx')
+ self.assertTrue(traverser.extractLanguage('sitemap_yyy.xml.gz') == 'yyy')
+
+ def test_publishTraverse(self):
+ from collective.linguasitemap.browser import sitemap
+ traverser = sitemap.SiteMapTraverser(utils.FakeContext(), {'URL':'http://nohost/plone'})
+ self.assertRaises(KeyError, traverser.publishTraverse, {'URL':'http://nohost/plone'}, 'test')
+
+
class IntegrationTestSiteMap(base.IntegrationTestCase):
"""The name of the class should be meaningful. This may be a class that
tests the installation of a particular product.
@@ -28,9 +46,6 @@ def test_language(self):
self.assertTrue(hasattr(sm, 'language'))
self.assertEqual(sm.language,'all')
- sm = self.portal.restrictedTraverse('@@sitemap.xml.gz')
- self.assertTrue(hasattr(sm, 'language'))
- self.assertEqual(sm.language,'all')
class FunctionaTestSiteMap(base.FunctionalTestCase):
"""The name of the class should be meaningful. This may be a class that
@@ -44,5 +59,3 @@ def test_language(self):
self.assert_(len(browser.contents)>0)
#TODO: open the gzip and then parse the xml and then verify content
-def test_suite():
- return unittest.defaultTestLoader.loadTestsFromName(__name__)
@@ -0,0 +1,11 @@
+import unittest2 as unittest
+from collective.linguasitemap.tests import base
+
+class TestSiteMapTraverser(base.IntegrationTestCase):
+ """The name of the class should be meaningful. This may be a class that
+ tests the installation of a particular product.
+ """
+
+
+def test_suite():
+ return unittest.defaultTestLoader.loadTestsFromName(__name__)

0 comments on commit d23981e

Please sign in to comment.