def test_add_a_functionality_with_percentage(self): fn = "FOO" self.backend.add_functionality(Feature(fn, None, 50)) self.backend.get_functionalities() | should.have_len(1) f, users = self.backend._get_functionality(fn) f.name | should.eql(fn) f.percentage | should.eql(50) users | should.be_empty().and_array()
def test_warns_when_unneeded(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") foo = self.inject(lambda: True) w | should.have_len(1) w[0].category | should.be(UserWarning)
def test_add_existing_an_user(self): fn = "FOO" self.backend.add_functionality(Feature(fn)) self.backend.get_functionalities() | should.have_len(1) f, users = self.backend._get_functionality(fn) users | should.be_empty().and_array() self.backend.add(fn, "bar") self.backend.add(fn, "bar") f, users = self.backend._get_functionality(fn) users | should.eql(['bar'])
def test_add_a_disabled_functionality_with_percentage(self): fn = "FOO" func = Feature(fn, None, 50) func.enabled = False self.backend.add_functionality(func) self.backend.get_functionalities() | should.have_len(1) f, users = self.backend._get_functionality(fn) f.name | should.eql(fn) f.percentage | should.eql(50) f.enabled | should.be_falsy() users | should.be_empty().and_array()
def test_no_warns_when_unneeded(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") class NoUse(object): __metaclass__ = MetaInject(self.inject) def foo(self): pass NoUse() w | should.have_len(0)
def test_deprecated_property(self): @self.inject def test(foo=InjectorPatchTests): return foo self.inject.dependencies = {InjectorPatchTests: 'foo'} with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") test() | should.eql('foo') w | should.have_len(1) w[0].category | should.be(UserWarning)
def test_overrides_a_functionality_with_same_name(self): self.rollout.add_func(self.FN, lambda x: x.id) self.rollout.backend.get_functionalities() | should.have_len(1)
def test_register_two_functionalities(self): self.rollout.add_func('bar', lambda x: x.id, percentage=0) self.rollout.backend.get_functionalities() | should.have_len(2) all_of([self.FN, 'bar']) | should.be_in(self.rollout.backend.get_functionalities())
def test_register_a_functionality(self): self.rollout.backend.get_functionalities() | should.have_len(1)