PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/obsolete/old/naaya2zope210/NaayaContent/NyURL/tests/testNyURL.py

https://github.com/eaudeweb/Naaya
Python | 233 lines | 211 code | 19 blank | 3 comment | 4 complexity | 885c99c4039db3ea834d98a1f19e461b MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. from Products.Naaya.tests.NaayaTestCase import NaayaTestCase
  2. from Products.Naaya import NyFolder
  3. from unittest import TestSuite, makeSuite
  4. from Products.NaayaContent.NyURL import NyURL
  5. class TestNyURL(NaayaTestCase):
  6. def afterSetUp(self):
  7. NyFolder.addNyFolder(self.app.portal, "test_folder")
  8. pass
  9. def beforeTearDown(self):
  10. self.app.portal.manage_delObjects("test_folder")
  11. def test_addNyURL_nologin(self):
  12. """
  13. Test adding URL without being logged in
  14. """
  15. NyURL.addNyURL(self.app.portal.test_folder, title="testURL")
  16. self.assertFalse(hasattr(self.app.portal.test_folder, "testURL"))
  17. def test_addNyURL_no_requiredattrs(self):
  18. self.login("contributor")
  19. self.failUnlessRaises(ValueError, lambda: NyURL.addNyURL(self.app.portal.test_folder))
  20. self.assertFalse(hasattr(self.app.portal.test_folder, "testURL"))
  21. self.logout()
  22. def test_addNyURL_has_requiredattrs(self):
  23. self.login("contributor")
  24. id = NyURL.addNyURL(self.app.portal.test_folder, title="test1", locator="www.google.com")
  25. self.assertTrue(hasattr(self.app.portal.test_folder, "test1"), "URL object test1 was not found in folder 'test_folder'")
  26. meta = self._portal().getCatalogedObjectsCheckView(meta_type=["Naaya URL"])
  27. test1 = None
  28. for url in meta:
  29. if url.title == "test1":
  30. test1 = url
  31. self.assertNotEqual(test1, None, "URL not found via CatalogedObjectsCheckView")
  32. self.assertEqual(test1.title, "test1")
  33. self.assertEqual(test1.locator, "www.google.com")
  34. self.logout()
  35. def test_addNyURL_duplicates(self):
  36. self.login("contributor")
  37. NyURL.addNyURL(self.app.portal.test_folder, id="urldup1", title="urldup1", locator="www.google.com")
  38. self.assertTrue(hasattr(self.app.portal.test_folder, "urldup1"), "URL object urldup1 was not found in folder 'test_folder'")
  39. NyURL.addNyURL(self.app.portal.test_folder, id="urldup1", title="urldup1", locator="www.google.com")
  40. self.assertTrue(hasattr(self.app.portal.test_folder, "urldup1-1"), "URL object urldup1 was not found in folder 'test_folder'")
  41. self.logout()
  42. def test_addNyURL_fullattrs(self):
  43. import time
  44. self.login("contributor")
  45. time.sleep(1)
  46. NyURL.addNyURL(self.app.portal.test_folder,
  47. id="test2",
  48. title="test2",
  49. description = "description",
  50. coverage = "coverage",
  51. keywords = "keyword1, keywords2",
  52. sortorder = 1,
  53. locator="www.google.com",
  54. contributor = "cristiroma",
  55. releasedate = "30/04/2008",
  56. discussion = 1,
  57. lang = "ar"
  58. )
  59. self.assertTrue(hasattr(self.app.portal.test_folder, "test2"), "URL object test2 was not found in folder 'test_folder'")
  60. meta = self._portal().getCatalogedObjectsCheckView(meta_type=["Naaya URL"])
  61. test2 = None
  62. for url in meta:
  63. if url.getLocalProperty("title", "ar") == "test2":
  64. test2 = url
  65. self.assertTrue(test2 != None, "URL not found via CatalogedObjectsCheckView")
  66. self.assertEqual(test2.id, "test2")
  67. self.assertEqual(test2.getLocalProperty("title", "ar"), "test2")
  68. self.assertEqual(test2.getLocalProperty("description", "ar"), "description")
  69. self.assertEqual(test2.getLocalProperty("coverage", "ar"), "coverage")
  70. self.assertEqual(test2.getLocalProperty("keywords", "ar"), "keyword1, keywords2")
  71. self.assertEqual(test2.sortorder, 1)
  72. self.assertEqual(test2.getLocalProperty("locator", "ar"), "www.google.com")
  73. self.assertEqual(test2.contributor, "cristiroma")
  74. self.assertEqual(test2.releasedate.day(), 30, "Release day does not match")
  75. self.assertEqual(test2.releasedate.month(), 4, "Release month does not match")
  76. self.assertEqual(test2.releasedate.year(), 2008, "Release year does not match")
  77. self.assertEqual(test2.discussion, 1)
  78. self.logout()
  79. def test_importNyURL(self):
  80. attrs = {"sortorder" : "1",
  81. "contributor" : "contributor",
  82. "discussion" : "1",
  83. "approved" : "1",
  84. "approved_by" : "contributor",
  85. "releasedate" : "30/04/2008",
  86. "validation_status" : "None",
  87. "validation_comment" : "OK",
  88. "validation_by" : "contributor",
  89. "validation_date" : "30/04/2008"}
  90. id = "url3"
  91. param = 0;
  92. self.app.portal.test_folder.importNyURL(param, id, attrs, '', {}, None, None)
  93. self.assertTrue(hasattr(self.app.portal.test_folder, "url3"), "URL object url3 was not found in folder 'test_folder'")
  94. def test_export_this_tag_custom(self):
  95. import re
  96. self.login("contributor")
  97. NyURL.addNyURL(self.app.portal.test_folder, title="urlx", contributor="cristiroma", locator="www.google.com")
  98. url = self.app.portal.test_folder.urlx
  99. self.app.portal.test_folder.validateObject(id="urlx", status="-1", comment="No comment")
  100. exportStr = url.export_this_tag_custom()
  101. strre=re.compile(exportStr, re.IGNORECASE)
  102. self.assertTrue(exportStr.find('validation_status="-1"') >= 0, "Exported custom tag is malformed")
  103. #TODO: self.assertTrue(strre.search('validation_date') != None, "Exported custom tag is malformed")
  104. self.assertTrue(exportStr.find('validation_by="contributor"') >= 0, "Exported custom tag is malformed")
  105. self.assertTrue(exportStr.find('validation_comment="No comment"') >= 0, "Exported custom tag is malformed")
  106. self.logout()
  107. def test_export_this_body_custom(self):
  108. self.login("contributor")
  109. NyURL.addNyURL(self.app.portal.test_folder, title="urly", contributor="cristiroma", locator="www.google.com")
  110. url = self.app.portal.test_folder.urly
  111. exportStr = url.export_this_body_custom()
  112. self.assertTrue(exportStr == '<locator lang="en"><![CDATA[www.google.com]]></locator>', "Exported custom body is malformed")
  113. self.logout()
  114. def test_startVersion(self):
  115. import traceback
  116. self.login("contributor")
  117. NyURL.addNyURL(self.app.portal.test_folder,
  118. id="test2",
  119. title="test2",
  120. description = "description",
  121. coverage = "coverage",
  122. keywords = "keyword1, keywords2",
  123. sortorder = 1,
  124. locator="www.google.com",
  125. contributor = "cristiroma",
  126. releasedate = "30/04/2008",
  127. discussion = 1,
  128. lang = "ar"
  129. )
  130. url = self.app.portal.test_folder.test2
  131. #Contributor is not allowed to start versioning
  132. # TODO: fix this test
  133. #try:
  134. # url.startVersion()
  135. # self.fail()
  136. #except:
  137. # pass
  138. self.logout()
  139. self.login()
  140. url.startVersion()
  141. url.saveProperties(
  142. title='test22',
  143. description='',
  144. coverage='',
  145. keywords='',
  146. sortorder=10,
  147. locator='www.yahoo.com',
  148. releasedate='02/02/2003',
  149. discussion=0,
  150. lang="ar")
  151. self.assertEqual(url.id, "test2")
  152. self.assertEqual(url.getLocalProperty("title", "ar"), "test2")
  153. self.assertEqual(url.getLocalProperty("description", "ar"), "description")
  154. self.assertEqual(url.getLocalProperty("coverage", "ar"), "coverage")
  155. self.assertEqual(url.getLocalProperty("keywords", "ar"), "keyword1, keywords2")
  156. self.assertEqual(url.sortorder, 1)
  157. self.assertEqual(url.getLocalProperty("locator", "ar"), "www.google.com")
  158. self.assertEqual(url.contributor, "cristiroma")
  159. self.assertEqual(url.releasedate.day(), 30, "Release day does not match")
  160. self.assertEqual(url.releasedate.month(), 4, "Release month does not match")
  161. self.assertEqual(url.releasedate.year(), 2008, "Release year does not match")
  162. #Discussion field passes the versioning system, no need to test self.assertEqual(url.discussion, 1)
  163. url.commitVersion()
  164. self.assertEqual(url.id, "test2")
  165. self.assertEqual(url.getLocalProperty("title", "ar"), "test22")
  166. self.assertEqual(url.getLocalProperty("description", "ar"), "")
  167. self.assertEqual(url.getLocalProperty("coverage", "ar"), "")
  168. self.assertEqual(url.getLocalProperty("keywords", "ar"), "")
  169. self.assertEqual(url.sortorder, 10)
  170. self.assertEqual(url.getLocalProperty("locator", "ar"), "www.yahoo.com")
  171. self.assertEqual(url.contributor, "cristiroma")
  172. self.assertEqual(url.releasedate.day(), 2, "Release day does not match")
  173. self.assertEqual(url.releasedate.month(), 2, "Release month does not match")
  174. self.assertEqual(url.releasedate.year(), 2003, "Release year does not match")
  175. #Discussion field passes the versioning system, no noeed to test self.assertEqual(url.discussion, 0)
  176. url.startVersion()
  177. url.saveProperties(
  178. title='1',
  179. description='1',
  180. coverage='1',
  181. keywords='1',
  182. sortorder=1,
  183. locator='1',
  184. releasedate='03/03/2004',
  185. discussion=1,
  186. lang="ar")
  187. url.discardVersion()
  188. self.assertEqual(url.id, "test2")
  189. self.assertEqual(url.getLocalProperty("title", "ar"), "test22")
  190. self.assertEqual(url.getLocalProperty("description", "ar"), "")
  191. self.assertEqual(url.getLocalProperty("coverage", "ar"), "")
  192. self.assertEqual(url.getLocalProperty("keywords", "ar"), "")
  193. self.assertEqual(url.sortorder, 10)
  194. self.assertEqual(url.getLocalProperty("locator", "ar"), "www.yahoo.com")
  195. self.assertEqual(url.contributor, "cristiroma")
  196. self.assertEqual(url.releasedate.day(), 2, "Release day does not match")
  197. self.assertEqual(url.releasedate.month(), 2, "Release month does not match")
  198. self.assertEqual(url.releasedate.year(), 2003, "Release year does not match")
  199. def test_suite():
  200. suite = TestSuite()
  201. suite.addTest(makeSuite(TestNyURL))
  202. return suite