Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toutpt committed Apr 26, 2012
1 parent b71bd03 commit d23981e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 1 addition & 1 deletion collective/linguasitemap/browser/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
25 changes: 19 additions & 6 deletions collective/linguasitemap/tests/test_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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__)
11 changes: 11 additions & 0 deletions collective/linguasitemap/tests/test_traverser.py
Original file line number Diff line number Diff line change
@@ -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.