From 3a3e5c826ce786f8ca61b587da9f1723500926bb Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Fri, 28 Sep 2012 19:41:09 +0200 Subject: [PATCH 1/6] [WIP] start writing some simple tests for portal_crm bzr revid: abo@openerp.com-20120928174109-q8z9w71oj27n0s56 --- addons/portal_crm/__openerp__.py | 5 ++++- addons/portal_crm/test/submit_contact_form.yml | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 addons/portal_crm/test/submit_contact_form.yml diff --git a/addons/portal_crm/__openerp__.py b/addons/portal_crm/__openerp__.py index 81b6815b942..102ec36bb42 100644 --- a/addons/portal_crm/__openerp__.py +++ b/addons/portal_crm/__openerp__.py @@ -27,11 +27,14 @@ 'complexity': 'easy', 'description': """ This module adds a contact page (with a contact form creating a lead when submitted) to your portal if crm and portal are installed. -==================================================================================================================================== +==================================================================================================================================== """, 'author': 'OpenERP SA', 'depends': ['crm','portal'], 'data': ['wizard/contact_view.xml'], + 'test': [ + 'test/submit_contact_form.yml', + ], 'installable': True, 'auto_install': True, 'category': 'Hidden', diff --git a/addons/portal_crm/test/submit_contact_form.yml b/addons/portal_crm/test/submit_contact_form.yml new file mode 100644 index 00000000000..026d2c76c11 --- /dev/null +++ b/addons/portal_crm/test/submit_contact_form.yml @@ -0,0 +1,12 @@ +- + 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 From 9aec783e3c348d7cca659e5767673319163903f6 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 1 Oct 2012 11:42:02 +0200 Subject: [PATCH 2/6] [IMP] test message bzr revid: abo@openerp.com-20121001094202-iw6xwrq7fd0zwg21 --- addons/crm/test/process/lead2opportunity2win.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/crm/test/process/lead2opportunity2win.yml b/addons/crm/test/process/lead2opportunity2win.yml index eadb46f0f55..dc5aadbcf16 100644 --- a/addons/crm/test/process/lead2opportunity2win.yml +++ b/addons/crm/test/process/lead2opportunity2win.yml @@ -11,9 +11,11 @@ !assert {model: crm.lead, id: crm.crm_case_4, string: Lead in open state}: - state == "open" - - I create partner from lead. + I fill in a lead2partner wizard. - !record {model: crm.lead2partner, id: crm_lead2partner_id1, context: '{"active_model": "crm.lead", "active_ids": [ref("crm_case_4")]}'}: +- + I create a partner from the lead2partner wizard. - !python {model: crm.lead2partner}: | context.update({'active_model': 'crm.lead', 'active_ids': [ref('crm_case_4')], 'active_id': ref('crm_case_4')}) From 1d84db39c8ddd5b588098086413fcd343412bddf Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 1 Oct 2012 12:02:12 +0200 Subject: [PATCH 3/6] [WIP] disable tests bzr revid: abo@openerp.com-20121001100212-2j0ekes5oc86jkff --- addons/portal_crm/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/portal_crm/__openerp__.py b/addons/portal_crm/__openerp__.py index 102ec36bb42..8e532a16e61 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/submit_contact_form.yml', ], 'installable': True, 'auto_install': True, From d4e7bba274ab5a1ce49b71cd379ce7d24356043a Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 1 Oct 2012 12:22:30 +0200 Subject: [PATCH 4/6] [FIX] move group_portal access rules on partner from portal_hr_employees directly into portal module thils will prevent errors while accessing partner model while portal_hr_employees isn't installed bzr revid: abo@openerp.com-20121001102230-k1fe4ndjwi58qrfg --- addons/portal/security/ir.model.access.csv | 4 ++++ addons/portal_hr_employees/security/ir.model.access.csv | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/portal/security/ir.model.access.csv b/addons/portal/security/ir.model.access.csv index 1c4ee5964bd..9202c7f4087 100644 --- a/addons/portal/security/ir.model.access.csv +++ b/addons/portal/security/ir.model.access.csv @@ -1,2 +1,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_mail_message_portal,mail.message.portal,mail.model_mail_message,group_portal,1,0,1,1 +access_res_partner,res.partner,base.model_res_partner,portal.group_portal,1,0,0,0 +access_res_partner_address,res.partner_address,base.model_res_partner_address,portal.group_portal,1,0,0,0 +access_res_partner_category,res.partner_category,base.model_res_partner_category,portal.group_portal,1,0,0,0 +access_res_partner_title,res.partner_title,base.model_res_partner_title,portal.group_portal,1,0,0,0 diff --git a/addons/portal_hr_employees/security/ir.model.access.csv b/addons/portal_hr_employees/security/ir.model.access.csv index d18aeb90e1c..de204d43a09 100644 --- a/addons/portal_hr_employees/security/ir.model.access.csv +++ b/addons/portal_hr_employees/security/ir.model.access.csv @@ -1,6 +1,2 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_hr_employee_user,hr.employee user,hr.model_hr_employee,portal.group_portal,1,0,0,0 -access_res_partner,res.partner,base.model_res_partner,portal.group_portal,1,0,0,0 -access_res_partner_address,res.partner_address,base.model_res_partner_address,portal.group_portal,1,0,0,0 -access_res_partner_category,res.partner_category,base.model_res_partner_category,portal.group_portal,1,0,0,0 -access_res_partner_title,res.partner_title,base.model_res_partner_title,portal.group_portal,1,0,0,0 From 93c83f1b7a89ae985105ccc85320a7a2db8dee35 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 1 Oct 2012 16:17:55 +0200 Subject: [PATCH 5/6] [IMP] add a few tests on the contact form bzr revid: abo@openerp.com-20121001141755-9aozwzm8eeo3a9z7 --- addons/portal_crm/__openerp__.py | 2 +- addons/portal_crm/test/contact_form.yml | 30 +++++++++++++++++++ .../portal_crm/test/submit_contact_form.yml | 12 -------- addons/portal_crm/wizard/contact.py | 10 +++---- 4 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 addons/portal_crm/test/contact_form.yml delete mode 100644 addons/portal_crm/test/submit_contact_form.yml 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 """ From 0fc7b34011a49ab185d180ee34f7583a1cc94242 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 1 Oct 2012 17:28:52 +0200 Subject: [PATCH 6/6] [IMP] perform wizard submit as a portal user bzr revid: abo@openerp.com-20121001152852-7pw98ediblodp1xk --- addons/portal_crm/test/contact_form.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/portal_crm/test/contact_form.yml b/addons/portal_crm/test/contact_form.yml index 9fd783e1dde..7ba93a9e831 100644 --- a/addons/portal_crm/test/contact_form.yml +++ b/addons/portal_crm/test/contact_form.yml @@ -1,3 +1,8 @@ +- + Set the current user as portal user. +- + !context + 'uid': 'portal.demo_user0' - As a portal user, I fill in the contact form and submit it. - @@ -17,9 +22,12 @@ 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')]) + from openerp import SUPERUSER_ID + + ids = self.search(cr, SUPERUSER_ID, [('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]) + + obj = self.browse(cr, SUPERUSER_ID, ids[0]) expected_values = dict( name='Need information about your contact form module', partner_name='Mr. John Doe',