Пример #1
0
 def test_error_is_raised_for_invalid_type_settings(self):
     test_func = apply_settings(test_function)
     try:
         test_func(settings=['current_period', False, 'current'])
     except Exception as error:
         self.error = error
         self.then_error_was_raised(TypeError, ["settings can only be either dict or instance of Settings class"])
Пример #2
0
 def test_apply_settings_should_return_default_settings_when_called_with_no_settings_after_once_called_with_settings_supplied_to_the_decorated_function(
         self):
     test_func = apply_settings(test_function)
     settings_once = test_func(settings={'PREFER_DATES_FROM': 'past'})
     settings_twice = test_func()
     self.assertNotEqual(settings_once, self.default_settings)
     self.assertEqual(settings_twice, self.default_settings)
Пример #3
0
 def test_apply_settings_shouldnt_create_new_settings_when_same_settings_are_supplied_to_the_decorated_function_more_than_once(  # noqa E501
     self
 ):
     test_func = apply_settings(test_function)
     settings_once = test_func(settings={'PREFER_DATES_FROM': 'past'})
     settings_twice = test_func(settings={'PREFER_DATES_FROM': 'past'})
     self.assertEqual(settings_once, settings_twice)
Пример #4
0
    def test_error_is_raised_when_none_is_passed_in_settings(self):
        test_func = apply_settings(test_function)
        with self.assertRaisesRegexp(TypeError, 'Invalid.*None\}'):
            test_func(settings={'PREFER_DATES_FROM': None})

        with self.assertRaisesRegexp(TypeError, 'Invalid.*None\}'):
            test_func(settings={'TIMEZONE': None})

        with self.assertRaisesRegexp(TypeError, 'Invalid.*None\}'):
            test_func(settings={'TO_TIMEZONE': None})
Пример #5
0
 def test_apply_settings_should_return_non_default_settings_when_settings_are_supplied_to_the_decorated_function(
         self):
     test_func = apply_settings(test_function)
     self.assertNotEqual(test_func(settings={'PREFER_DATES_FROM': 'past'}),
                         self.default_settings)
Пример #6
0
 def test_apply_settings_should_return_default_settings_when_no_settings_are_supplied_to_the_decorated_function(
         self):
     test_func = apply_settings(test_function)
     self.assertEqual(test_func(), self.default_settings)
Пример #7
0
 def test_apply_settings_should_return_default_settings_when_called_with_no_settings_after_once_called_with_settings_supplied_to_the_decorated_function(self):
     test_func = apply_settings(test_function)
     settings_once = test_func(settings={'PREFER_DATES_FROM': 'past'})
     settings_twice = test_func()
     self.assertNotEqual(settings_once, self.default_settings)
     self.assertEqual(settings_twice, self.default_settings)
Пример #8
0
 def test_apply_settings_should_not_create_new_settings_when_same_settings_are_supplied_to_the_decorated_function_more_than_once(self):
     test_func = apply_settings(test_function)
     settings_once = test_func(settings={'PREFER_DATES_FROM': 'past'})
     settings_twice = test_func(settings={'PREFER_DATES_FROM': 'past'})
     self.assertEqual(settings_once, settings_twice)
Пример #9
0
 def test_apply_settings_should_return_non_default_settings_when_settings_are_supplied_to_the_decorated_function(self):
     test_func = apply_settings(test_function)
     self.assertNotEqual(test_func(settings={'PREFER_DATES_FROM': 'past'}), self.default_settings)
Пример #10
0
 def test_apply_settings_should_return_default_settings_when_no_settings_are_supplied_to_the_decorated_function(self):
     test_func = apply_settings(test_function)
     self.assertEqual(test_func(), self.default_settings)