Permalink
Browse files

[FIX] web_planner: test should not assume url parameter order

test_web_planner throws errors like this on some environments:
AssertionError:
'/web#action=135&view_type=list' != '/web#view_type=list&action=135'

the urls in web_planner are created with a dict for the parameters to
create the urls. dicts are unorderd up to python 3.5. (see
 https://www.python.org/dev/peps/pep-0468/)

As the urls /web#action=135&view_type=list and
/web#view_type=list&action=135 are equivalent we now test if the
parameters are the equal in the url regardless of their order.
  • Loading branch information...
ap-wtioit committed Jan 11, 2019
1 parent df7953f commit e3778e9048997865fa78bee504b526df33d86738
Showing with 13 additions and 16 deletions.
  1. +13 −16 addons/web_planner/tests/test_web_planner.py
@@ -3,6 +3,7 @@

from odoo.tests.common import TransactionCase
from odoo.addons.web_planner.models.web_planner import Planner
from werkzeug import urls


class TestWebPlanner(TransactionCase):
@@ -26,10 +27,9 @@ def test_00(self):
}
)

self.assertEqual(
Planner.prepare_backend_url(self, "web_planner.test_00"),
"/web#view_type=list&action=%s" % action.id,
)
backend_url = Planner.prepare_backend_url(self, "web_planner.test_00", 'form')
parameters = dict(urls.url_decode(backend_url[backend_url.index('#') + 1:]))
self.assertEqual(parameters, {'view_type': ['list'], 'action': [str(action.id)]})

def test_01(self):
#bad choise of view_type
@@ -50,10 +50,9 @@ def test_01(self):
}
)

self.assertEqual(
Planner.prepare_backend_url(self, "web_planner.test_01", 'form'),
"/web#view_type=list&action=%s" % action.id,
)
backend_url = Planner.prepare_backend_url(self, "web_planner.test_01", 'form')
parameters = dict(urls.url_decode(backend_url[backend_url.index('#') + 1:]))
self.assertEqual(parameters, {'view_type': ['list'], 'action': [str(action.id)]})

def test_02(self):
#choose the second view_mode
@@ -74,10 +73,9 @@ def test_02(self):
}
)

self.assertEqual(
Planner.prepare_backend_url(self, "web_planner.test_02", 'form'),
"/web#view_type=form&action=%s" % action.id,
)
backend_url = Planner.prepare_backend_url(self, "web_planner.test_02", 'form')
parameters = dict(urls.url_decode(backend_url[backend_url.index('#') + 1:]))
self.assertEqual(parameters, {'view_type': ['form'], 'action': [str(action.id)]})

def test_03(self):
#bad xml_id
@@ -98,8 +96,7 @@ def test_03(self):
}
)

self.assertEqual(
Planner.prepare_backend_url(self, "web_planner.bad_xml_id", 'form'),
"/web#view_type=list&model=ir.module.module",
)
backend_url = Planner.prepare_backend_url(self, "web_planner.bad_xml_id", 'form')
parameters = dict(urls.url_decode(backend_url[backend_url.index('#') + 1:]))
self.assertEqual(parameters, {'view_type': ['list'], 'model': ['ir.module.module']})

0 comments on commit e3778e9

Please sign in to comment.