PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/naaya/content/document/tests/testFunctional.py

https://github.com/bogtan/Naaya
Python | 212 lines | 177 code | 15 blank | 20 comment | 2 complexity | d7d7f116c992facc5f149704ce7ded56 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 NyDocumentFunctionalTestCase(NaayaFunctionalTestCase):
  24. """ TestCase for NaayaContent object """
  25. def afterSetUp(self):
  26. from Products.Naaya.NyFolder import addNyFolder
  27. from naaya.content.document.document_item import addNyDocument
  28. addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1)
  29. addNyDocument(self.portal.myfolder, id='mydoc', title='My document', 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/document_add')
  37. self.failUnless('<h1>Submit HTML Document</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_doc'
  48. form['description:utf8:ustring'] = 'test_doc_description'
  49. form['coverage:utf8:ustring'] = 'test_doc_coverage'
  50. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  51. form['body:utf8:ustring'] = 'test_doc_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_doc.approveThis()
  56. self.browser.go('http://localhost/portal/info/test_doc')
  57. html = self.browser.get_html()
  58. self.failUnless(re.search(r'<h1>.*test_doc.*</h1>', html, re.DOTALL))
  59. self.failUnless('test_doc_description' in html)
  60. self.failUnless('test_doc_coverage' in html)
  61. self.failUnless('keyw1, keyw2' in html)
  62. self.failUnless('test_doc_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/document_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/mydoc/edit_html')
  77. form = self.browser.get_form('frmEdit')
  78. self.failUnlessEqual(form['title:utf8:ustring'], 'My document')
  79. form['title:utf8:ustring'] = 'new_doc_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.mydoc.title, 'new_doc_title')
  83. self.browser.go('http://localhost/portal/myfolder/mydoc/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.mydoc.title, 'new_doc_title')
  89. self.failUnlessEqual(self.portal.myfolder.mydoc.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/mydoc/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/mydoc/manage_edit_html')
  105. form = self.browser.get_form('frmEdit')
  106. self.failUnlessEqual(form['title:utf8:ustring'], 'My document')
  107. form['title:utf8:ustring'] = 'new_doc_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.mydoc.title, 'new_doc_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_document = tables[0].findAll('a', attrs={'href': 'http://localhost/portal/myfolder/mydoc'})
  120. self.assertTrue(len(links_to_document) == 1)
  121. self.assertTrue(links_to_document[0].string == 'My document')
  122. self.browser_do_logout()
  123. class NyDocumentVersioningFunctionalTestCase(NaayaFunctionalTestCase):
  124. """ TestCase for NaayaContent object """
  125. def afterSetUp(self):
  126. from naaya.content.document.document_item import addNyDocument
  127. addNyDocument(self.portal.info, id='ver_doc', title='ver_doc', submitted=1)
  128. import transaction; transaction.commit()
  129. def beforeTearDown(self):
  130. self.portal.info.manage_delObjects(['ver_doc'])
  131. import transaction; transaction.commit()
  132. def test_start_version(self):
  133. from naaya.content.document.document_item import document_item
  134. self.browser_do_login('admin', '')
  135. self.failUnlessEqual(self.portal.info.ver_doc.version, None)
  136. self.browser.go('http://localhost/portal/info/ver_doc/startVersion')
  137. self.failUnless(isinstance(self.portal.info.ver_doc.version, document_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_doc/startVersion')
  142. form = self.browser.get_form('frmEdit')
  143. form['title:utf8:ustring'] = 'ver_doc_newtitle'
  144. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  145. self.browser.submit()
  146. ver_doc = self.portal.info.ver_doc
  147. self.failUnlessEqual(ver_doc.title, 'ver_doc')
  148. # we can't do ver_doc.version.title because version objects don't have the _languages property
  149. self.failUnlessEqual(ver_doc.version.getLocalProperty('title', 'en'), 'ver_doc_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_doc/startVersion')
  154. form = self.browser.get_form('frmEdit')
  155. form['title:utf8:ustring'] = 'ver_doc_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_doc_version')
  160. self.browser_do_logout()
  161. def test_suite():
  162. suite = TestSuite()
  163. suite.addTest(makeSuite(NyDocumentFunctionalTestCase))
  164. suite.addTest(makeSuite(NyDocumentVersioningFunctionalTestCase))
  165. return suite