PageRenderTime 99ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/naaya/content/story/tests/testFunctional.py

https://github.com/bogtan/Naaya
Python | 213 lines | 178 code | 15 blank | 20 comment | 2 complexity | 613dfcd69a8f9dcd520adc05178b838b MD5 | raw file
  1. # The contents of this file are subject to the Mozilla Public
  2. # License Version 1.1 (the "License"); you may not use this file
  3. # except in compliance with the License. You may obtain a copy of
  4. # the License at http://www.mozilla.org/MPL/
  5. #
  6. # Software distributed under the License is distributed on an "AS
  7. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  8. # implied. See the License for the specific language governing
  9. # rights and limitations under the License.
  10. #
  11. # The Initial Owner of the Original Code is European Environment
  12. # Agency (EEA). Portions created by Eau de Web are
  13. # Copyright (C) European Environment Agency. All
  14. # Rights Reserved.
  15. #
  16. # Authors:
  17. #
  18. # Alex Morega, Eau de Web
  19. import re
  20. from unittest import TestSuite, makeSuite
  21. from BeautifulSoup import BeautifulSoup
  22. from Products.Naaya.tests.NaayaFunctionalTestCase import NaayaFunctionalTestCase
  23. class NyStoryFunctionalTestCase(NaayaFunctionalTestCase):
  24. """ TestCase for NaayaContent object """
  25. def afterSetUp(self):
  26. from Products.Naaya.NyFolder import addNyFolder
  27. from naaya.content.story.story_item import addNyStory
  28. addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1)
  29. addNyStory(self.portal.myfolder, id='mystory', title='My story', submitted=1, contributor='contributor')
  30. import transaction; transaction.commit()
  31. def beforeTearDown(self):
  32. self.portal.manage_delObjects(['myfolder'])
  33. import transaction; transaction.commit()
  34. def test_add(self):
  35. self.browser_do_login('contributor', 'contributor')
  36. self.browser.go('http://localhost/portal/info/story_add')
  37. self.failUnless('<h1>Submit Story</h1>' in self.browser.get_html())
  38. form = self.browser.get_form('frmAdd')
  39. expected_controls = set([
  40. 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'coverage:utf8:ustring',
  41. 'keywords:utf8:ustring', 'releasedate', 'discussion:boolean',
  42. ])
  43. found_controls = set(c.name for c in form.controls)
  44. self.failUnless(expected_controls.issubset(found_controls),
  45. 'Missing form controls: %s' % repr(expected_controls - found_controls))
  46. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  47. form['title:utf8:ustring'] = 'test_story'
  48. form['description:utf8:ustring'] = 'test_story_description'
  49. form['coverage:utf8:ustring'] = 'test_story_coverage'
  50. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  51. form['body:utf8:ustring'] = 'test_story_body'
  52. self.browser.submit()
  53. html = self.browser.get_html()
  54. self.failUnless('The administrator will analyze your request and you will be notified about the result shortly.' in html)
  55. self.portal.info.test_story.approveThis()
  56. self.browser.go('http://localhost/portal/info/test_story')
  57. html = self.browser.get_html()
  58. self.failUnless(re.search(r'<h1>.*test_story.*</h1>', html, re.DOTALL))
  59. self.failUnless('test_story_description' in html)
  60. self.failUnless('test_story_coverage' in html)
  61. self.failUnless('keyw1, keyw2' in html)
  62. self.failUnless('test_story_body' in html)
  63. self.browser_do_logout()
  64. def test_add_error(self):
  65. self.browser_do_login('contributor', 'contributor')
  66. self.browser.go('http://localhost/portal/myfolder/story_add')
  67. form = self.browser.get_form('frmAdd')
  68. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  69. # enter no values in the fields
  70. self.browser.submit()
  71. html = self.browser.get_html()
  72. self.failUnless('The form contains errors' in html)
  73. self.failUnless('Value required for "Title"' in html)
  74. def test_edit(self):
  75. self.browser_do_login('admin', '')
  76. self.browser.go('http://localhost/portal/myfolder/mystory/edit_html')
  77. form = self.browser.get_form('frmEdit')
  78. self.failUnlessEqual(form['title:utf8:ustring'], 'My story')
  79. form['title:utf8:ustring'] = 'new_story_title'
  80. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  81. self.browser.submit()
  82. self.failUnlessEqual(self.portal.myfolder.mystory.title, 'new_story_title')
  83. self.browser.go('http://localhost/portal/myfolder/mystory/edit_html?lang=fr')
  84. form = self.browser.get_form('frmEdit')
  85. form['title:utf8:ustring'] = 'french_title'
  86. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  87. self.browser.submit()
  88. self.failUnlessEqual(self.portal.myfolder.mystory.title, 'new_story_title')
  89. self.failUnlessEqual(self.portal.myfolder.mystory.getLocalProperty('title', 'fr'), 'french_title')
  90. self.browser_do_logout()
  91. def test_edit_error(self):
  92. self.browser_do_login('admin', '')
  93. self.browser.go('http://localhost/portal/myfolder/mystory/edit_html')
  94. form = self.browser.get_form('frmEdit')
  95. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  96. form['title:utf8:ustring'] = ''
  97. self.browser.submit()
  98. html = self.browser.get_html()
  99. self.failUnless('The form contains errors' in html)
  100. self.failUnless('Value required for "Title"' in html)
  101. self.browser_do_logout()
  102. def test_manage(self):
  103. self.browser_do_login('admin', '')
  104. self.browser.go('http://localhost/portal/myfolder/mystory/manage_edit_html')
  105. form = self.browser.get_form('frmEdit')
  106. self.failUnlessEqual(form['title:utf8:ustring'], 'My story')
  107. form['title:utf8:ustring'] = 'new_story_title'
  108. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  109. self.browser.submit()
  110. self.failUnlessEqual(self.portal.myfolder.mystory.title, 'new_story_title')
  111. self.browser_do_logout()
  112. def test_view_in_folder(self):
  113. self.browser_do_login('admin', '')
  114. self.browser.go('http://localhost/portal/myfolder')
  115. html = self.browser.get_html()
  116. soup = BeautifulSoup(html)
  117. tables = soup.findAll('table', id='folderfile_list')
  118. self.assertTrue(len(tables) == 1)
  119. links_to_story = tables[0].findAll('a', attrs={'href': 'http://localhost/portal/myfolder/mystory'})
  120. self.assertTrue(len(links_to_story) == 1)
  121. self.assertTrue(links_to_story[0].string == 'My story')
  122. self.browser_do_logout()
  123. class NyStoryVersioningFunctionalTestCase(NaayaFunctionalTestCase):
  124. """ TestCase for NaayaContent object """
  125. def afterSetUp(self):
  126. from naaya.content.story.story_item import addNyStory
  127. addNyStory(self.portal.info, id='ver_story', title='ver_story', submitted=1)
  128. import transaction; transaction.commit()
  129. def beforeTearDown(self):
  130. self.portal.info.manage_delObjects(['ver_story'])
  131. import transaction; transaction.commit()
  132. def test_start_version(self):
  133. from naaya.content.story.story_item import story_item
  134. self.browser_do_login('admin', '')
  135. self.failUnlessEqual(self.portal.info.ver_story.version, None)
  136. self.browser.go('http://localhost/portal/info/ver_story/startVersion')
  137. self.failUnless(isinstance(self.portal.info.ver_story.version, story_item))
  138. self.browser_do_logout()
  139. def test_edit_version(self):
  140. self.browser_do_login('admin', '')
  141. self.browser.go('http://localhost/portal/info/ver_story/startVersion')
  142. form = self.browser.get_form('frmEdit')
  143. form['title:utf8:ustring'] = 'ver_story_newtitle'
  144. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  145. self.browser.submit()
  146. ver_story = self.portal.info.ver_story
  147. self.failUnlessEqual(ver_story.title, 'ver_story')
  148. # we can't do ver_story.version.title because version objects don't have the _languages property
  149. self.failUnlessEqual(ver_story.version.getLocalProperty('title', 'en'), 'ver_story_newtitle')
  150. self.browser_do_logout()
  151. def test_save_changes_version(self):
  152. self.browser_do_login('admin', '')
  153. self.browser.go('http://localhost/portal/info/ver_story/startVersion')
  154. form = self.browser.get_form('frmEdit')
  155. form['title:utf8:ustring'] = 'ver_story_version'
  156. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  157. self.browser.submit()
  158. form = self.browser.get_form('frmEdit')
  159. self.failUnlessEqual(form['title:utf8:ustring'], 'ver_story_version')
  160. self.browser_do_logout()
  161. def test_suite():
  162. suite = TestSuite()
  163. suite.addTest(makeSuite(NyStoryFunctionalTestCase))
  164. suite.addTest(makeSuite(NyStoryVersioningFunctionalTestCase))
  165. return suite