Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:added toggle methods to basemodel #293

Closed
24 changes: 24 additions & 0 deletions edx_toggles/tests/test_waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -29,6 +30,29 @@ def test_constructor(self):
self.assertEqual("module1", waffle.module_name)
self.assertEqual(1, len(NaiveWaffle.get_instances()))

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
self.assertEqual(False, waffle.is_disabled())
# test is_toggle_on method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Theo-flux: This comment is out of sync. Rather than updating it, I think the assertions are clear enough as-is and you could simply delete all of these # test ... comments from these two tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Theo-flux? 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Theo-flux: I'd love to have you be able to land this. Checking in one more time. Otherwise - I may end up taking this over at some point. Just let me know. Thanks.

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):
"""
Expand Down
9 changes: 9 additions & 0 deletions edx_toggles/toggles/internal/base.py
robrap marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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_disabled(self):
return not self.is_enabled()

def is_toggle_on(self):
return self.is_enabled()

def is_toggle_off(self):
return self.is_disabed()
robrap marked this conversation as resolved.
Show resolved Hide resolved