Ticket #29226: test_modify_settings.patch

File test_modify_settings.patch, 2.6 KB (added by Manuel Kaufmann, 7 years ago)

Tests to demostrate the inconsisten behaviour of @modify_settings

  • tests/settings_tests/tests.py

    diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
    index 5a618954ed..cb3b1dcfbe 100644
    a b import os  
    22import sys
    33import unittest
    44import warnings
     5from collections import OrderedDict
    56from types import ModuleType
    67from unittest import mock
    78
    class FullyDecoratedTranTestCase(TransactionTestCase):  
    4849    def test_method_list_override_no_ops(self):
    4950        self.assertEqual(settings.ITEMS, ['b', 'd'])
    5051
     52    @modify_settings(ITEMS={
     53        'append': ['a', 'e'],
     54        'remove': ['a', 'c', 'e'],
     55    })
     56    def test_method_list_append_remove_same_values(self):
     57        # This test fails randomly in Python < 3.6 since dictionaries
     58        # doesn't have "insert ordering" as in Python >= 3.6
     59
     60        # This test fails in Python >= 3.6 since it has "insert
     61        # ordering" and we are first appending the items and then
     62        # removing them
     63        self.assertEqual(settings.ITEMS, ['b', 'd', 'a', 'e'])
     64
     65    @modify_settings(ITEMS={
     66        'remove': ['a', 'c', 'e'],
     67        'append': ['a', 'e'],
     68    })
     69    def test_method_list_remove_append_same_values(self):
     70        # This test fails randomly in Python < 3.6 since dictionaries
     71        # doesn't have "insert ordering" as in Python >= 3.6.
     72
     73        # This test passes in Python >= 3.6 since it has "insert
     74        # ordering" and we are first removing the items and then
     75        # appending them
     76        self.assertEqual(settings.ITEMS, ['b', 'd', 'a', 'e'])
     77
     78    @modify_settings(ITEMS={
     79        'remove': ['a', 'c', 'e'],
     80    })
     81    @modify_settings(ITEMS={
     82        'append': ['a', 'e'],
     83    })
     84    def test_method_list_append_remove_same_values_twice_decorated(self):
     85        self.assertEqual(settings.ITEMS, ['b', 'd', 'a', 'e'])
     86
     87    @unittest.expectedFailure
     88    @modify_settings(ITEMS=OrderedDict([
     89        ('append', ['a', 'e']),
     90        ('remove', ['a', 'c', 'e']),
     91    ]))
     92    def test_method_list_append_remove_same_values_ordereddict(self):
     93        # This test fail because it first appends the items and then
     94        # removes them
     95        self.assertEqual(settings.ITEMS, ['b', 'd', 'a', 'e'])
     96
     97    @modify_settings(ITEMS=OrderedDict([
     98        ('remove', ['a', 'c', 'e']),
     99        ('append', ['a', 'e']),
     100    ]))
     101    def test_method_list_remove_append_same_values_ordereddict(self):
     102        # This test pass because it first removes the items and then
     103        # appends them
     104        self.assertEqual(settings.ITEMS, ['b', 'd', 'a', 'e'])
     105
    51106    @modify_settings(ITEMS={
    52107        'append': 'e',
    53108        'prepend': 'a',
Back to Top