def test_creating_existing_toggle(self): ft_tgl = self.active_ft_tgl tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) with self.assertRaises(FeatureToggleAlreadyExists): tgl.create()
def test_creating_existing_toggle_with_raise_if_does_not_exists(self): ft_tgl = self.active_ft_tgl tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code, raise_does_not_exist=False) with self.assertRaises(FeatureToggleAlreadyExists): tgl.create()
def test_is_enabled_with_start_date_less_than_now(self): yesterday = datetime.date.today() - datetime.timedelta(1) ft_tgl = self.active_ft_tgl ft_tgl.set_attribute(constants.FeatureToggle.Attributes.START_DATE, yesterday) tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertTrue(tgl.is_enabled())
def test_is_enabled_with_inactive_toggle_with_end_date(self): tomorrow = datetime.date.today() + datetime.timedelta(1) ft_tgl = self.inactive_ft_tgl ft_tgl.set_attribute(constants.FeatureToggle.Attributes.END_DATE, tomorrow) tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertFalse(tgl.is_enabled())
def test_is_enabled_with_start_date_greater_than_now(self): tomorrow = datetime.date.today() + datetime.timedelta(1) ft_tgl = self.active_ft_tgl ft_tgl.set_attribute(constants.FeatureToggle.Attributes.START_DATE, tomorrow) tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertFalse(tgl.is_enabled())
def test_creating_non_existing_toggle(self): name = 'test3' code = 'TEST3' tgl = Toggle(environment=self.active_ft_tgl.environment, name=name, code=code, raise_does_not_exist=False) tgl.create() self.assertEquals(tgl.name, name) self.assertEquals(tgl.code, code)
def test_is_enabled_with_active_toggle_with_both_start_and_end_date_for_invalid_range( self): yesterday = datetime.date.today() - datetime.timedelta(1) tomorrow = datetime.date.today() + datetime.timedelta(1) ft_tgl = self.active_ft_tgl ft_tgl.set_attribute(constants.FeatureToggle.Attributes.START_DATE, tomorrow) ft_tgl.set_attribute(constants.FeatureToggle.Attributes.END_DATE, yesterday) tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertFalse(tgl.is_enabled())
def test_creating_non_existing_toggle_with_attributes(self): name = 'test5' code = 'TEST5' attrib_key = 'module' attrib_value = 'TEST5' tgl = Toggle(environment=self.active_ft_tgl.environment, name=name, code=code, attributes={attrib_key: attrib_value}, raise_does_not_exist=False) tgl.create() self.assertEquals(tgl.name, name) self.assertEquals(tgl.code, code) self.assertEquals(getattr(tgl, attrib_key), attrib_value)
def test_non_existing_toggle_with_error_suppression(self): name = '-' tgl = Toggle(environment=constants.FeatureToggle.Environment.LOCAL, name=name, code='-', raise_does_not_exist=False) self.assertEqual(tgl.name, name)
def test_is_attribute_of_a_toggle(self): time_bomb = '__time_bomb__' ft_tgl = self.active_ft_tgl ft_tgl.set_attribute(constants.FeatureToggle.Attributes.TIME_BOMB, time_bomb) tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertEquals( getattr(tgl, constants.FeatureToggle.Attributes.TIME_BOMB), time_bomb)
def convert(cls, toggle_model): toggle_attributes = toggle_model.attibutes.all().values('key', 'value') toggle_attributes = { attrib['key']: attrib['value'] for attrib in toggle_attributes.items() } tgl = Toggle( uid=toggle_model.uid, name=toggle_model.name, environment=toggle_model.environment, is_active=toggle_model.is_active, start_date_time=toggle_model.start_date_time, end_date_time=toggle_model.end_date_time, time_bomb=toggle_model.time_bomb, attributes=toggle_attributes, ) return tgl
def test_given_simple_active_toggle_when_evaluated_then_returns_true(): """ test_case_type: positive test_case_complexity: simple """ today = utc_now() some_far_away_date = today + datetime.timedelta(days=9999) simple_active_toggle = Toggle( uid=1, name="test", environment=Environments.Local, is_active=True, start_date_time=today, end_date_time=some_far_away_date, ) assert bool(simple_active_toggle) is True
def test_toggle_without_name_and_code(self): with self.assertRaises(RuntimeError): Toggle(environment=constants.FeatureToggle.Environment.LOCAL)
def test_toggle_with_invalid_environment(self): with self.assertRaises(AssertionError): Toggle(environment='__invalid__', name=self.active_ft_tgl.name, code=self.active_ft_tgl.code)
def test_is_active_with_inactive_toggle(self): ft_tgl = self.inactive_ft_tgl tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.name, code=ft_tgl.code) self.assertFalse(tgl.is_active())
def test_existing_toggle_with_code(self): ft_tgl = self.inactive_ft_tgl tgl = Toggle(environment=ft_tgl.environment, name=ft_tgl.code) self._toggle_equality_test(tgl, ft_tgl)
def test_non_existing_toggle(self): with self.assertRaises(FeatureToggleDoesNotExist): Toggle(environment=constants.FeatureToggle.Environment.LOCAL, name='-', code='-')