PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/naaya/content/mediafile/tests/testFunctional.py

https://github.com/mihneasim/Naaya
Python | 208 lines | 159 code | 24 blank | 25 comment | 2 complexity | 75676ce9e05abe1bbfa3bf91894009bf 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 StringIO import StringIO
  23. from BeautifulSoup import BeautifulSoup
  24. from Products.Naaya.tests.NaayaFunctionalTestCase import NaayaFunctionalTestCase
  25. class NyMediaFileFunctionalTestCase(NaayaFunctionalTestCase):
  26. """ TestCase for NaayaContent object """
  27. def afterSetUp(self):
  28. self.portal.manage_install_pluggableitem('Naaya Media File')
  29. from Products.Naaya.NyFolder import addNyFolder
  30. from naaya.content.mediafile.mediafile_item import addNyMediaFile
  31. addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1)
  32. addNyMediaFile(self.portal.myfolder, id='mymediafile', title='My media file',
  33. submitted=1, contributor='contributor', _skip_videofile_check=True)
  34. import transaction; transaction.commit()
  35. def beforeTearDown(self):
  36. self.portal.manage_delObjects(['myfolder'])
  37. self.portal.manage_uninstall_pluggableitem('Naaya Media File')
  38. import transaction; transaction.commit()
  39. def test_add(self):
  40. self.browser_do_login('contributor', 'contributor')
  41. self.browser.go('http://localhost/portal/myfolder/mediafile_add_html')
  42. self.failUnless('<h1>Submit Media File</h1>' in self.browser.get_html())
  43. form = self.browser.get_form('frmAdd')
  44. expected_controls = set([
  45. 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'coverage:utf8:ustring',
  46. 'keywords:utf8:ustring', 'releasedate', 'discussion:boolean', 'file',
  47. ])
  48. found_controls = set(c.name for c in form.controls)
  49. self.failUnless(expected_controls.issubset(found_controls),
  50. 'Missing form controls: %s' % repr(expected_controls - found_controls))
  51. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  52. form['title:utf8:ustring'] = 'test_create_mediafile'
  53. form['description:utf8:ustring'] = 'test_mediafile_description'
  54. form['coverage:utf8:ustring'] = 'test_mediafile_coverage'
  55. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  56. form.find_control('file').add_file(StringIO('the_FLV_data'),
  57. filename='testvid.flv', content_type='video/x-flv')
  58. self.browser.submit()
  59. html = self.browser.get_html()
  60. self.failUnless('The administrator will analyze your request and you will be notified about the result shortly.' in html)
  61. self.portal.myfolder.testcreatemediafile.approveThis()
  62. self.browser.go('http://localhost/portal/myfolder/testcreatemediafile')
  63. html = self.browser.get_html()
  64. self.failUnless(re.search(r'<h1>.*test_create_mediafile.*</h1>', html, re.DOTALL))
  65. self.failUnless('test_mediafile_description' in html)
  66. self.failUnless('test_mediafile_coverage' in html)
  67. self.failUnless('keyw1, keyw2' in html)
  68. media_id = self.portal.myfolder.testcreatemediafile.getSingleMediaId()
  69. self.failUnlessEqual(media_id, 'testvid.flv')
  70. self.browser.go('http://localhost/portal/myfolder/testcreatemediafile/%s' % media_id)
  71. html = self.browser.get_html()
  72. headers = self.browser._browser._response._headers
  73. self.failUnlessEqual(headers.get('content-type', None), 'application/x-flash-video')
  74. # apparently the test publisher doesn't serve our flv file correctly.
  75. #self.failUnlessEqual(html, 'the_FLV_data')
  76. self.browser_do_logout()
  77. def test_add_error(self):
  78. self.browser_do_login('contributor', 'contributor')
  79. self.browser.go('http://localhost/portal/myfolder/mediafile_add_html')
  80. form = self.browser.get_form('frmAdd')
  81. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  82. # enter no values in the fields
  83. self.browser.submit()
  84. html = self.browser.get_html()
  85. self.failUnless('The form contains errors' in html)
  86. self.failUnless('Value required for "Title"' in html)
  87. self.failUnless('No file was uploaded' in html)
  88. def test_edit(self):
  89. self.browser_do_login('admin', '')
  90. self.browser.go('http://localhost/portal/myfolder/mymediafile/edit_html')
  91. form = self.browser.get_form('frmEdit')
  92. self.failUnlessEqual(form['title:utf8:ustring'], 'My media file')
  93. form['title:utf8:ustring'] = 'new_mediafile_title'
  94. form.find_control('file').add_file(StringIO('the_FLV_data_B'),
  95. filename='testvid_B.flv', content_type='video/x-flv')
  96. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  97. self.browser.submit()
  98. html = self.browser.get_html()
  99. self.failUnless('<h1>Edit Media File</h1>' in html)
  100. self.failUnlessEqual(self.portal.myfolder.mymediafile.title, 'new_mediafile_title')
  101. self.portal.myfolder.mymediafile.approveThis()
  102. media_id = self.portal.myfolder.mymediafile.getSingleMediaId()
  103. self.failUnlessEqual(media_id, 'testvid_B.flv')
  104. self.browser.go('http://localhost/portal/myfolder/mymediafile/%s' % media_id)
  105. html = self.browser.get_html()
  106. headers = self.browser._browser._response._headers
  107. self.failUnlessEqual(headers.get('content-type', None), 'application/x-flash-video')
  108. # apparently the test publisher doesn't serve our flv file correctly.
  109. #self.failUnlessEqual(html, 'the_FLV_data_B')
  110. self.browser.go('http://localhost/portal/myfolder/mymediafile/edit_html?lang=fr')
  111. form = self.browser.get_form('frmEdit')
  112. form['title:utf8:ustring'] = 'french_title'
  113. form.find_control('file').add_file(StringIO('the_FLV_data_C'),
  114. filename='testvid_C.flv', content_type='video/x-flv')
  115. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  116. self.browser.submit()
  117. self.failUnless('Saved changes' in self.browser.get_html())
  118. media_id = self.portal.myfolder.mymediafile.getSingleMediaId()
  119. self.failUnlessEqual(media_id, 'testvid_B.flv') # the file is not renamed - is this correct?
  120. self.browser.go('http://localhost/portal/myfolder/mymediafile/%s' % media_id)
  121. html = self.browser.get_html()
  122. headers = self.browser._browser._response._headers
  123. self.failUnlessEqual(headers.get('content-type', None), 'application/x-flash-video')
  124. # apparently the test publisher doesn't serve our flv file correctly.
  125. #self.failUnlessEqual(html, 'the_FLV_data_C')
  126. self.failUnlessEqual(self.portal.myfolder.mymediafile.title, 'new_mediafile_title')
  127. self.failUnlessEqual(self.portal.myfolder.mymediafile.getLocalProperty('title', 'fr'), 'french_title')
  128. self.browser_do_logout()
  129. def test_edit_error(self):
  130. self.browser_do_login('admin', '')
  131. self.browser.go('http://localhost/portal/myfolder/mymediafile/edit_html')
  132. form = self.browser.get_form('frmEdit')
  133. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  134. form['title:utf8:ustring'] = ''
  135. self.browser.submit()
  136. html = self.browser.get_html()
  137. self.failUnless('The form contains errors' in html)
  138. self.failUnless('Value required for "Title"' in html)
  139. self.browser_do_logout()
  140. def test_manage(self):
  141. self.browser_do_login('admin', '')
  142. self.browser.go('http://localhost/portal/myfolder/mymediafile/manage_edit_html')
  143. form = self.browser.get_form('frmEdit')
  144. # TODO: title control should be 'title:utf8:ustring'
  145. self.failUnlessEqual(form['title'], 'My media file')
  146. form['title'] = 'new_mediafile_title'
  147. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  148. self.browser.submit()
  149. self.failUnlessEqual(self.portal.myfolder.mymediafile.title, 'new_mediafile_title')
  150. self.browser_do_logout()
  151. def test_view_in_folder(self):
  152. self.browser_do_login('admin', '')
  153. self.browser.go('http://localhost/portal/myfolder')
  154. html = self.browser.get_html()
  155. soup = BeautifulSoup(html)
  156. tables = soup.findAll('table', id='folderfile_list')
  157. self.assertTrue(len(tables) == 1)
  158. links_to_mediafile = tables[0].findAll('a', attrs={'href': 'http://localhost/portal/myfolder/mymediafile'})
  159. self.assertTrue(len(links_to_mediafile) == 1)
  160. self.assertTrue(links_to_mediafile[0].string == 'My media file')
  161. self.browser_do_logout()
  162. def test_suite():
  163. suite = TestSuite()
  164. suite.addTest(makeSuite(NyMediaFileFunctionalTestCase))
  165. return suite