Skip to content

Commit

Permalink
Merge pull request #48 from cfpb/replace-optional-text
Browse files Browse the repository at this point in the history
Remove "optional" from state string language
  • Loading branch information
willbarton authored Jul 22, 2019
2 parents dcf4163 + f9959f5 commit 6713ed4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
8 changes: 4 additions & 4 deletions flags/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def __eq__(self, other):

def check_state(self, **kwargs):
""" Determine this flag's state based on any of its conditions """
optional_conditions = [
non_required_conditions = [
c for c in self.conditions if not c.required
]
required_conditions = [
c for c in self.conditions if c.required
]

if (len(optional_conditions) == 0
if (len(non_required_conditions) == 0
and len(required_conditions) == 0):
return False

Expand All @@ -59,9 +59,9 @@ def check_state(self, **kwargs):
state = (
any(
state for c, state in checked_conditions
if c in optional_conditions
if c in non_required_conditions
)
if len(optional_conditions) > 0
if len(non_required_conditions) > 0
else True
) and (
all(
Expand Down
2 changes: 0 additions & 2 deletions flags/templates/flags/panels/flags.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ <h4>{{ flag.name }}</h4>
<td>
{% if condition.required %}
{% trans "Required" %}
{% else %}
{% trans "Optional" %}
{% endif %}
</td>
</tr>
Expand Down
7 changes: 5 additions & 2 deletions flags/templatetags/flags_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def state_str(flag):

state_str += _(' when <i>all</i> required conditions')

if len(non_bool_conditions) == len(req_conditions):
if len(non_bool_conditions) == len(req_conditions) or is_enabled:
state_str += _(' are met')

# If there aren't any required conditions, it's simpler.
Expand All @@ -81,7 +81,10 @@ def state_str(flag):
if len(non_bool_conditions) > len(req_conditions):
if len(req_conditions) > 0:
state_str += _(' and')
state_str += _(' <i>any</i> optional condition is met')
state_str += _(' <i>any</i>')
if len(req_conditions) > 0:
state_str += _(' non-required')
state_str += _(' condition is met')

# Finally, if there are no non-boolean conditions and no required boolean
# conditions, we can just say it's enabled or disabled for all requests.
Expand Down
37 changes: 25 additions & 12 deletions flags/tests/test_templatetags_flags_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TestStateStrTemplateTag(TestCase):
@override_settings(FLAGS={'MYFLAG': [
('anonymous', 'False', True),
]})
def test_state_str_required_no_optional_no_bool(self):
def test_state_str_required_no_non_required_no_bool(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>all</i> required conditions '
Expand All @@ -55,7 +55,7 @@ def test_state_str_required_no_optional_no_bool(self):
('anonymous', 'False', True),
('boolean', True),
]})
def test_state_str_required_no_optional_bool_true(self):
def test_state_str_required_no_non_required_bool_true(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>all</i> required conditions '
Expand All @@ -67,7 +67,7 @@ def test_state_str_required_no_optional_bool_true(self):
('anonymous', 'False', True),
('boolean', False),
]})
def test_state_str_required_no_optional_bool_false(self):
def test_state_str_required_no_non_required_bool_false(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>disabled</b> for all requests, '
Expand All @@ -80,11 +80,11 @@ def test_state_str_required_no_optional_bool_false(self):
('path matches', '/mypath'),
('boolean', False),
]})
def test_state_str_required_optional_bool_false(self):
def test_state_str_required_non_required_bool_false(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>all</i> required conditions '
'and <i>any</i> optional condition is met.',
'and <i>any</i> non-required condition is met.',
state_str(flag)
)

Expand All @@ -93,7 +93,7 @@ def test_state_str_required_optional_bool_false(self):
('boolean', True, True),
('path matches', '/mypath'),
]})
def test_state_str_required_optional_bool_true_required(self):
def test_state_str_required_non_required_bool_true_required(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> for all requests.',
Expand All @@ -105,7 +105,7 @@ def test_state_str_required_optional_bool_true_required(self):
('boolean', False, True),
('path matches', '/mypath'),
]})
def test_state_str_required_optional_bool_false_required(self):
def test_state_str_required_non_required_bool_false_required(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>disabled</b> for all requests.',
Expand All @@ -116,7 +116,7 @@ def test_state_str_required_optional_bool_false_required(self):
('anonymous', 'False'),
('boolean', True),
]})
def test_state_str_no_required_optional_bool_true(self):
def test_state_str_no_required_non_required_bool_true(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> for all requests.',
Expand All @@ -127,21 +127,34 @@ def test_state_str_no_required_optional_bool_true(self):
('anonymous', 'False', True),
('path matches', '/mypath'),
]})
def test_state_str_required_optional_no_bool(self):
def test_state_str_required_non_required_no_bool(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>all</i> required conditions '
'and <i>any</i> optional condition is met.',
'and <i>any</i> non-required condition is met.',
state_str(flag)
)

@override_settings(FLAGS={'MYFLAG': [
('anonymous', 'False', True),
('path matches', '/mypath'),
('boolean', True)
]})
def test_state_str_required_non_required_bool(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>all</i> required conditions '
'are met.',
state_str(flag)
)

@override_settings(FLAGS={'MYFLAG': [
('path matches', '/mypath'),
]})
def test_state_str_non_bool_optional(self):
def test_state_str_non_bool_non_required(self):
flag = get_flags().get('MYFLAG')
self.assertEqual(
'MYFLAG is <b>enabled</b> when <i>any</i> optional condition '
'MYFLAG is <b>enabled</b> when <i>any</i> condition '
'is met.',
state_str(flag)
)
Expand Down

0 comments on commit 6713ed4

Please sign in to comment.