testRunMyDoc.py 10.9 KB
Newer Older
Rafael Monnerat's avatar
Rafael 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-2012 Nexedi SA and Contributors. All Rights Reserved.
#               Rafael Monnerat <rafael@nexedi.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 31
from Products.ERP5OOo.tests.testDms import makeFileUpload
from time import time
Rafael Monnerat's avatar
Rafael Monnerat committed
32 33 34 35 36 37 38 39 40 41 42 43 44

class TestRunMyDoc(ERP5TypeTestCase):
  """
   Basic Test for internal implementation of RunMyDocs
  """

  def getTitle(self):
    return "Run My Doc"

  def getBusinessTemplateList(self):
    """
    Tuple of Business Templates we need to install
    """
45 46 47 48
    return ('erp5_base',
            'erp5_jquery',
            'erp5_jquery_ui',
            'erp5_knowledge_pad',
49 50
            'erp5_ingestion_mysql_innodb_catalog',
            'erp5_ingestion',
51 52 53
            'erp5_web',
            'erp5_dms',
            'erp5_slideshow_style',
Rafael Monnerat's avatar
Rafael Monnerat committed
54
            'erp5_ui_test_core',
55
            'erp5_run_my_doc')
Rafael Monnerat's avatar
Rafael Monnerat committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

  def afterSetUp(self):
    """
    This is ran before anything, used to set the environment
    """
    # here, you can create the categories and objects your test will depend on
    pass

  website_id = "test_page_web_site"

  def test_getDocumentListWithTestPage(self):
    """
     Assert if Test Page works with getDocumentList
    """
    test_page_reference = "developer-my.test.page"
    website = getattr(self.portal.web_site_module, self.website_id, None)
    if website is None:
      website = self.portal.web_site_module.newContent(
                                   portal_type='Web Site',
                                   id=self.website_id)
      website.publish()
77
      self.tic()
Rafael Monnerat's avatar
Rafael Monnerat committed
78 79 80 81 82 83 84 85

    test_page = self.portal.test_page_module.newContent(
              portal_type="Test Page",
              reference=test_page_reference,
              language="en",
              version="001")
              
    test_page.publish()
86
    self.tic()
Rafael Monnerat's avatar
Rafael Monnerat committed
87 88 89 90
    
    document = website.WebSection_getDocumentValue(test_page_reference)
    
    self.assertNotEquals(None, document)
91
    self.assertEqual(document.getRelativeUrl(),
Rafael Monnerat's avatar
Rafael Monnerat committed
92
                      test_page.getRelativeUrl())
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

  def test_Zuite_uploadScreenShot(self):
    """
      Test Screeshot upload script used by Zelenium to 
      update screenshots of the documents.
    """
    image_upload = makeFileUpload('TEST-en-002.png')
    self.assertNotEquals(None, image_upload)
    
    # Create a web page, and check if the content is not overwriten
    web_page_reference = "WEB-PAGE-REFERENCE"
    web_page = self.portal.web_page_module.newContent(
                                     reference=web_page_reference, 
                                     language="en", version="001")
    web_page.publishAlive()
108
    self.tic()
109 110 111 112 113 114

    image_reference = "IMAGE-REFERENCE-%s" % str(time())
    image_page = self.portal.image_module.newContent(
                                   reference=image_reference, 
                                   language="en", version="001")
    image_page.publishAlive()
115
    self.tic()
116 117 118 119
    image_page_2 = self.portal.image_module.newContent(
                                   reference=image_reference, 
                                   language="en", version="002")
    image_page_2.publishAlive()
120
    self.tic()
121 122 123 124 125 126 127 128 129

    self.portal.REQUEST.form['data_uri'] = image_upload
    fake_image_reference = "DO-NOT-EXISTANT-IMAGE"
    self.assertNotEquals(None, 
                   self.portal.Zuite_uploadScreenshot(image_upload, fake_image_reference))

    self.assertNotEquals(None, 
                   self.portal.Zuite_uploadScreenshot(image_upload, web_page_reference))

130
    self.assertEqual(None, 
131 132
                   self.portal.Zuite_uploadScreenshot(image_upload, image_reference))

133
    self.tic()
134 135
    # The right image were updated.
    image_upload.seek(0)
136 137 138
    self.assertEqual(image_page_2.getData(), image_upload.read().decode("base64"))
    self.assertEqual(image_page_2.getFilename(), image_reference + '.png')
    self.assertEqual(image_page.getData(), '')
139

140
  def test_viewSeleniumTest(self):
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    """
      Test the script that extracts Selenium Test from HTML body.
    """
    test_page_html = """<section><h1>TITLE</h1><details>DETAILS<details>
    <test><table class="test" style="display: none;"> <tbody> </tbody></table> </test> 
    </section> 
    <section><h1>TITLE</h1><details>DETAILS<details><test>
      <table class="test" style="display: none;">
        <tbody> 
          <tr> 
            <td colspan="3">&lt;span metal:use-macro=&quot;container/Zuite_viewTestMacroLibrary/macros/init_test_environment&quot; style=&quot;display: none;&quot;&gt;init&lt;/span&gt;</td> 
          </tr> 
          <tr> 
            <td>selectAndWait</td> 
            <td>name=select_module</td> 
            <td>label=Test Pages</td> 
          </tr> 
          <tr> 
            <td>verifyTextPresent</td> 
            <td>Test Pages</td> 
            <td> <br /> </td> 
          </tr> 
          <tr style="opacity: 1;"> 
            <td>clickAndWait</td> 
            <td>css=a.fast_input &gt; span.image</td> 
            <td> <br /> </td> 
          </tr> </tbody></table> </test> 
    </section> 
    <section><h1>TITLE</h1><details>DETAILS<details><test>
      <table class="test" style="display: none;"> <tbody> 
          <tr> 
            <td>verifyTextPresent</td> 
            <td>Test Pages</td> 
            <td> <br /> </td> 
          </tr> </tbody></table> </test> 
    </section>"""

