From 8014609e845057d7f7a16ba18a520ab9c70cc18c Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 8 Jul 2023 02:18:10 +0100 Subject: [PATCH 1/7] feat: added toggle methods to basemodel --- edx_toggles/toggles/internal/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/edx_toggles/toggles/internal/base.py b/edx_toggles/toggles/internal/base.py index 8c64be10..3d2404b7 100644 --- a/edx_toggles/toggles/internal/base.py +++ b/edx_toggles/toggles/internal/base.py @@ -37,3 +37,12 @@ def get_instances(cls): Return the list of class instances sorted by name. """ return sorted(cls._class_instances, key=lambda instance: instance.name) + + def is_disabed(self): + return not self.is_enabled() + + def is_toggle_on(self): + return self.is_enabled() + + def is_toggle_off(self): + return self.is_disabed() From c3709917aa2a06f1321c04134456c3c68f0779a3 Mon Sep 17 00:00:00 2001 From: Theo Date: Thu, 17 Aug 2023 07:18:59 +0100 Subject: [PATCH 2/7] test:toggle methods' testcase in BaseWaffleTest class --- edx_toggles/tests/test_waffle.py | 11 +++++++++++ edx_toggles/toggles/internal/base.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/edx_toggles/tests/test_waffle.py b/edx_toggles/tests/test_waffle.py index 69f6a14a..601fc6e8 100644 --- a/edx_toggles/tests/test_waffle.py +++ b/edx_toggles/tests/test_waffle.py @@ -29,6 +29,17 @@ def test_constructor(self): self.assertEqual("module1", waffle.module_name) self.assertEqual(1, len(NaiveWaffle.get_instances())) + def test_toggle_methods(self): + waffle = NaiveWaffle("namespaced.name", "module1") + # test is_enabled method + self.assertEqual(True, waffle.is_enabled()) + #test is_disabled method + self.assertEqual(False, waffle.is_disabled()) + #test is_toggle_on method + self.assertEqual(waffle.is_enabled(), waffle.is_toggle_on()) + #test is_toggle_off method + self.assertEqual(waffle.is_disabled(), waffle.is_toggle_off()) + class WaffleFlagTests(TestCase): """ diff --git a/edx_toggles/toggles/internal/base.py b/edx_toggles/toggles/internal/base.py index 3d2404b7..a873840a 100644 --- a/edx_toggles/toggles/internal/base.py +++ b/edx_toggles/toggles/internal/base.py @@ -38,7 +38,7 @@ def get_instances(cls): """ return sorted(cls._class_instances, key=lambda instance: instance.name) - def is_disabed(self): + def is_disabled(self): return not self.is_enabled() def is_toggle_on(self): From 9f0b6ae17eaff73ad7162ffce146d5ff67536d64 Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 18 Aug 2023 06:50:10 +0100 Subject: [PATCH 3/7] test: added test_toggle_methods_with_disabled_waffle in BaseWaffleTest --- edx_toggles/tests/test_waffle.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/edx_toggles/tests/test_waffle.py b/edx_toggles/tests/test_waffle.py index 601fc6e8..c4f02aea 100644 --- a/edx_toggles/tests/test_waffle.py +++ b/edx_toggles/tests/test_waffle.py @@ -2,6 +2,7 @@ Unit tests for waffle classes. """ +from unittest.mock import patch from django.test import TestCase from edx_toggles.toggles import NonNamespacedWaffleFlag, NonNamespacedWaffleSwitch, WaffleFlag, WaffleSwitch @@ -29,16 +30,28 @@ def test_constructor(self): self.assertEqual("module1", waffle.module_name) self.assertEqual(1, len(NaiveWaffle.get_instances())) - def test_toggle_methods(self): + def test_toggle_methods_with_enabled_waffle(self): waffle = NaiveWaffle("namespaced.name", "module1") # test is_enabled method self.assertEqual(True, waffle.is_enabled()) - #test is_disabled method + # test is_disabled method self.assertEqual(False, waffle.is_disabled()) - #test is_toggle_on method - self.assertEqual(waffle.is_enabled(), waffle.is_toggle_on()) - #test is_toggle_off method - self.assertEqual(waffle.is_disabled(), waffle.is_toggle_off()) + # test is_toggle_on method + self.assertEqual(True, waffle.is_toggle_on()) + # test is_toggle_off method + self.assertEqual(False, waffle.is_toggle_off()) + + def test_toggle_methods_with_disabled_waffle(self): + with patch.object(NaiveWaffle, "is_enabled", return_value=False): + waffle = NaiveWaffle("namespaced.name", "module1") + # test is_enabled method + self.assertEqual(False, waffle.is_enabled()) + # test is_disabled method + self.assertEqual(True, waffle.is_disabled()) + # test is_toggle_on method + self.assertEqual(False, waffle.is_toggle_on()) + # test is_toggle_off method + self.assertEqual(True, waffle.is_toggle_off()) class WaffleFlagTests(TestCase): From 08ce0d9c25fd148cb036e7734c7773004984f653 Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 18 Aug 2023 19:17:37 +0100 Subject: [PATCH 4/7] refactor: is_disabed changed to is_disabled --- edx_toggles/toggles/internal/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edx_toggles/toggles/internal/base.py b/edx_toggles/toggles/internal/base.py index a873840a..bdd1f020 100644 --- a/edx_toggles/toggles/internal/base.py +++ b/edx_toggles/toggles/internal/base.py @@ -45,4 +45,4 @@ def is_toggle_on(self): return self.is_enabled() def is_toggle_off(self): - return self.is_disabed() + return self.is_disabled() From 60ee15c394941129b18cca6f6d95451fd9c8e544 Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 16 Oct 2023 16:45:53 +0100 Subject: [PATCH 5/7] refactor: removed whitespace from file. --- CHANGELOG.rst | 5 +++++ edx_toggles/__init__.py | 2 +- edx_toggles/toggles/internal/base.py | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8339924a..7f0ccd9c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,11 @@ Change Log Unreleased ~~~~~~~~~~ +[5.2.0] - 2023-10-16 +-------------------- + +* Added is_disabled, is_toggled_on, and is_toggled_off methods to BaseToggle. + [5.1.0] - 2023-08-02 -------------------- diff --git a/edx_toggles/__init__.py b/edx_toggles/__init__.py index 133fd408..dcaced9f 100644 --- a/edx_toggles/__init__.py +++ b/edx_toggles/__init__.py @@ -2,4 +2,4 @@ Library and utilities for feature toggles. """ -__version__ = '5.1.1' +__version__ = '5.2.0' diff --git a/edx_toggles/toggles/internal/base.py b/edx_toggles/toggles/internal/base.py index bdd1f020..918ee3a1 100644 --- a/edx_toggles/toggles/internal/base.py +++ b/edx_toggles/toggles/internal/base.py @@ -41,8 +41,8 @@ def get_instances(cls): def is_disabled(self): return not self.is_enabled() - def is_toggle_on(self): + def is_toggled_on(self): return self.is_enabled() - def is_toggle_off(self): + def is_toggled_off(self): return self.is_disabled() From e636210412ab06404b606b138fc0e41966cdca2c Mon Sep 17 00:00:00 2001 From: Theo Date: Tue, 17 Oct 2023 04:08:55 +0100 Subject: [PATCH 6/7] fix: is_toggle_on/of changed to is_toggled_on/of --- edx_toggles/tests/test_waffle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edx_toggles/tests/test_waffle.py b/edx_toggles/tests/test_waffle.py index c4f02aea..32309431 100644 --- a/edx_toggles/tests/test_waffle.py +++ b/edx_toggles/tests/test_waffle.py @@ -49,9 +49,9 @@ def test_toggle_methods_with_disabled_waffle(self): # test is_disabled method self.assertEqual(True, waffle.is_disabled()) # test is_toggle_on method - self.assertEqual(False, waffle.is_toggle_on()) + self.assertEqual(False, waffle.is_toggled_on()) # test is_toggle_off method - self.assertEqual(True, waffle.is_toggle_off()) + self.assertEqual(True, waffle.is_toggled_off()) class WaffleFlagTests(TestCase): From 4d4c17ea6e50e9e621a6ec1df750b8f81c97907a Mon Sep 17 00:00:00 2001 From: Theo Date: Tue, 17 Oct 2023 04:11:52 +0100 Subject: [PATCH 7/7] fix: is_toggle_on/of changed to is_toggled_on/of --- edx_toggles/tests/test_waffle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edx_toggles/tests/test_waffle.py b/edx_toggles/tests/test_waffle.py index 32309431..7a823210 100644 --- a/edx_toggles/tests/test_waffle.py +++ b/edx_toggles/tests/test_waffle.py @@ -37,9 +37,9 @@ def test_toggle_methods_with_enabled_waffle(self): # test is_disabled method self.assertEqual(False, waffle.is_disabled()) # test is_toggle_on method - self.assertEqual(True, waffle.is_toggle_on()) + self.assertEqual(True, waffle.is_toggled_on()) # test is_toggle_off method - self.assertEqual(False, waffle.is_toggle_off()) + self.assertEqual(False, waffle.is_toggled_off()) def test_toggle_methods_with_disabled_waffle(self): with patch.object(NaiveWaffle, "is_enabled", return_value=False):