Commit 73f68fb8 authored by Jérome Perrin's avatar Jérome Perrin

testDeferredStyle: minor cleanups

Split a reusable test base class and use self.username variable.

Also don't set username as reference on person, this is no longer needed
since ERP5 Login.
parent 66e43d73
...@@ -36,8 +36,7 @@ from lxml import html ...@@ -36,8 +36,7 @@ from lxml import html
import email, urlparse, httplib import email, urlparse, httplib
class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): class DeferredStyleTestCase(ERP5TypeTestCase, ZopeTestCase.Functional):
"""Tests deferred styles for ERP5."""
skin = content_type = None skin = content_type = None
recipient_email_address = 'invalid@example.com' recipient_email_address = 'invalid@example.com'
attachment_file_extension = '' attachment_file_extension = ''
...@@ -50,9 +49,6 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -50,9 +49,6 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
publication_section = "reporting" publication_section = "reporting"
classification = "collaborative" classification = "collaborative"
def getTitle(self):
return 'Test Deferred Style'
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ('erp5_core_proxy_field_legacy', return ('erp5_core_proxy_field_legacy',
'erp5_base', 'erp5_base',
...@@ -67,14 +63,10 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -67,14 +63,10 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
if not self.skin:
raise NotImplementedError('Subclasses must define skin')
self.portal.MailHost.reset() self.portal.MailHost.reset()
person_module = self.portal.person_module person_module = self.portal.person_module
if person_module._getOb('pers', None) is None: if person_module._getOb('pers', None) is None:
person = person_module.newContent(id='pers', portal_type='Person', person = person_module.newContent(id='pers', portal_type='Person',
reference=self.username,
first_name=self.first_name, first_name=self.first_name,
default_email_text=self.recipient_email_address) default_email_text=self.recipient_email_address)
assignment = person.newContent(portal_type='Assignment') assignment = person.newContent(portal_type='Assignment')
...@@ -107,23 +99,29 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -107,23 +99,29 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.tic() self.tic()
def loginAsUser(self, username): def loginAsUser(self, username):
"""Login as a user and assign Manager role to this user.
"""
uf = self.portal.acl_users uf = self.portal.acl_users
user = uf.getUser(username).__of__(uf) user = uf.getUser(username).__of__(uf)
uf.zodb_roles.assignRoleToPrincipal('Manager', user.getId()) uf.zodb_roles.assignRoleToPrincipal('Manager', user.getId())
newSecurityManager(None, user) newSecurityManager(None, user)
class TestDeferredStyleBase(DeferredStyleTestCase):
"""Tests deferred styles for ERP5."""
def test_skin_selection(self): def test_skin_selection(self):
self.assertTrue('Deferred' in self.portal.portal_skins.getSkinSelections()) self.assertTrue('Deferred' in self.portal.portal_skins.getSkinSelections())
def test_report_view(self): def test_report_view(self):
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s'
% (self.portal.getId(), self.skin), '%s:%s' % (self.username, self.password)) % (self.portal.getId(), self.skin), '%s:%s' % (self.username, self.password))
self.tic() self.tic()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -158,7 +156,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -158,7 +156,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def _checkDocument(self): def _checkDocument(self):
document_list = self.portal.document_module.objectValues() document_list = self.portal.document_module.objectValues()
self.assertEquals(len(document_list), 1) self.assertEqual(len(document_list), 1)
document = document_list[0].getObject() document = document_list[0].getObject()
expected_file_name = 'History%s' % self.attachment_file_extension expected_file_name = 'History%s' % self.attachment_file_extension
self.assertEqual(expected_file_name, document.getFilename()) self.assertEqual(expected_file_name, document.getFilename())
...@@ -179,7 +177,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -179,7 +177,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def test_report_stored_as_document(self): def test_report_stored_as_document(self):
self._defineSystemPreference() self._defineSystemPreference()
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s'
...@@ -188,7 +186,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -188,7 +186,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self._checkDocument() self._checkDocument()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -217,7 +215,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -217,7 +215,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
notification_message.validate() notification_message.validate()
self.tic() self.tic()
self._defineSystemPreference("notification-deferred.report") self._defineSystemPreference("notification-deferred.report")
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s'
...@@ -226,7 +224,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -226,7 +224,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self._checkDocument() self._checkDocument()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -240,7 +238,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -240,7 +238,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def test_pdf_report_stored_as_document(self): def test_pdf_report_stored_as_document(self):
self._defineSystemPreference() self._defineSystemPreference()
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s&format=pdf' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s&format=pdf'
...@@ -250,7 +248,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -250,7 +248,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self._checkDocument() self._checkDocument()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -263,7 +261,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -263,7 +261,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.fail('Link not found in email\n%s' % message_text) self.fail('Link not found in email\n%s' % message_text)
def test_normal_form(self): def test_normal_form(self):
self.loginAsUser('bob') self.loginAsUser(self.username)
# simulate a big request, for which Base_callDialogMethod will not issue a # simulate a big request, for which Base_callDialogMethod will not issue a
# redirect # redirect
response = self.publish( response = self.publish(
...@@ -275,7 +273,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -275,7 +273,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
'%s:%s' % (self.username, self.password)) '%s:%s' % (self.username, self.password))
self.tic() self.tic()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -298,7 +296,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -298,7 +296,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def test_lang_negociation(self): def test_lang_negociation(self):
# User's Accept-Language header is honored in reports. # User's Accept-Language header is honored in reports.
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s'
...@@ -323,7 +321,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -323,7 +321,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
def test_lang_negociation_cookie(self): def test_lang_negociation_cookie(self):
# User's LOCALIZER_LANGUAGE cookie is honored in reports and have priority over Accept-Language # User's LOCALIZER_LANGUAGE cookie is honored in reports and have priority over Accept-Language
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s'
...@@ -354,8 +352,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -354,8 +352,7 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.tic() self.tic()
class TestODSDeferredStyle(TestDeferredStyleBase):
class TestODSDeferredStyle(TestDeferredStyle):
skin = 'ODS' skin = 'ODS'
content_type = 'application/vnd.oasis.opendocument.spreadsheet' content_type = 'application/vnd.oasis.opendocument.spreadsheet'
attachment_file_extension = '.ods' attachment_file_extension = '.ods'
...@@ -364,14 +361,14 @@ class TestODSDeferredStyle(TestDeferredStyle): ...@@ -364,14 +361,14 @@ class TestODSDeferredStyle(TestDeferredStyle):
def test_report_view_sheet_per_report_section(self): def test_report_view_sheet_per_report_section(self):
"""Test the sheet_per_report_section feature of erp5_ods_style. """Test the sheet_per_report_section feature of erp5_ods_style.
""" """
self.loginAsUser('bob') self.loginAsUser(self.username)
self.portal.changeSkin('Deferred') self.portal.changeSkin('Deferred')
response = self.publish( response = self.publish(
'/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s&sheet_per_report_section:int=1' '/%s/person_module/pers/Base_viewHistory?deferred_portal_skin=%s&sheet_per_report_section:int=1'
% (self.portal.getId(), self.skin), '%s:%s' % (self.username, self.password)) % (self.portal.getId(), self.skin), '%s:%s' % (self.username, self.password))
self.tic() self.tic()
last_message = self.portal.MailHost._last_message last_message = self.portal.MailHost._last_message
self.assertNotEquals((), last_message) self.assertNotEqual(last_message, ())
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0]) self.assertEqual('"%s" <%s>' % (self.first_name, self.recipient_email_address), mto[0])
mail_message = email.message_from_string(message_text) mail_message = email.message_from_string(message_text)
...@@ -394,12 +391,13 @@ class TestODSDeferredStyle(TestDeferredStyle): ...@@ -394,12 +391,13 @@ class TestODSDeferredStyle(TestDeferredStyle):
self.fail('Attachment not found in email\n%s' % message_text) self.fail('Attachment not found in email\n%s' % message_text)
class TestODTDeferredStyle(TestDeferredStyle): class TestODTDeferredStyle(TestDeferredStyleBase):
skin = 'ODT' skin = 'ODT'
content_type = 'application/vnd.oasis.opendocument.text' content_type = 'application/vnd.oasis.opendocument.text'
attachment_file_extension = '.odt' attachment_file_extension = '.odt'
portal_type = "Text" portal_type = "Text"
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestODSDeferredStyle)) suite.addTest(unittest.makeSuite(TestODSDeferredStyle))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment