testUNG.py 17.2 KB
Newer Older
Gabriel Monnerat's avatar
Gabriel Monnerat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
##############################################################################
#
# Copyright (c) 2002-2011 Nexedi SA and Contributors. All Rights Reserved.
#                         Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
30
from DateTime import DateTime
31
import re
32
import json
33

Gabriel Monnerat's avatar
Gabriel Monnerat committed
34 35 36 37 38 39 40 41 42 43 44 45

class TestUNG(ERP5TypeTestCase):
  """
    UNG Test Case
  """

  def getTitle(self):
    return "UNG Tests"

  def getBusinessTemplateList(self):
    return ('erp5_base',
            'erp5_web',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
46
            'erp5_ingestion_mysql_innodb_catalog',
47
            'erp5_core_proxy_field_legacy',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
48
            'erp5_ingestion',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
49
            'erp5_dms',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
50 51
            'erp5_crm',
            'erp5_knowledge_pad',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
52 53
            'erp5_jquery',
            'erp5_jquery_ui',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
54
            'erp5_jquery_plugin_spinbtn',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
55 56
            'erp5_jquery_plugin_jgraduate',
            'erp5_jquery_plugin_svgicon',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
57
            'erp5_jquery_plugin_hotkey',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
58 59
            'erp5_jquery_plugin_jquerybbq',
            'erp5_jquery_plugin_svg_editor',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
60 61 62 63 64
            'erp5_jquery_plugin_sheet',
            'erp5_jquery_plugin_mbmenu',
            'erp5_jquery_plugin_jqchart',
            'erp5_jquery_plugin_colorpicker',
            'erp5_jquery_plugin_elastic',
Rafael Monnerat's avatar
Rafael Monnerat committed
65
            'erp5_jquery_plugin_wdcalendar',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
66
            'erp5_jquery_sheet_editor',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
67
            'erp5_xinha_editor',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
68
            'erp5_svg_editor',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
69
            'erp5_web_ung_core',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
70
            'erp5_web_ung_theme',)
Gabriel Monnerat's avatar
Gabriel Monnerat committed
71

72 73 74 75
  def afterSetUp(self):
    """Clean up form"""
    self.portal.REQUEST.form.clear()

76 77
  def assertCreateDocumentUsingTemplate(self, template, **kw):
    web_page_module = self.portal.web_page_module
Gabriel Monnerat's avatar
Gabriel Monnerat committed
78
    self.portal.ERP5Site_createNewWebDocument(template)
79 80 81 82 83 84
    self.stepTic()
    web_page_search = web_page_module.searchFolder(**kw)
    self.assertEquals(1, len(web_page_search))

  def getTitleListToBySubjectDomain(self):
    parent = self.portal.portal_domains.ung_domain.by_subject
85
    return [domain.getTitle() for domain in self.portal.ERP5Site_generateDomain(0, parent)]
Gabriel Monnerat's avatar
Gabriel Monnerat committed
86 87

  def testERP5Site_createNewWebDocument(self):
88
    """Test if the script creates the objects using Templates correctly"""
89
    web_page_module = self.portal.web_page_module
90
    self.assertCreateDocumentUsingTemplate("web_page_template",
91 92
                                           portal_type="Web Page",
                                           reference="default-Web.Page.Reference")
93
    self.assertCreateDocumentUsingTemplate("web_table_template",
94 95
                                           portal_type="Web Table",
                                           reference="default-Web.Table.Reference")
96
    self.assertCreateDocumentUsingTemplate("web_illustration_template",
97 98 99
                                           portal_type="Web Illustration",
                                           reference="default-Web.Illustration.Reference")

100 101
  def testERP5Site_generateDomain(self):
    """Test if script ERP5Site_generateDomain generates the list of
102
    domains correctly"""
103 104 105 106 107 108
    web_page = self.portal.web_page_module.newContent(portal_type="Web Page")
    self.stepTic()
    title_list = self.getTitleListToBySubjectDomain()
    self.assertFalse("Ung" in title_list)
    web_page.setSubjectList("Ung")
    self.stepTic()
109 110
    # The script uses cache (short) to store the results
    self.portal.portal_caches.clearAllCache()
111
    title_list = self.getTitleListToBySubjectDomain()
Rafael Monnerat's avatar
Rafael Monnerat committed
112
    self.assertTrue("Ung" in title_list, title_list)
