def test_check_state_multiple_conditions_required_failure(self): request = Mock(path='/foo') flag = Flag('MY_FLAG', [ Condition('boolean', False, required=True), Condition('path matches', '/foo', required=True) ]) self.assertFalse(flag.check_state(request=request))
def test_check_state_multiple_conditions(self): request = Mock(path='/foo') flag = Flag( 'MY_FLAG', [Condition('boolean', True), Condition('path matches', '/foo')]) self.assertTrue(flag.check_state(request=request))
def get_flags(self): return { 'SOURCED_FLAG': [Condition('boolean', True), ], 'NOT_IN_SETTINGS_FLAG': [ Condition('boolean', False), ], }
def test_check_state_multiple_conditions_not_required(self): request = Mock(path="/foo") flag = Flag( "MY_FLAG", [Condition("boolean", False), Condition("path matches", "/foo")], ) self.assertTrue(flag.check_state(request=request))
def test_check_state_multiple_conditions_required_failure(self): request = Mock(path="/foo") flag = Flag( "MY_FLAG", [ Condition("boolean", False, required=True), Condition("path matches", "/foo", required=True), ], ) self.assertFalse(flag.check_state(request=request))
def test_flag_check_state_logs_state(self): flag = Flag( 'MY_FLAG', [Condition('boolean', False), Condition('path matches', '/foo')]) with self.assertLogs('flags.sources', level='INFO') as logger: flag.check_state(request=Mock(path='/bar')) flag.check_state(request=Mock(path='/foo')) self.assertEqual(logger.output, [ 'INFO:flags.sources:Flag MY_FLAG evaluated False with ' 'conditions: boolean (False), path matches (False).', 'INFO:flags.sources:Flag MY_FLAG evaluated True with ' 'conditions: boolean (False), path matches (True).' ])
def test_get_flags_list_of_dicts_without_required(self): source = SettingsFlagsSource() flags = source.get_flags() self.assertEqual( flags, {"MY_FLAG": [Condition("boolean", True, required=False)]}, )
def test_get_flags_two_tuple(self): source = SettingsFlagsSource() flags = source.get_flags() self.assertEqual( flags, {"MY_FLAG": [Condition("boolean", True, required=False)]}, )
def test_get_flags(self): FlagState.objects.create(name="MY_FLAG", condition="boolean", value="False") source = DatabaseFlagsSource() flags = source.get_flags() self.assertEqual(flags, {"MY_FLAG": [Condition("boolean", "False")]})
def test_get_flags_list_of_dicts(self): source = SettingsFlagsSource() flags = source.get_flags() self.assertEqual( flags, {'MY_FLAG': [ Condition('boolean', True, required=True), ]})
def test_get_flags_two_tuple(self): source = SettingsFlagsSource() flags = source.get_flags() self.assertEqual( flags, {'MY_FLAG': [ Condition('boolean', True, required=False), ]})
def test_get_flags(self): FlagState.objects.create(name='MY_FLAG', condition='boolean', value='False') source = DatabaseFlagsSource() flags = source.get_flags() self.assertEqual(flags, {'MY_FLAG': [ Condition('boolean', 'False'), ]})
def test_flag_check_state_logs_state(self): flag = Flag( "MY_FLAG", [Condition("boolean", False), Condition("path matches", "/foo")], ) with self.assertLogs("flags.sources", level="INFO") as logger: flag.check_state(request=Mock(path="/bar")) flag.check_state(request=Mock(path="/foo")) self.assertEqual( logger.output, [ "INFO:flags.sources:Flag MY_FLAG evaluated False with " "conditions: boolean (False), path matches (False).", "INFO:flags.sources:Flag MY_FLAG evaluated True with " "conditions: boolean (False), path matches (True).", ], )
def test_get_flags_dict(self): source = SettingsFlagsSource() with warnings.catch_warnings(record=True) as warning_list: flags = source.get_flags() self.assertTrue( any(item.category == FutureWarning for item in warning_list)) self.assertEqual( flags, {'MY_FLAG': [ Condition('boolean', True, required=False), ]})
def test_check_fn_none(self): condition = Condition("nonexistent", "value") result = condition.check() self.assertIsNone(result)
def test_check_state(self): flag = Flag("MY_FLAG", [Condition("boolean", True)]) self.assertTrue(flag.check_state())
def test_check_state(self): flag = Flag('MY_FLAG', [Condition('boolean', True)]) self.assertTrue(flag.check_state())
def test_conditions(self): flag = Flag('MY_FLAG', [Condition('boolean', True)]) self.assertEqual(len(list(flag.conditions)), 1)
def test_check_fn_none(self): condition = Condition('nonexistent', 'value') result = condition.check() self.assertIsNone(result)
def test_conditions(self): flag = Flag("MY_FLAG", [Condition("boolean", True)]) self.assertEqual(len(list(flag.conditions)), 1)
def get_flags(self): return { "SOURCED_FLAG": [Condition("boolean", True)], "NOT_IN_SETTINGS_FLAG": [Condition("boolean", False)], }