| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo.tests import HttpCase, patch, tagged |
| 4 |
|
| 5 |
from odoo.addons.google_address_autocomplete.controllers.google_address_autocomplete import ( |
| 6 |
AutoCompleteController, |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
CONTROLLER_PATH = 'odoo.addons.google_address_autocomplete.controllers.google_address_autocomplete.AutoCompleteController' |
| 11 |
MOCK_GOOGLE_ID = 'aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQ==' |
| 12 |
MOCK_API_KEY = 'Tm9ib2R5IGV4cGVjdHMgdGhlIFNwYW5pc2ggaW5xdWlzaXRpb24gIQ==' |
| 13 |
|
| 14 |
|
| 15 |
@tagged('post_install', '-at_install') |
| 16 |
class TestUI(HttpCase): |
| 17 |
@classmethod |
| 18 |
def setUpClass(cls): |
| 19 |
super().setUpClass() |
| 20 |
cls.product = cls.env['product.product'].create({ |
| 21 |
'name': 'A test product', |
| 22 |
'website_published': True, |
| 23 |
'list_price': 1 |
| 24 |
}) |
| 25 |
|
| 26 |
def test_autocomplete(self): |
| 27 |
with patch.object(AutoCompleteController, '_perform_complete_place_search', |
| 28 |
lambda controller, *args, **kwargs: { |
| 29 |
'country': [self.env['res.country'].search([('code', '=', 'USA')]).id, 'United States'], |
| 30 |
'state': [self.env['res.country.state'].search([('country_id.code', '=', 'USA')])[0].id, 'Alabama'], |
| 31 |
'zip': '12345', |
| 32 |
'city': 'A Fictional City', |
| 33 |
'street': 'A fictional Street', |
| 34 |
'number': 42, |
| 35 |
'formatted_street_number': '42 A fictional Street' |
| 36 |
}), \ |
| 37 |
patch.object(AutoCompleteController, '_perform_place_search', |
| 38 |
lambda controller, *args, **kwargs: { |
| 39 |
'results': [{ |
| 40 |
'formatted_address': f'Result {x}', |
| 41 |
'google_place_id': MOCK_GOOGLE_ID |
| 42 |
} for x in range(5)]}): |
| 43 |
self.env['website'].get_current_website().google_places_api_key = MOCK_API_KEY |
| 44 |
self.start_tour('/shop/address', 'autocomplete_tour') |