[MERGE] marketing_campaign: improve tests

bzr revid: rco@openerp.com-20111215103225-8rlbof75uxnqjkrw
This commit is contained in:
Raphael Collet 2011-12-15 11:32:25 +01:00
commit 68ff6cb98a
5 changed files with 259 additions and 12 deletions

View File

@ -58,7 +58,11 @@ Note: If you need demo data, you can install the marketing_campaign_crm_demo mod
"security/ir.model.access.csv"
],
'demo_xml': [
'marketing_campaign_demo.xml',
],
'test': [
'test/marketing_campaign.yml',
],
'installable': True,
'active': False,
'certificate' : '00421723279617928365',

View File

@ -164,11 +164,12 @@ Normal - the campaign runs normally and automatically sends all emails and repor
self.write(cr, uid, ids, {'state': 'cancelled'})
return True
# dead code
def signal(self, cr, uid, model, res_id, signal, run_existing=True, context=None):
record = self.pool.get(model).browse(cr, uid, res_id, context)
return self._signal(cr, uid, record, signal, run_existing, context)
#dead code
def _signal(self, cr, uid, record, signal, run_existing=True, context=None):
if not signal:
raise ValueError('signal cannot be False')
@ -461,6 +462,7 @@ class marketing_campaign_activity(osv.osv):
return super(marketing_campaign_activity, self).search(cr, uid, args,
offset, limit, order, context, count)
#dead code
def _process_wi_report(self, cr, uid, activity, workitem, context=None):
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
(report_data, format) = service.create(cr, uid, [], {}, {})
@ -481,6 +483,7 @@ class marketing_campaign_activity(osv.osv):
activity.email_template_id.id,
workitem.res_id, context=context)
#dead code
def _process_wi_action(self, cr, uid, activity, workitem, context=None):
if context is None:
context = {}
@ -670,7 +673,7 @@ class marketing_campaign_workitem(osv.osv):
def _process_one(self, cr, uid, workitem, context=None):
if workitem.state != 'todo':
return
return False
activity = workitem.activity_id
proxy = self.pool.get(workitem.object_id.model)
@ -707,7 +710,7 @@ class marketing_campaign_workitem(osv.osv):
if result:
# process _chain
workitem = workitem.browse(context)[0] # reload
workitem = workitem.browse(context=context)[0] # reload
date = datetime.strptime(workitem.date, DT_FMT)
for transition in activity.to_ids:
@ -784,11 +787,7 @@ class marketing_campaign_workitem(osv.osv):
res = {}
wi_obj = self.browse(cr, uid, ids[0], context=context)
if wi_obj.activity_id.type == 'email':
data_obj = self.pool.get('ir.model.data')
data_id = data_obj._get_id(cr, uid, 'email_template', 'email_template_preview_form')
view_id = 0
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'email_template', 'email_template_preview_form')
res = {
'name': _('Email Preview'),
'view_type': 'form',
@ -796,7 +795,7 @@ class marketing_campaign_workitem(osv.osv):
'res_model': 'email_template.preview',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
'views': [(view_id and view_id[1] or 0, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy':True,

View File

@ -0,0 +1,93 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Email tempalte -->
<record id="email_template_1" model="email.template">
<field name="name">Template for New Partner</field>
<field name="email_from">info@tinyerp.com</field>
<field name="subject">Welcome in OpenERP Partner Channel!</field>
<field name="email_to">${object.email or ''}</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="body_text">Hello, We are very happy to send Welcome message.</field>
</record>
<record id="email_template_2" model="email.template">
<field name="name">Template for Silver Partner</field>
<field name="email_from">info@tinyerp.com</field>
<field name="subject">Congratulation! You become now our Silver Partner.</field>
<field name="email_to">${object.email or ''}</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="body_text">Hello, We are happy to announce that you now become our Silver Partner.</field>
</record>
<record id="email_template_3" model="email.template">
<field name="name">Template for Gold Partner</field>
<field name="email_from">info@tinyerp.com</field>
<field name="subject">Congratulation! You become our Gold Partner.</field>
<field name="email_to">${object.email or ''}</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="body_text">Hello, We are happy to announce that you become our Gold Partner.</field>
</record>
<!-- Campaign -->
<record id="marketing_campaign_openerppartnerchannel" model="marketing.campaign">
<field name="name">OpenERP Partner Channel</field>
<field name="object_id" ref="base.model_res_partner"/>
<field name="mode">active</field>
</record>
<!-- Activity -->
<record id="marketing_campaign_activity_0" model="marketing.campaign.activity">
<field name="name">New Partner</field>
<field name="campaign_id" ref="marketing_campaign_openerppartnerchannel"/>
<field name="email_template_id" ref="email_template_1"/>
<field name="condition">object.credit_limit &lt; 10000</field>
<field name="keep_if_condition_not_met">True</field>
<field eval="1" name="start"/>
</record>
<record id="marketing_campaign_activity_1" model="marketing.campaign.activity">
<field name="name">Silver Partner</field>
<field name="campaign_id" ref="marketing_campaign_openerppartnerchannel"/>
<field name="condition">object.credit_limit &gt;= 10000 and object.credit_limit &lt; 50000</field>
<field name="keep_if_condition_not_met">True</field>
<field name="email_template_id" ref="email_template_2"/>
</record>
<record id="marketing_campaign_activity_2" model="marketing.campaign.activity">
<field name="name">Gold Partner</field>
<field name="condition">object.credit_limit &gt;= 100000</field>
<field name="campaign_id" ref="marketing_campaign_openerppartnerchannel"/>
<field name="keep_if_condition_not_met">True</field>
<field name="email_template_id" ref="email_template_3"/>
</record>
<!-- Tranisition -->
<record id="marketing_campaign_transition_0" model="marketing.campaign.transition">
<field model="marketing.campaign.activity" name="activity_from_id" ref = "marketing_campaign_activity_0"/>
<field model="marketing.campaign.activity" name="activity_to_id" ref = "marketing_campaign_activity_1"/>
</record>
<record id="marketing_campaign_transition_1" model="marketing.campaign.transition">
<field model="marketing.campaign.activity" name="activity_from_id" ref = "marketing_campaign_activity_1"/>
<field model="marketing.campaign.activity" name="activity_to_id" ref = "marketing_campaign_activity_2"/>
</record>
<!-- Segment -->
<record id="filter0" model="ir.filters">
<field name="name">Partners</field>
<field name="domain">[('name','like','Agrolait')]</field>
<field name="model_id">res.partner</field>
</record>
<record id="marketing_campaign_segment0" model="marketing.campaign.segment">
<field eval="time.strftime('%Y-%m-%d %H:%M:%S')" name="date_run"/>
<field name="name">OpenERP Partner</field>
<field name="sync_mode">create_date</field>
<field name="ir_filter_id" ref="filter0"></field>
<field name="campaign_id" ref="marketing_campaign_openerppartnerchannel"/>
</record>
</data>
</openerp>

View File

@ -0,0 +1,151 @@
-
In order to test process of compaign, I start compaign.
-
!workflow {model: marketing.campaign, action: state_running_set, ref: marketing_campaign_openerppartnerchannel}
-
I check the campaign on Running mode after started.
-
!assert {model: marketing.campaign, id: marketing_campaign_openerppartnerchannel}:
- state == 'running'
-
I start this segment after assinged campaign.
-
!workflow {model: marketing.campaign.segment, action: state_running_set, ref: marketing_campaign_segment0}
-
I check the segment on Running mode after started.
-
!assert {model: marketing.campaign.segment, id: marketing_campaign_segment0}:
- state == 'running'
-
I synchronized segment manually to see all step of activity and process covered on this campaign.
-
!python {model: marketing.campaign.segment}: |
segment_id = self.browse(cr ,uid ,ref("marketing_campaign_segment0") ,context)
assert segment_id.date_next_sync, 'Next Synchronization date is not calculated.'
self.synchroniz(cr, uid, [ref("marketing_campaign_segment0")])
-
I cancel Marketing Workitems.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel'))])
self.button_cancel(cr, uid, ids)
record = self.browse(cr, uid, ids[0])
assert record.state == 'cancelled' or record.state == 'done' , 'Marketing Workitem shoud be in cancel state.'
-
I set Marketing Workitems in draft state.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel'))])
self.button_draft(cr, uid, ids)
record = self.browse(cr, uid, ids[0])
assert record.state == 'todo' or record.state == 'done' , 'Marketing Workitem shoud be in draft state.'
-
I check followup detail of first activity.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_0'))])
assert ids, 'Followup item is not created for first activity.'
work_item_id = self.browse(cr ,uid ,ids[0] ,context)
assert work_item_id.res_name, 'Resource Name is not defined.'
-
I process followup of first activity.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_0'))])
self.process(cr, uid, ids)
record = self.browse(cr, uid, ids)[0]
assert record.state == "done", "Followup item should be closed after process."
-
I check followup detail of second activity after process of first activity.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_1'))])
assert ids, 'Followup item is not created for second activity.'
-
Now I increase credit limit of customer
-
!python {model: res.partner}: |
self.write(cr, uid, [ref("base.res_partner_agrolait")], {'credit_limit':41000}, context=context)
-
I process followup of second activity after set draft.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_1'))])
self.button_draft(cr, uid, ids, context=context)
self.process(cr, uid, ids, context=context)
record = self.browse(cr, uid, ids[0], context=context)
assert record.state == "done", "Followup item should be closed after process."
-
I check followup detail of third activity after process of second activity.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_2'))])
assert ids, 'Followup item is not created for third activity.'
-
Now I increase credit limit of customer
-
!python {model: res.partner}: |
self.write(cr, uid, [ref("base.res_partner_agrolait")], {'credit_limit':151000}, context=context)
-
I process followup of third activity after set draft.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_2'))])
self.button_draft(cr, uid, ids, context=context)
self.process(cr, uid, ids, context=context)
record = self.browse(cr, uid, ids[0], context=context)
assert record.state == "done", "Followup item should be closed after process."
-
I print workitem report.
-
!python {model: marketing.campaign.workitem}: |
ids = self.search(cr, uid, [('segment_id', '=', ref('marketing_campaign_segment0')),
('campaign_id', '=', ref('marketing_campaign_openerppartnerchannel')), ('activity_id', '=', ref('marketing_campaign_activity_2'))])
self.preview(cr, uid, ids)
-
I cancel segmentation because of some activity.
-
!workflow {model: marketing.campaign.segment, action: state_cancel_set, ref: marketing_campaign_segment0}
-
I check the segmentation is canceled.
-
!assert {model: marketing.campaign.segment, id: marketing_campaign_segment0}:
- state == 'cancelled'
-
I reopen the segmentation.
-
!workflow {model: marketing.campaign.segment, action: state_draft_set, ref: marketing_campaign_segment0}
-
!workflow {model: marketing.campaign.segment, action: state_running_set, ref: marketing_campaign_segment0}
-
I check the segment on Running mode after started.
-
!assert {model: marketing.campaign.segment, id: marketing_campaign_segment0}:
- state == 'running'
-
I close segmentation After completion of all activity.
-
!workflow {model: marketing.campaign.segment, action: state_done_set, ref: marketing_campaign_segment0}
-
I check the segmentation is done.
-
!assert {model: marketing.campaign.segment, id: marketing_campaign_segment0}:
- state == 'done'
-
I close this campaing.
-
!workflow {model: marketing.campaign.segment, action: state_done_set, ref: marketing_campaign_openerppartnerchannel}
-
I check the campaing is done.
-
!assert {model: marketing.campaign.segment, id: marketing_campaign_openerppartnerchannel}:
- state == 'done'

View File

@ -58,7 +58,7 @@
<field name="name">For OpenERP Discovery Day on May 2010</field>
</record>
<record id="email_template_3" model="email.template">
<record id="email_template_3" model="email.template">
<field name="subject">Thanks for subscribing to the OpenERP Discovery Day</field>
<field name="email_to">info@tinyerp.com</field>
<field model="ir.actions.act_window" name="ref_ir_act_window" search="[('name', '=', u'For OpenERP OnDemand Free Trial 2010 Mail Form')]"/>
@ -72,7 +72,7 @@
<field name="name">For OpenERP Discovery Day</field>
</record>
<record id="email_template_4" model="email.template">
<record id="email_template_4" model="email.template">
<field name="subject">Thanks for buying the OpenERP book</field>
<field name="email_to">info@tinyerp.com</field>
<field model="ir.actions.act_window" name="ref_ir_act_window" search="[('name', '=', u'For OpenERP OnDemand Free Trial 2010 Mail Form')]"/>
@ -91,7 +91,6 @@
<field name="email_to">info@tinyerp.com</field>
<field model="ir.actions.act_window" name="ref_ir_act_window" search="[('name', '=', u'For OpenERP OnDemand Free Trial 2010 Mail Form')]"/>
<field model="ir.values" name="ref_ir_value" search="[('name', '=', u'Send Mail (For OpenERP OnDemand Free Trial 2010)')]"/>
<field name="model_id" ref="crm.model_crm_lead"/>
<field eval="0" name="user_signature"/>
<field name="body_text">Hello, We have very good offer that might suit you.
For our gold partners,We are arranging free technical training on june,2010.
@ -157,6 +156,7 @@
<record id="marketing_campaign_openerpondemandfreetrial0" model="marketing.campaign">
<field name="name">OpenERP OnDemand Free Trial 2010</field>
<field name="object_id" ref="crm.model_crm_lead"/>
<field name="mode">active</field>
<field name="partner_field_id" ref="crm.field_crm_lead_partner_id"/>
</record>