178
    expected_test_html = u"""<html>
179 180 181 182 183 184 185 186 187 188 189 190
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>TEST</title>
  </head>
  <body>
    <table name="SELENIUM-TEST" cellpadding="1" cellspacing="1" border="1">
      <thead>
        <tr class="title">
          <td colspan="3">TEST</td>
        </tr>
      </thead>
      <tbody>
191
        <span metal:use-macro="container/Zuite_CommonTemplate/macros/init" style="display: none;">init</span>        <tr>
192 193 194 195 196 197 198
          <td>store</td>
          <!-- ERP5TypeTestCase is the default for any UnitTest -->
          <td>%s</td>
          <td>base_user</td>
         </tr>
        <tr>
          <td>store</td>
199 200
          <td>%s</td>
          <td>base_password</td>
201
         </tr>
202 203
        <span metal:use-macro="container/Zuite_viewTestMacroLibrary/macros/init_test_environment" style="display: none;">init</span><tr> 
            <td>selectAndWait</td> 
204 205
            <td>name=select_module</td> 
            <td>label=Test Pages</td> 
206 207 208
          </tr> 
          <tr> 
            <td>verifyTextPresent</td> 
209
            <td>Test Pages</td> 
210
            <td> <br> </td> 
211 212 213
          </tr> 
          <tr style="opacity: 1;"> 
            <td>clickAndWait</td> 
214
            <td>css=a.fast_input &gt; span.image</td> 
215
            <td> <br> </td> 
216 217
          </tr> <tr> 
            <td>verifyTextPresent</td> 
218
            <td>Test Pages</td> 
219 220
            <td> <br> </td> 
          </tr> 
221 222 223 224 225 226 227 228
      </tbody>
    </table>
  </body>
</html>"""
  
    test_page = self.portal.test_page_module.newContent(title="TEST",
                                                        reference='TESTPAGEREFERENCE',
                                                        text_content=test_page_html)
229
    self.assertEqual(test_page.TestPage_viewSeleniumTest(), expected_test_html % 
230
                                 ("ERP5TypeTestCase", ""))
231

232
    self.tic()
233 234 235 236 237 238 239 240
    test_page.TestPage_runSeleniumTest()

    zuite = getattr(self.portal.portal_tests, 'TESTPAGEREFERENCE', None)
    self.assertNotEquals(zuite, None)
    
    zptest = getattr(zuite, "TEST", None)
    self.assertNotEquals(zptest, None)

241 242
    expected_html = expected_test_html % ("ERP5TypeTestCase", "")

243
    self.assertEqual(zptest._text, expected_html.strip())
244

245
    expected_test_html = u"""<html>
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
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>TEST</title>
  </head>
  <body>
    <table name="SELENIUM-TEST" cellpadding="1" cellspacing="1" border="1">
      <thead>
        <tr class="title">
          <td colspan="3">TEST</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>store</td>
          <td>%s</td>
          <td>base_url</td>
        </tr>
        <tr>
          <td>store</td>
          <!-- ERP5TypeTestCase is the default for any UnitTest -->
          <td>%s</td>
          <td>base_user</td>
         </tr>
        <tr>
          <td>store</td>
271 272
          <td>%s</td>
          <td>base_password</td>
273
         </tr>
274 275
        <span metal:use-macro="container/Zuite_viewTestMacroLibrary/macros/init_test_environment" style="display: none;">init</span><tr> 
            <td>selectAndWait</td> 
276 277
            <td>name=select_module</td> 
            <td>label=Test Pages</td> 
278 279 280
          </tr> 
          <tr> 
            <td>verifyTextPresent</td> 
281
            <td>Test Pages</td> 
282
            <td> <br> </td> 
283 284 285
          </tr> 
          <tr style="opacity: 1;"> 
            <td>clickAndWait</td> 
286
            <td>css=a.fast_input &gt; span.image</td> 
287
            <td> <br> </td> 
288 289
          </tr> <tr> 
            <td>verifyTextPresent</td> 
290
            <td>Test Pages</td> 
291 292
            <td> <br> </td> 
          </tr> 
293 294 295 296 297 298 299 300 301 302 303
      </tbody>
    </table>
  </body>
</html>"""


    # Mimic usage of TestPage_viewSeleniumTest?url=...
    self.portal.REQUEST['url'] = "http://toto.com"
    self.portal.REQUEST['user'] = "toto"
    self.portal.REQUEST['password'] = "toto"

304
    self.assertEqual(test_page.TestPage_viewSeleniumTest(REQUEST=self.portal.REQUEST),
305
                      expected_test_html % ("http://toto.com", "toto", "toto"))
306
    self.tic()
307 308 309 310 311 312 313
    test_page.TestPage_runSeleniumTest()

    zuite = getattr(self.portal.portal_tests, 'TESTPAGEREFERENCE', None)
    self.assertNotEquals(zuite, None)

    zptest = getattr(zuite, "TEST", None)
    self.assertNotEquals(zptest, None)
314

315
    expected_html = expected_test_html % ("http://toto.com", "toto", "toto")
316

317
    self.assertEqual(zptest._text, expected_html.strip())