Beispiel #1
0
 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))
Beispiel #2
0
 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))
Beispiel #3
0
 def get_flags(self):
     return {
         'SOURCED_FLAG': [Condition('boolean', True), ],
         'NOT_IN_SETTINGS_FLAG': [
             Condition('boolean', False),
         ],
     }
Beispiel #4
0
 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))
Beispiel #5
0
 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))
Beispiel #6
0
    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).'
        ])
Beispiel #7
0
 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)]},
     )
Beispiel #8
0
 def test_get_flags_two_tuple(self):
     source = SettingsFlagsSource()
     flags = source.get_flags()
     self.assertEqual(
         flags,
         {"MY_FLAG": [Condition("boolean", True, required=False)]},
     )
Beispiel #9
0
 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")]})
Beispiel #10
0
 def test_get_flags_list_of_dicts(self):
     source = SettingsFlagsSource()
     flags = source.get_flags()
     self.assertEqual(
         flags, {'MY_FLAG': [
             Condition('boolean', True, required=True),
         ]})
Beispiel #11
0
 def test_get_flags_two_tuple(self):
     source = SettingsFlagsSource()
     flags = source.get_flags()
     self.assertEqual(
         flags, {'MY_FLAG': [
             Condition('boolean', True, required=False),
         ]})
Beispiel #12
0
 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'),
     ]})
Beispiel #13
0
    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).",
            ],
        )
Beispiel #14
0
    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),
            ]})
Beispiel #15
0
 def test_check_fn_none(self):
     condition = Condition("nonexistent", "value")
     result = condition.check()
     self.assertIsNone(result)
Beispiel #16
0
 def test_check_state(self):
     flag = Flag("MY_FLAG", [Condition("boolean", True)])
     self.assertTrue(flag.check_state())
Beispiel #17
0
 def test_check_state(self):
     flag = Flag('MY_FLAG', [Condition('boolean', True)])
     self.assertTrue(flag.check_state())
Beispiel #18
0
 def test_conditions(self):
     flag = Flag('MY_FLAG', [Condition('boolean', True)])
     self.assertEqual(len(list(flag.conditions)), 1)
Beispiel #19
0
 def test_check_fn_none(self):
     condition = Condition('nonexistent', 'value')
     result = condition.check()
     self.assertIsNone(result)
Beispiel #20
0
 def test_conditions(self):
     flag = Flag("MY_FLAG", [Condition("boolean", True)])
     self.assertEqual(len(list(flag.conditions)), 1)
Beispiel #21
0
 def get_flags(self):
     return {
         "SOURCED_FLAG": [Condition("boolean", True)],
         "NOT_IN_SETTINGS_FLAG": [Condition("boolean", False)],
     }