[IMP] add a few tests on the contact form

bzr revid: abo@openerp.com-20121001141755-9aozwzm8eeo3a9z7
This commit is contained in:
Antonin Bourguignon 2012-10-01 16:17:55 +02:00
parent d4e7bba274
commit 93c83f1b7a
4 changed files with 36 additions and 18 deletions

View File

@ -33,7 +33,7 @@ This module adds a contact page (with a contact form creating a lead when submit
'depends': ['crm','portal'],
'data': ['wizard/contact_view.xml'],
'test': [
#'test/submit_contact_form.yml',
'test/contact_form.yml',
],
'installable': True,
'auto_install': True,

View File

@ -0,0 +1,30 @@
-
As a portal user, I fill in the contact form and submit it.
-
!record {model: portal_crm.crm_contact_us, id: contact_us_01}:
name: 'Need information about your contact form module'
partner_name: 'Mr. John Doe'
email_from: 'mister@john.doe'
phone: '+32 444 11 22 33'
description: 'Dear Sir or Madam, could you get back to me asap ? Regards.'
-
For security reasons, the wizard values is empty.
-
!python {model: portal_crm.crm_contact_us}: |
obj = self.browse(cr, uid, ref("contact_us_01"))
assert not(obj.name or obj.partner_name or obj.email_from or obj.phone or obj.description), 'All the wizard\'s values are not empty'
-
And a lead is created with the proper values.
-
!python {model: crm.lead}: |
ids = self.search(cr, uid, [('name', '=', 'Need information about your contact form module')])
assert len(ids) == 1, 'There are more than one matching lead, while only one was expected'
obj = self.browse(cr, uid, ids[0])
expected_values = dict(
name='Need information about your contact form module',
partner_name='Mr. John Doe',
email_from='mister@john.doe',
phone='+32 444 11 22 33',
description='Dear Sir or Madam, could you get back to me asap ? Regards.')
for k, v in expected_values.iteritems():
assert obj[k] == expected_values[k], 'Lead data mismatch: expected %s, got %s' % (expected_values[k], obj[k])

View File

@ -1,12 +0,0 @@
-
As a portal user, I fill in the contact form and submit it
-
!python {model: portal_crm.crm_contact_us}: |
values = {
'name': 'Need information about your products',
'partner_name': 'Mr. John Doe',
'email_from': 'mister@john.doe',
'phone': '+32 444 11 22 33',
'description': 'Dear Sir or Madam, could you get back to me asap ? Regards.'
}
self.create(cr, ref("portal.demo_user0"), values, context=context)

View File

@ -81,8 +81,8 @@ class crm_contact_us(osv.TransientModel):
def create(self, cr, uid, values, context=None):
"""
Since they are potentially sensitive, we don't want any user to be able
to read datas generated through this module. That's why we'll write
those information directly in the crm.lead table and leave blank
to read datas generated through this module. Therefore we'll write
these information directly in the crm.lead table and leave blank
entries in the portal_crm.crm_contact_us table.
This is why the create() method is overwritten.
"""
@ -93,8 +93,7 @@ class crm_contact_us(osv.TransientModel):
models implied (like mail.thread, among others, that performs a read
when its create() method is called (in method message_get_subscribers()),
it is quite complicated to set proper rights for this object.
Therefore, user SUPERUSER_ID will perform the creation until a better
workaround is figured out.
Therefore, user SUPERUSER_ID will perform the creation.
"""
values['contact_name'] = values['name']
crm_lead.create(cr, SUPERUSER_ID, dict(values,user_id=False), context)
@ -103,7 +102,8 @@ class crm_contact_us(osv.TransientModel):
Create an empty record in the portal_crm.crm_contact_us table.
Since the 'name' field is mandatory, give an empty string to avoid an integrity error.
"""
return super(crm_contact_us, self).create(cr, uid, {'name': ' '})
empty_values = dict((k, False) if k != 'name' else (k, '') for k, v in values.iteritems())
return super(crm_contact_us, self).create(cr, uid, empty_values)
def submit(self, cr, uid, ids, context=None):
""" When the form is submitted, redirect the user to a "Thanks" message """