PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/naaya/content/geopoint/tests/testFunctional.py

https://github.com/bogtan/Naaya
Python | 221 lines | 184 code | 16 blank | 21 comment | 2 complexity | 67bb00abfc8a32bed0148c2fdf93e8b2 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 copy import deepcopy
  22. from BeautifulSoup import BeautifulSoup
  23. from Products.Naaya.tests.NaayaFunctionalTestCase import NaayaFunctionalTestCase
  24. from Products.NaayaCore.SchemaTool.widgets.geo import Geo
  25. class NyGeoPointFunctionalTestCase(NaayaFunctionalTestCase):
  26. """ TestCase for NaayaContent object """
  27. def afterSetUp(self):
  28. self.portal.manage_install_pluggableitem('Naaya GeoPoint')
  29. from Products.Naaya.NyFolder import addNyFolder
  30. from naaya.content.geopoint.geopoint_item import addNyGeoPoint
  31. addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1)
  32. self.portal.myfolder.folder_meta_types.append('Naaya GeoPoint')
  33. addNyGeoPoint(self.portal.myfolder, id='mygeopoint', title='My geopoint',
  34. submitted=1, contributor='contributor', geo_location=Geo('13', '13'))
  35. import transaction; transaction.commit()
  36. def beforeTearDown(self):
  37. self.portal.manage_delObjects(['myfolder'])
  38. self.portal.manage_uninstall_pluggableitem('Naaya GeoPoint')
  39. import transaction; transaction.commit()
  40. def test_add(self):
  41. self.browser_do_login('contributor', 'contributor')
  42. self.browser.go('http://localhost/portal/myfolder/geopoint_add_html')
  43. self.failUnless('<h1>Submit GeoPoint</h1>' in self.browser.get_html())
  44. form = self.browser.get_form('frmAdd')
  45. expected_controls = set([
  46. 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'coverage:utf8:ustring',
  47. 'keywords:utf8:ustring', 'releasedate', 'discussion:boolean',
  48. 'geo_location.lat:utf8:ustring', 'geo_location.lon:utf8:ustring',
  49. 'geo_location.address:utf8:ustring',
  50. 'geo_type:utf8:ustring', 'url:utf8:ustring', 'pointer:utf8:ustring',
  51. ])
  52. found_controls = set(c.name for c in form.controls)
  53. self.failUnless(expected_controls.issubset(found_controls),
  54. 'Missing form controls: %s' % repr(expected_controls - found_controls))
  55. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  56. form['title:utf8:ustring'] = 'test_geopoint'
  57. form['description:utf8:ustring'] = 'test_geopoint_description'
  58. form['coverage:utf8:ustring'] = 'test_geopoint_coverage'
  59. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  60. form['geo_location.lat:utf8:ustring'] = '12.587142'
  61. form['geo_location.lon:utf8:ustring'] = '55.681004'
  62. form['geo_location.address:utf8:ustring'] = 'Kongens Nytorv 6, 1050 Copenhagen K, Denmark'
  63. #form['geo_type:utf8:ustring'] = ''
  64. form['url:utf8:ustring'] = 'http://www.eea.europa.eu'
  65. form['pointer:utf8:ustring'] = 'portal/info/contact'
  66. self.browser.submit()
  67. html = self.browser.get_html()
  68. self.failUnless('The administrator will analyze your request and you will be notified about the result shortly.' in html)
  69. geopoint = self.portal.myfolder.test_geopoint
  70. self.failUnlessEqual(geopoint.title, 'test_geopoint')
  71. self.failUnlessEqual(geopoint.geo_location,
  72. Geo('12.587142', '55.681004',
  73. 'Kongens Nytorv 6, 1050 Copenhagen K, Denmark'))
  74. self.failUnlessEqual(geopoint.url, 'http://www.eea.europa.eu')
  75. geopoint.approveThis()
  76. self.browser.go('http://localhost/portal/myfolder/test_geopoint')
  77. html = self.browser.get_html()
  78. self.failUnless(re.search(r'<h1>.*test_geopoint.*</h1>', html, re.DOTALL))
  79. self.failUnless('test_geopoint_description' in html)
  80. self.failUnless('test_geopoint_coverage' in html)
  81. self.failUnless('keyw1, keyw2' in html)
  82. self.browser_do_logout()
  83. def test_add_error(self):
  84. self.browser_do_login('contributor', 'contributor')
  85. self.browser.go('http://localhost/portal/myfolder/geopoint_add_html')
  86. form = self.browser.get_form('frmAdd')
  87. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  88. # enter no values in the fields
  89. self.browser.submit()
  90. html = self.browser.get_html()
  91. self.failUnless('The form contains errors' in html)
  92. self.failUnless('Value required for "Title"' in html)
  93. def test_edit(self):
  94. self.browser_do_login('admin', '')
  95. self.browser.go('http://localhost/portal/myfolder/mygeopoint/edit_html')
  96. form = self.browser.get_form('frmEdit')
  97. self.failUnlessEqual(form['title:utf8:ustring'], 'My geopoint')
  98. form['title:utf8:ustring'] = 'new_geopoint_title'
  99. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  100. self.browser.submit()
  101. self.failUnlessEqual(self.portal.myfolder.mygeopoint.title, 'new_geopoint_title')
  102. self.browser.go('http://localhost/portal/myfolder/mygeopoint/edit_html?lang=fr')
  103. form = self.browser.get_form('frmEdit')
  104. form['title:utf8:ustring'] = 'french_title'
  105. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  106. self.browser.submit()
  107. self.failUnlessEqual(self.portal.myfolder.mygeopoint.title, 'new_geopoint_title')
  108. self.failUnlessEqual(self.portal.myfolder.mygeopoint.getLocalProperty('title', 'fr'), 'french_title')
  109. self.browser_do_logout()
  110. def test_edit_error(self):
  111. self.browser_do_login('admin', '')
  112. self.browser.go('http://localhost/portal/myfolder/mygeopoint/edit_html')
  113. form = self.browser.get_form('frmEdit')
  114. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  115. form['title:utf8:ustring'] = ''
  116. self.browser.submit()
  117. html = self.browser.get_html()
  118. self.failUnless('The form contains errors' in html)
  119. self.failUnless('Value required for "Title"' in html)
  120. self.browser_do_logout()
  121. def test_view_in_folder(self):
  122. self.browser_do_login('admin', '')
  123. self.browser.go('http://localhost/portal/myfolder')
  124. html = self.browser.get_html()
  125. soup = BeautifulSoup(html)
  126. tables = soup.findAll('table', id='folderfile_list')
  127. self.assertTrue(len(tables) == 1)
  128. links_to_geopoint = tables[0].findAll('a', attrs={'href': 'http://localhost/portal/myfolder/mygeopoint'})
  129. self.assertTrue(len(links_to_geopoint) == 1)
  130. self.assertTrue(links_to_geopoint[0].string == 'My geopoint')
  131. self.browser_do_logout()
  132. class NyGeoPointVersioningFunctionalTestCase(NaayaFunctionalTestCase):
  133. """ TestCase for NaayaContent object """
  134. def afterSetUp(self):
  135. self.portal.manage_install_pluggableitem('Naaya GeoPoint')
  136. from naaya.content.geopoint.geopoint_item import addNyGeoPoint
  137. addNyGeoPoint(self.portal.info, id='ver_geopoint', title='ver_geopoint',
  138. submitted=1, geo_location=Geo('13', '13'))
  139. import transaction; transaction.commit()
  140. def beforeTearDown(self):
  141. self.portal.info.manage_delObjects(['ver_geopoint'])
  142. self.portal.manage_uninstall_pluggableitem('Naaya GeoPoint')
  143. import transaction; transaction.commit()
  144. def test_start_version(self):
  145. from naaya.content.geopoint.geopoint_item import geopoint_item
  146. self.browser_do_login('admin', '')
  147. self.failUnlessEqual(self.portal.info.ver_geopoint.version, None)
  148. self.browser.go('http://localhost/portal/info/ver_geopoint/startVersion')
  149. self.failUnless(isinstance(self.portal.info.ver_geopoint.version, geopoint_item))
  150. self.browser_do_logout()
  151. def test_edit_version(self):
  152. self.browser_do_login('admin', '')
  153. self.browser.go('http://localhost/portal/info/ver_geopoint/startVersion')
  154. form = self.browser.get_form('frmEdit')
  155. form['title:utf8:ustring'] = 'ver_geopoint_newtitle'
  156. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  157. self.browser.submit()
  158. ver_geopoint = self.portal.info.ver_geopoint
  159. self.failUnlessEqual(ver_geopoint.title, 'ver_geopoint')
  160. # we can't do ver_geopoint.version.title because version objects don't have the _languages property
  161. self.failUnlessEqual(ver_geopoint.version.getLocalProperty('title', 'en'), 'ver_geopoint_newtitle')
  162. self.browser_do_logout()
  163. def test_save_changes_version(self):
  164. self.browser_do_login('admin', '')
  165. self.browser.go('http://localhost/portal/info/ver_geopoint/startVersion')
  166. form = self.browser.get_form('frmEdit')
  167. form['title:utf8:ustring'] = 'ver_geopoint_version'
  168. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  169. self.browser.submit()
  170. form = self.browser.get_form('frmEdit')
  171. self.failUnlessEqual(form['title:utf8:ustring'], 'ver_geopoint_version')
  172. self.browser_do_logout()
  173. def test_suite():
  174. suite = TestSuite()
  175. suite.addTest(makeSuite(NyGeoPointFunctionalTestCase))
  176. suite.addTest(makeSuite(NyGeoPointVersioningFunctionalTestCase))
  177. return suite