Gabriel Monnerat's avatar
Gabriel Monnerat committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

  def testBase_changeWorkflowState(self):
    """Test if script change the state of object correctly"""
    web_table = self.portal.web_page_module.newContent(portal_type="Web Table")
    web_table.Base_changeWorkflowState("publish_action")
    self.stepTic()
    self.assertEquals(web_table.getValidationState(), "published")
    web_table.Base_changeWorkflowState("reject_action")
    self.assertEquals(web_table.getValidationState(), "draft")

  def testWebPage_getUNGIcon(self):
    """Test if the paths are returned correctly"""
    web_page = self.portal.web_page_module.newContent(portal_type="Web Page")
    web_table = self.portal.web_page_module.newContent(portal_type="Web Table")
    web_illustration = self.portal.web_page_module.newContent(portal_type="Web Illustration")
    self.stepTic()
    self.assertEquals(web_page.WebPage_getUNGIcon(),
                      "<img src='ung_images/document.gif'/>")
    self.assertEquals(web_table.WebPage_getUNGIcon(),
                      "<img src='ung_images/table.jpg'/>")
    self.assertEquals(web_illustration.WebPage_getUNGIcon(),
                      "<img src='ung_images/svg.png'/>")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
135 136 137 138

  def testWebSection_deleteObjectList(self):
    """Test if objects are deleted correctly"""
    web_page = self.portal.web_page_module.newContent(portal_type="Web Page")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
139
    relative_url = web_page.getRelativeUrl()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
140 141 142 143
    self.portal.REQUEST.set("uids", [web_page.getUid(),])
    self.stepTic()
    self.portal.WebSection_deleteObjectList()
    self.stepTic()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
144 145 146 147 148 149
    self.assertEquals(web_page.getValidationState(), "deleted")
    self.portal.REQUEST.set("uids", [web_page.getUid(),])
    self.stepTic()
    self.portal.WebSection_deleteObjectList()
    self.stepTic()
    self.assertEquals(len(self.portal.portal_catalog(relative_url=relative_url)), 0)
Gabriel Monnerat's avatar
Gabriel Monnerat committed
150

151
  def testERP5Site_userFollowUpWebPage(self):
152
    """Test if user is added in field Follow Up of Web Page"""
Gabriel Monnerat's avatar
Gabriel Monnerat committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166
    web_page = self.portal.web_page_module.newContent(portal_type="Web Page")
    web_page.setReference("new.Web-Page")
    self.stepTic()
    portal = self.portal
    person = portal.person_module.newContent(portal_type='Person',
                                             reference="ung_new_user")
    assignment = person.newContent(portal_type='Assignment')
    assignment.open()
    person = portal.person_module.newContent(portal_type='Person',
                                             reference="ung_new_user2")
    assignment = person.newContent(portal_type='Assignment')
    assignment.open()
    self.stepTic()
    self.login("ung_new_user")
167
    self.portal.ERP5Site_userFollowUpWebPage("new.Web-Page")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
168
    self.stepTic()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
169 170
    self.login("ERP5TypeTestCase")
    self.assertEquals("ung_new_user", web_page.getFollowUpValue().getReference())
Gabriel Monnerat's avatar
Gabriel Monnerat committed
171
    self.login("ung_new_user2")
172
    self.portal.ERP5Site_userFollowUpWebPage("new.Web-Page")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
173
    self.stepTic()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
174 175 176 177
    self.login("ERP5TypeTestCase")
    reference_list = [user.getReference() for user in web_page.getFollowUpValueList()]
    self.assertEquals(["ung_new_user", "ung_new_user2"],
                      sorted(reference_list))
Gabriel Monnerat's avatar
Gabriel Monnerat committed
178 179

  def testWebSection_getGadgetPathList(self):
180
    """Validate the gadget list"""
181
    gadget_list = json.loads((self.portal.WebSection_getGadgetPathList()))
Gabriel Monnerat's avatar
Gabriel Monnerat committed
182 183 184 185 186
    for gadget in gadget_list:
      url = gadget.get("image_url").split("?")[0]
      url = url.replace("/default_image", "")
      catalog_result = self.portal.portal_catalog(relative_url=url)
      self.assertEquals(len(catalog_result), 1)
187 188 189
      self.assertEquals(catalog_result[0].getTitle(), gadget.get('title'))

  def testEventModule_createNewEvent(self):
