[FIX] crm_partner_assign: safer geolocalization test
Backport & adapt commits afd4b68acc1c60152776e0fffd99c4e567c6058f & 27787265ddcbc3383652129a69de362884a94ea6 As google starts to refuse to answer to our geocode requests, we need to mock results in tests.production/rebase-20171130
parent
8a187c5b1d
commit
cf8577b9d0
|
@ -23,5 +23,6 @@ import crm_partner_assign
|
|||
import crm_lead
|
||||
import wizard
|
||||
import report
|
||||
from . import tests
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -51,7 +51,6 @@ to an appropriate local partner, based on the distance and the weight that was a
|
|||
'res_partner_demo.xml',
|
||||
'crm_lead_demo.xml'
|
||||
],
|
||||
'test': ['test/partner_assign.yml'],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
-
|
||||
In order to test find nearest Partner functionality and assign to opportunity ,
|
||||
-
|
||||
I Set Geo Lattitude and Longitude according to partner address.
|
||||
-
|
||||
!python {model: res.partner}: |
|
||||
self.geo_localize(cr, uid, [ref('base.res_partner_2')], context)
|
||||
-
|
||||
I check Geo Latitude and Longitude of partner after set
|
||||
-
|
||||
!python {model: res.partner}: |
|
||||
partner = self.browse(cr, uid, ref('base.res_partner_2'))
|
||||
assert 50 < partner.partner_latitude < 51, "Latitude is wrong: 50 < %s < 51" % partner.partner_latitude
|
||||
assert 3 < partner.partner_longitude < 5, "Longitude is wrong: 3 < %s < 5" % partner.partner_longitude
|
||||
-
|
||||
I assign nearest partner to opportunity.
|
||||
-
|
||||
!python {model: crm.lead}: |
|
||||
self.assign_partner(cr, uid, [ref('crm.crm_case_19')], context=context)
|
||||
-
|
||||
I check assigned partner of opportunity who is nearest Geo Latitude and Longitude of opportunity.
|
||||
-
|
||||
!python {model: crm.lead}: |
|
||||
lead = self.browse(cr, uid, ref('crm.crm_case_19'))
|
||||
assert lead.partner_assigned_id.id == ref('base.res_partner_15') , "Opportuniy is not assigned nearest partner"
|
||||
assert 50 < lead.partner_latitude < 55, "Latitude is wrong: 50 < %s < 55" % lead.partner_latitude
|
||||
assert -4 < lead.partner_longitude < -1, "Longitude is wrong: -4 < %s < -1" % lead.partner_longitude
|
||||
-
|
||||
I forward this opportunity to its nearest partner.
|
||||
-
|
||||
!python {model: crm.lead.forward.to.partner}: |
|
||||
context.update({'default_model': 'crm.lead', 'default_res_id': ref('crm.crm_case_19'), 'active_ids': [ref('crm.crm_case_19')]})
|
||||
forward_id = self.create(cr, uid, {}, context=context)
|
||||
try:
|
||||
self.action_forward(cr, uid, [forward_id], context=context)
|
||||
except:
|
||||
pass
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_partner_assign
|
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from mock import patch
|
||||
|
||||
from openerp.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestPartnerAssign(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPartnerAssign, self).setUp()
|
||||
|
||||
def geo_find(addr):
|
||||
return {
|
||||
u'69 rue de Namur, 1300 Wavre, Belgium': (50.7158956, 4.6128075),
|
||||
u'L25 4RL Liverpool, United Kingdom': (53.3816319, -2.8737347),
|
||||
}.get(addr)
|
||||
|
||||
patcher = patch('openerp.addons.base_geolocalize.models.res_partner.geo_find', wraps=geo_find)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
patcher = patch('openerp.addons.crm_partner_assign.crm_partner_assign.geo_find',
|
||||
wraps=geo_find)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_00_partner_assign(self):
|
||||
partner2 = self.env.ref('base.res_partner_2')
|
||||
lead = self.env.ref('crm.crm_case_19')
|
||||
'''
|
||||
In order to test find nearest Partner functionality and assign to opportunity,
|
||||
I Set Geo Lattitude and Longitude according to partner address.
|
||||
'''
|
||||
partner2.geo_localize()
|
||||
|
||||
# I check Geo Latitude and Longitude of partner after set
|
||||
self.assertTrue(50 < partner2.partner_latitude < 51, "Latitude is wrong: 50 < %s < 51" % partner2.partner_latitude)
|
||||
self.assertTrue(3 < partner2.partner_longitude < 5, "Longitude is wrong: 3 < %s < 5" % partner2.partner_longitude)
|
||||
|
||||
# I assign nearest partner to opportunity.
|
||||
lead.assign_partner()
|
||||
|
||||
# I check assigned partner of opportunity who is nearest Geo Latitude and Longitude of opportunity.
|
||||
self.assertEqual(lead.partner_assigned_id, self.env.ref('base.res_partner_15'), "Opportuniy is not assigned nearest partner")
|
||||
self.assertTrue(50 < lead.partner_latitude < 55, "Latitude is wrong: 50 < %s < 55" % lead.partner_latitude)
|
||||
self.assertTrue(-4 < lead.partner_longitude < -1, "Longitude is wrong: -4 < %s < -1" % lead.partner_longitude)
|
||||
|
||||
# I forward this opportunity to its nearest partner.
|
||||
context = dict(self.env.context, default_model='crm.lead', default_res_id=lead.id, active_ids=lead.ids)
|
||||
lead_forwarded = self.env['crm.lead.forward.to.partner'].with_context(context).create({})
|
||||
try:
|
||||
lead_forwarded.action_forward()
|
||||
except Exception:
|
||||
pass
|
Loading…
Reference in New Issue