SHARE
TWEET

test_sync.py

a guest May 18th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import copy
  2. import unittest2 as unittest
  3. from plone import api
  4. from plone.app.multilingual.interfaces import ITranslationManager
  5.  
  6. from my.translations.testing import\
  7. MY_TRANSLATIONS_INTEGRATION_TESTING
  8.  
  9. from zope.component import getSiteManager
  10.  
  11. #Plone
  12. from plone.app.testing import TEST_USER_NAME, TEST_USER_ID
  13. from plone.app.testing import login, logout
  14. from plone.app.testing import setRoles
  15. from plone.testing.z2 import Browser
  16.  
  17. class TestTranslationSync(unittest.TestCase):
  18.     """ Ensure that when an English object is acted on that translations are
  19.    also generated/removed appropriately.
  20.    """
  21.     layer = MY_TRANSLATIONS_INTEGRATION_TESTING
  22.  
  23.     def setUp(self):
  24.         self.app = self.layer['app']
  25.         self.portal = self.layer['portal']
  26.  
  27.         sm = getSiteManager(context=self.portal)
  28.  
  29.     def tearDown(self):
  30.         sm = getSiteManager(context=self.portal)
  31.  
  32.     def get_site_languages(self):
  33.         """ Returns site languages except for preferred language.
  34.        """
  35.         portal_languages = api.portal.get_tool(name='portal_languages')
  36.         langs = copy.copy(portal_languages.getSupportedLanguages())
  37.         langs.remove(portal_languages.getPreferredLanguage())
  38.  
  39.         return langs
  40.  
  41.     def test_transition_to_private(self):
  42.         # create the english object
  43.         en = self.portal.unrestrictedTraverse('en')
  44.         test_doc = api.content.create(
  45.         type='Document',
  46.         title='Test Translation Sync',
  47.         container=en)
  48.  
  49.         api.content.transition(obj=test_doc,
  50.                                 transition='publishformembers',
  51.                                 comment='Testing translation sync.')
  52.  
  53.         # make sure that translation exists for all supported
  54.         # site language that are not the preferred language.
  55.         langs = self.get_site_languages()
  56.  
  57.         all_translations_exist = all([ITranslationManager(test_doc).has_translation(lang) for lang in langs])
  58.  
  59.         api.content.delete(obj=test_doc)
  60.  
  61.         assert all_translations_exist
  62.  
  63.  
  64.  
  65. def test_suite():
  66.     return unittest.defaultTestLoader.loadTestsFromName(__name__)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top