190
    """Test if script creates correctly a new event"""
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    portal = self.portal
    event_dict = dict(portal_type="Note",
                      title="Buy Phone",
                      event_text_content="testUNG Sample",
                      start_date_hour=11,
                      start_date_minute=12,
                      start_date_day=12,
                      start_date_month=02,
                      start_date_year=2011,
                      stop_date_hour=12,
                      stop_date_minute=12,
                      stop_date_day=13,
                      stop_date_month=02,
                      stop_date_year=2011)
    portal.REQUEST.form.update(event_dict)
    portal.event_module.EventModule_createNewEvent()
    self.stepTic()
    event = portal.portal_catalog.getResultValue(portal_type="Note")
    self.assertEquals(event.getDescription(), "testUNG Sample")
    start_date = event.getStartDate()
    self.assertEquals(start_date.month(), 2)
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    self.assertEquals(start_date.minute(), 12)

  def testWebPage_setSubjectList(self):
    """Test if string is inserted as subjects in object correctly"""
    web_table = self.portal.web_page_module.newContent(portal_type="Web Table")
    self.stepTic()
    web_table.WebPage_setSubjectList("VPN")
    self.stepTic()
    subject_list = web_table.getSubjectList()
    self.assertEquals(["VPN"], subject_list)
    web_table.WebPage_setSubjectList("VPN,ERP5")
    self.stepTic()
    subject_list = web_table.getSubjectList()
    self.assertEquals(["ERP5", "VPN"], sorted(subject_list))

  def testWebSection_getDocumentUrl(self):
    """Test if script used to generated custom url to listbox works
    correctly"""
    web_illustration = self.portal.web_page_module.newContent(portal_type="Web Illustration")
    web_page = self.portal.web_page_module.newContent(portal_type="Web Page")
    self.stepTic()
    kw = dict(brain=web_illustration)
    url = self.portal.WebSection_getDocumentUrl(**kw)
    pattern = "^http.*\/web_page_module\/[0-9]+\/WebIllustration_viewEditor\?editable_mode\:int\=1"
    self.assertNotEquals(re.search(pattern, url), None)
    kw = dict(brain=web_page)
    url = self.portal.WebSection_getDocumentUrl(**kw)
    pattern = "^http.*\/web_page_module\/[0-9]+\/WebPage_viewEditor\?editable_mode\:int\=1"
    self.assertNotEquals(re.search(pattern, url), None, url)
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
 
  def testBase_updateCalendarEventList(self):
    """Test script used to manage events in UNG Calendar """
    event_dict = json.loads(self.portal.Base_updateCalendarEventList("list"))
    self.assertEquals(event_dict.get("events"), [])
    event = self.portal.event_module.newContent(portal_type="Note")
    event.setStartDate(DateTime())
    event.setStopDate(DateTime()+1)
    self.stepTic()
    event_dict = json.loads(self.portal.Base_updateCalendarEventList("list"))
    event_list = event_dict.get("events")
    self.assertEquals(event_list[0][-2], "Note")
    form_dict = dict(CalendarStartTime=DateTime().strftime("%m/%d/%Y %H:%M"),
                     CalendarEndTime=DateTime().strftime("%m/%d/%Y %H:%M"),
                     CalendarTitle="One Sample",
                     portal_type="Web Message")
    self.portal.REQUEST.form.update(form_dict)
    self.portal.Base_updateCalendarEventList("add")
    self.stepTic()
    web_message = self.portal.portal_catalog.getResultValue(portal_type="Web Message")
    self.assertEquals(web_message.getTitle(), "One Sample")
    self.portal.REQUEST.form.clear()
    form_dict = dict(CalendarStartTime=DateTime().strftime("%m/%d/%Y %H:%M"),
                     CalendarEndTime=DateTime().strftime("%m/%d/%Y %H:%M"),
                     title="Buy Coffee",
                     event_id=web_message.getId())
    self.portal.REQUEST.form.update(form_dict)
    self.portal.Base_updateCalendarEventList("update")
    self.stepTic()
    self.assertEquals(web_message.getTitle(), "Buy Coffee")
    self.portal.REQUEST.form.clear()
    form_dict = dict(title=web_message.getTitle(),
                     id=web_message.getId())
    self.portal.REQUEST.form.update(form_dict)
    self.portal.Base_updateCalendarEventList("remove")
    self.stepTic()
    web_message = self.portal.portal_catalog.getResultValue(portal_type="Web Message")
    self.assertEquals(web_message, None)
Gabriel Monnerat's avatar
Gabriel Monnerat committed
279 280 281 282 283
  
  def testERPSite_createUNGUser(self):
    """Test if script creates an user correctly"""
    form_dict = dict(firstname="UNG",
                     lastname="User",
284 285
                     email="g@g.com",
                     password="ung_password",
Gabriel Monnerat's avatar
Gabriel Monnerat committed
286
                     login_name="ung_user")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
287
    self.portal.REQUEST.form.update(form_dict)
288 289
    response = json.loads(self.portal.ERPSite_createUNGUser())
    self.assertTrue(response)
Gabriel Monnerat's avatar
Gabriel Monnerat committed
290 291 292 293
    self.stepTic()
    person = self.portal.portal_catalog.getResultValue(portal_type="Person",
                                                       first_name="UNG")
    self.assertEquals(person.getLastName(), "User")
294 295
    self.assertEquals(person.getValidationState(), "validated")
    self.assertEquals(person.getEmail().getPortalType(), "Email")
296
    self.assertEquals(person.getEmailText(), "g@g.com")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
297
    self.assertEquals(person.getReference(), "ung_user")
298 299
    response = json.loads(self.portal.ERPSite_createUNGUser())
    self.assertEquals(response, None)
300

