summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonin Bourguignon <abo@openerp.com>2012-10-01 16:17:55 +0200
committerAntonin Bourguignon <abo@openerp.com>2012-10-01 16:17:55 +0200
commit93c83f1b7a89ae985105ccc85320a7a2db8dee35 (patch)
tree60a44da9fdf8022183a73fc5f7dea73578209522
parentd4e7bba274ab5a1ce49b71cd379ce7d24356043a (diff)
[IMP] add a few tests on the contact form
bzr revid: abo@openerp.com-20121001141755-9aozwzm8eeo3a9z7
-rw-r--r--addons/portal_crm/__openerp__.py2
-rw-r--r--addons/portal_crm/test/contact_form.yml30
-rw-r--r--addons/portal_crm/test/submit_contact_form.yml12
-rw-r--r--addons/portal_crm/wizard/contact.py10
4 files changed, 36 insertions, 18 deletions
diff --git a/addons/portal_crm/__openerp__.py b/addons/portal_crm/__openerp__.py
index 8e532a16e61..1516ab13961 100644
--- a/addons/portal_crm/__openerp__.py
+++ b/addons/portal_crm/__openerp__.py
@@ -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,
diff --git a/addons/portal_crm/test/contact_form.yml b/addons/portal_crm/test/contact_form.yml
new file mode 100644
index 00000000000..9fd783e1dde
--- /dev/null
+++ b/addons/portal_crm/test/contact_form.yml
@@ -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])
diff --git a/addons/portal_crm/test/submit_contact_form.yml b/addons/portal_crm/test/submit_contact_form.yml
deleted file mode 100644
index 026d2c76c11..00000000000
--- a/addons/portal_crm/test/submit_contact_form.yml
+++ /dev/null
@@ -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) \ No newline at end of file
diff --git a/addons/portal_crm/wizard/contact.py b/addons/portal_crm/wizard/contact.py
index b671ced2275..a0f0d952a66 100644
--- a/addons/portal_crm/wizard/contact.py
+++ b/addons/portal_crm/wizard/contact.py
@@ -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 """