def test_switch_main_different_contexts(fake_heksher_service, monkeypatch): monkeypatch.setattr(fake_heksher_service, 'context_features', ['a', 'b', 'c']) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf1', {'outcome': 'created'}) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf2', {'outcome': 'created'}) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf3', {'outcome': 'created'}) setting1 = Setting('conf1', int, ['a'], 74) client1 = ThreadHeksherClient(fake_heksher_service.local_url(), 10000000, ['a', 'b']) client1.track_contexts(a=['a', 'b'], b=TRACK_ALL) client1.set_as_main() setting2 = Setting('conf2', int, ['b'], 26) with fake_heksher_service.query_rules.patch( JSONResponse({ 'settings': { 'conf1': { 'rules': [{ 'context_features': [], 'value': 5, 'rule_id': 1 }], 'default_value': 74 }, 'conf2': { 'rules': [{ 'context_features': [], 'value': 4, 'rule_id': 2 }], 'default_value': 26 } } })): client1.reload() assert len(client1._tracked_settings) == 2 assert setting1.get(a='') == 5 assert setting2.get(b='') == 4 client2 = ThreadHeksherClient(fake_heksher_service.local_url(), 10000000, ['b', 'c']) client2.track_contexts(a=['a', 'b'], b=TRACK_ALL) client1.close() with raises(RuntimeError): # not allowed client2.set_as_main()
def test_switch_main_from_temp(fake_heksher_service, monkeypatch): monkeypatch.setattr(fake_heksher_service, 'context_features', ['a', 'b']) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf1', {'outcome': 'created'}) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf2', {'outcome': 'created'}) setting1 = Setting('conf1', int, ['a'], 74) client = ThreadHeksherClient(fake_heksher_service.local_url(), 10000000, ['a', 'b']) client.track_contexts(a=['a', 'b'], b=TRACK_ALL) client.set_as_main() setting2 = Setting('conf2', int, ['b'], 26) with fake_heksher_service.query_rules.patch( JSONResponse({ 'settings': { 'conf1': { 'rules': [{ 'context_features': [], 'value': 5, 'rule_id': 1 }], 'default_value': 74 }, 'conf2': { 'rules': [{ 'context_features': [], 'value': 4, 'rule_id': 2 }], 'default_value': 26 } } })): client.reload() assert setting1.get(a='') == 5 assert setting2.get(b='') == 4 client.close()
def test_switch_main_different_tracking(fake_heksher_service, monkeypatch, caplog): monkeypatch.setattr(fake_heksher_service, 'context_features', ['a', 'b']) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf1', {'outcome': 'created'}) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf2', {'outcome': 'created'}) monkeypatch.setitem(fake_heksher_service.declare_responses, 'conf3', {'outcome': 'created'}) setting1 = Setting('conf1', int, ['a'], 74) client1 = ThreadHeksherClient(fake_heksher_service.local_url(), 10000000, ['a', 'b']) client1.track_contexts(a=['a', 'b'], b=TRACK_ALL) client1.set_as_main() setting2 = Setting('conf2', int, ['b'], 26) with fake_heksher_service.query_rules.patch( JSONResponse({ 'settings': { 'conf1': { 'rules': [{ 'context_features': [], 'value': 5, 'rule_id': 1 }], 'default_value': 74 }, 'conf2': { 'rules': [{ 'context_features': [], 'value': 4, 'rule_id': 2 }], 'default_value': 26 } } })): client1.reload() assert len(client1._tracked_settings) == 2 assert setting1.get(a='') == 5 assert setting2.get(b='') == 4 client2 = ThreadHeksherClient(fake_heksher_service.local_url(), 10000000, ['a', 'b']) client2.track_contexts(a=['a', 'b', 'c'], b="shoobidoobi") client1.close() with assert_logs( caplog, WARNING ): # it should warn you you're doing bad things, and that your tracking differs client2.set_as_main() setting3 = Setting('conf3', int, ['b'], 59) with fake_heksher_service.query_rules.patch( JSONResponse({ 'settings': { 'conf1': { 'rules': [{ 'context_features': [], 'value': 5, 'rule_id': 1 }], 'default_value': 74, }, 'conf2': { 'rules': [{ 'context_features': [], 'value': 4, 'rule_id': 2 }], 'default_value': 26, }, 'conf3': { 'rules': [{ 'context_features': [], 'value': 3, 'rule_id': 3 }], 'default_value': 59, } } })): client2.reload() assert setting1.get(a='') == 5 assert setting2.get(b='') == 4 assert setting3.get(b='') == 3 client2.close()