Gabriel Monnerat's avatar
Gabriel Monnerat committed
301 302 303 304 305 306 307 308
  def testERP5Site_checkIfUserExistUsingHttpRequest(self):
    """Test script ERP5Site_checkIfUserExist to simulate the browser request"""
    script_path = self.portal.web_site_module.ung.getPath() + "/ERP5Site_checkIfUserExist"
    response = json.loads(self.publish(script_path).getBody())
    self.assertEquals(response, {'response': False})
    response = json.loads(self.publish(script_path + "?reference=ung_reference").getBody())
    self.assertEquals(response, {'response': True})

309 310
  def testERP5Site_checkIfUserExist(self):
    """Test script ERP5Site_checkIfUserExist"""
311 312 313 314
    portal = self.portal
    form_dict = dict(firstname="UNG",
                     lastname="User",
                     email="g@g.com",
Gabriel Monnerat's avatar
Gabriel Monnerat committed
315
                     login_name="ung_reference")
316 317
    portal.REQUEST.form.update(form_dict)
    portal.ERPSite_createUNGUser()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
318
    kw = dict(reference=form_dict["login_name"],)
319
    response = json.loads(portal.ERP5Site_checkIfUserExist(**kw))
320 321
    self.assertEquals(response.get("response"), False)
    self.stepTic()
Gabriel Monnerat's avatar
Gabriel Monnerat committed
322
    param_list = ["%s=%s" % (key,value) for key, value in kw.iteritems()]
323
    response = json.loads(portal.ERP5Site_checkIfUserExist(**kw))
324 325 326 327
    self.assertEquals(response.get("response"), True)
    kw = dict(first_name="Not Exist",
              reference="no_reference",
             )
328
    response = json.loads(portal.ERP5Site_checkIfUserExist(**kw))
Gabriel Monnerat's avatar
Gabriel Monnerat committed
329 330 331
    self.assertEquals(response.get("response"), False)
    self.login("ung_reference")
    user = portal.ERP5Site_getAuthenticatedMemberPersonValue()
332
    self.assertEquals(user.getFirstName(), "UNG")
333 334 335 336

  def testWebSection_addGadget(self):
    """Test if gadgets are added correctly"""
    obj = self.portal.knowledge_pad_module.newContent(portal_type="Knowledge Pad")
Gabriel Monnerat's avatar
Gabriel Monnerat committed
337
    obj.edit(publication_section_value=self.portal.web_site_module.ung)
338 339 340 341 342 343 344 345
    obj.visible()
    self.stepTic()
    gadget = self.portal.portal_gadgets.searchFolder()[0]
    gadget_id = gadget.getId()
    self.portal.web_site_module.ung.WebSection_addGadget(gadget_id)
    self.stepTic()
    gadget = self.portal.portal_catalog.getResultValue(portal_type="Gadget",
                                                       validation_state="visible")
346 347 348 349 350 351 352 353 354 355 356 357
    self.assertEquals(gadget_id, gadget.getId())

  def testBase_getPreferencePathList(self):
    """Test if the paths of preference objects are returned correctly"""
    self.logout()
    self.assertEquals(json.loads(self.portal.Base_getPreferencePathList()), None)
    self.login("ERP5TypeTestCase")
    preference_dict = json.loads(self.portal.Base_getPreferencePathList())
    self.assertEquals(preference_dict, {})
    self.portal.portal_preferences.ung_preference.enable()
    self.stepTic()
    preference_dict = json.loads(self.portal.Base_getPreferencePathList())
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
    self.assertEquals(preference_dict["preference"], "portal_preferences/ung_preference")
  
  def testWebSection_getWebPageObjectList(self):
    """Test if the paths of preference objects are returned correctly"""
    self.portal.web_page_module.manage_delObjects(list(self.portal.web_page_module.objectIds()))
    self.stepTic()
    self.portal.web_page_module.newContent(portal_type="Web Page")
    self.portal.web_page_module.newContent(portal_type="Web Table")
    self.portal.web_page_module.newContent(portal_type="Web Illustration")
    self.stepTic()
    kw = {"portal_type": "Web Page"}
    result_list = self.portal.web_site_module.ung.WebSection_getWebPageObjectList(**kw)
    self.assertEquals(len(result_list), 1)
    self.assertEquals(result_list[0].getPortalType(), "Web Page")
    kw["portal_type"] = "Web Illustration"
    result_list = self.portal.web_site_module.ung.WebSection_getWebPageObjectList(**kw)
    self.assertEquals(len(result_list), 1)
    self.assertEquals(result_list[0].getPortalType(), "Web Illustration")
    kw["portal_type"] = "Web Table"
    result_list = self.portal.web_site_module.ung.WebSection_getWebPageObjectList(**kw)
    self.assertEquals(len(result_list), 1)
    self.assertEquals(result_list[0].getPortalType(), "Web Table")