PageRenderTime 66ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/eggs/naaya.content.youtube/naaya/content/youtube/tests/testFunctional.py

https://github.com/eaudeweb/Naaya
Python | 151 lines | 132 code | 16 blank | 3 comment | 2 complexity | 7a8acc70c00a134bc8b091ebd6cd33d7 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. import re
  2. from BeautifulSoup import BeautifulSoup
  3. from Products.Naaya.tests.NaayaFunctionalTestCase import NaayaFunctionalTestCase
  4. class NyYoutubeFunctionalTestCase(NaayaFunctionalTestCase):
  5. """ TestCase for NaayaContent object """
  6. def afterSetUp(self):
  7. self.portal.manage_install_pluggableitem('Naaya Youtube')
  8. from Products.Naaya.NyFolder import addNyFolder
  9. from naaya.content.youtube.youtube_item import addNyYoutube
  10. addNyFolder(self.portal, 'myfolder', contributor='contributor',
  11. submitted=1)
  12. addNyYoutube(self.portal.myfolder, id='myyoutube',
  13. title='My Youtube Video', submitted=1, contributor='contributor',
  14. youtube_id='uelHwf8o7_U', iframe_width='640', iframe_height='360')
  15. import transaction; transaction.commit()
  16. def beforeTearDown(self):
  17. self.portal.manage_delObjects(['myfolder'])
  18. self.portal.manage_uninstall_pluggableitem('Naaya Youtube')
  19. import transaction; transaction.commit()
  20. def test_add(self):
  21. self.browser_do_login('contributor', 'contributor')
  22. self.browser.go('http://localhost/portal/info/youtube_add_html')
  23. self.failUnless('<h1>Embed YouTube video</h1>' in self.browser.get_html())
  24. form = self.browser.get_form('frmAdd')
  25. expected_controls = set([
  26. 'lang', 'title:utf8:ustring', 'description:utf8:ustring', 'coverage:utf8:ustring',
  27. 'keywords:utf8:ustring', 'releasedate', 'discussion:boolean',
  28. ])
  29. found_controls = set(c.name for c in form.controls)
  30. self.failUnless(expected_controls.issubset(found_controls),
  31. 'Missing form controls: %s' % repr(expected_controls - found_controls))
  32. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  33. form['title:utf8:ustring'] = 'test_youtube'
  34. form['description:utf8:ustring'] = 'test_youtube_description'
  35. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  36. form['youtube_id:utf8:ustring'] = 'uelHwf8o7_U'
  37. self.browser.submit()
  38. html = self.browser.get_html()
  39. self.failUnless('The administrator will analyze your request and you will be notified about the result shortly.' in html)
  40. self.portal.info.test_youtube.approveThis()
  41. self.browser.go('http://localhost/portal/info/test_youtube')
  42. html = self.browser.get_html()
  43. self.failUnless(re.search(r'<h1>.*test_youtube.*</h1>', html, re.DOTALL))
  44. self.failUnless('test_youtube_description' in html)
  45. self.browser_do_logout()
  46. def test_add_error(self):
  47. self.browser_do_login('contributor', 'contributor')
  48. self.browser.go('http://localhost/portal/myfolder/youtube_add_html')
  49. form = self.browser.get_form('frmAdd')
  50. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  51. # enter no values in the fields
  52. self.browser.submit()
  53. html = self.browser.get_html()
  54. self.failUnless('The form contains errors' in html)
  55. self.failUnless('Value required for "Title"' in html)
  56. form = self.browser.get_form('frmAdd')
  57. self.browser.clicked(form, self.browser.get_form_field(form, 'title'))
  58. form['title:utf8:ustring'] = 'test_youtube'
  59. form['description:utf8:ustring'] = 'test_youtube_description'
  60. form['keywords:utf8:ustring'] = 'keyw1, keyw2'
  61. # enter an invalid Youtube ID
  62. form['youtube_id:utf8:ustring'] = 'aaaaaaaaaaa'
  63. self.browser.submit()
  64. html = self.browser.get_html()
  65. self.failUnless('The form contains errors' in html)
  66. self.failUnless('Invalid Youtube ID (inexisting video)' in html)
  67. def test_edit(self):
  68. self.browser_do_login('admin', '')
  69. self.browser.go('http://localhost/portal/myfolder/myyoutube/edit_html')
  70. form = self.browser.get_form('frmEdit')
  71. self.failUnlessEqual(form['title:utf8:ustring'], 'My Youtube Video')
  72. form['title:utf8:ustring'] = 'new_youtube_title'
  73. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  74. self.browser.submit()
  75. self.failUnlessEqual(self.portal.myfolder.myyoutube.title, 'new_youtube_title')
  76. self.browser.go('http://localhost/portal/myfolder/myyoutube/edit_html?lang=fr')
  77. form = self.browser.get_form('frmEdit')
  78. form['title:utf8:ustring'] = 'french_title'
  79. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  80. self.browser.submit()
  81. self.failUnlessEqual(self.portal.myfolder.myyoutube.title, 'new_youtube_title')
  82. self.failUnlessEqual(self.portal.myfolder.myyoutube.getLocalProperty('title', 'fr'), 'french_title')
  83. self.browser_do_logout()
  84. def test_edit_error(self):
  85. self.browser_do_login('admin', '')
  86. self.browser.go('http://localhost/portal/myfolder/myyoutube/edit_html')
  87. form = self.browser.get_form('frmEdit')
  88. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  89. form['title:utf8:ustring'] = ''
  90. self.browser.submit()
  91. html = self.browser.get_html()
  92. self.failUnless('The form contains errors' in html)
  93. self.failUnless('Value required for "Title"' in html)
  94. self.browser_do_logout()
  95. def test_manage(self):
  96. self.browser_do_login('admin', '')
  97. self.browser.go('http://localhost/portal/myfolder/myyoutube/manage_edit_html')
  98. form = self.browser.get_form('frmEdit')
  99. self.failUnlessEqual(form['title:utf8:ustring'], 'My Youtube Video')
  100. form['title:utf8:ustring'] = 'new_youtube_title'
  101. self.browser.clicked(form, self.browser.get_form_field(form, 'title:utf8:ustring'))
  102. self.browser.submit()
  103. self.failUnlessEqual(self.portal.myfolder.myyoutube.title, 'new_youtube_title')
  104. self.browser_do_logout()
  105. def test_view_in_folder(self):
  106. self.browser_do_login('admin', '')
  107. self.browser.go('http://localhost/portal/myfolder')
  108. html = self.browser.get_html()
  109. soup = BeautifulSoup(html)
  110. tables = soup.findAll('table', id='folderfile_list')
  111. self.assertTrue(len(tables) == 1)
  112. links_to_youtube = tables[0].findAll('a', attrs={'href': 'http://localhost/portal/myfolder/myyoutube'})
  113. self.assertTrue(len(links_to_youtube) == 1)
  114. self.assertTrue(links_to_youtube[0].string == 'My Youtube Video')
  115. self.browser_do_logout()