Commit 8d5ced18 authored by Julien Muchembled's avatar Julien Muchembled

qa: fix sort method in testResource

The error was found with MariaDB 10.4, which returns results (of a
request without ORDER BY) in a different order than previous versions.
parent d10401d8
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
import unittest import random, unittest
from unittest import expectedFailure from unittest import expectedFailure
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -891,27 +891,19 @@ class TestResource(ERP5TypeTestCase): ...@@ -891,27 +891,19 @@ class TestResource(ERP5TypeTestCase):
if variation: if variation:
categories.append(variation) categories.append(variation)
def sortResult(a, b): def sort_key(supply_line):
def _pricingSortMethod(a, b): # XXX copied from Resource.py return (
# Simple method : the one that defines a destination section wins # same as in Resource._pricingSortKeyMethod
if a.getDestinationSection(): not supply_line.getDestinationSection(),
return -1 # a defines a destination section and wins ###
return 1 # a defines no destination section and loses
if _pricingSortMethod(a, b):
# now sort based on resource definition # now sort based on resource definition
if a.getResourceValue(): supply_line.getResourceValue() is None,
if b.getResourceValue(): # and make sure this is enough
return 1 random.random(),
else: )
return -1
else:
return 1
else:
return -1
self.assertEqual(base_price, product.getPrice(categories=categories, self.assertEqual(base_price, product.getPrice(categories=categories,
sort_method=sortResult)) sort_key_method=sort_key))
# The following test tests Movement.getPrice, which is based on the movement # The following test tests Movement.getPrice, which is based on the movement
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment