def test_update_config(self): # check that an ability reflects the value in app. property pre_ability = self.run_async(self.data_svc.locate('abilities', dict(ability_id='123'))) self.assertEqual('0.0.0.0', BaseWorld.get_config('app.contact.http')) self.assertEqual('curl 0.0.0.0', BaseWorld.decode_bytes(pre_ability[0].test)) # update property self.run_async(self.rest_svc.update_config(data=dict(prop='app.contact.http', value='127.0.0.1'))) # verify ability reflects new value post_ability = self.run_async(self.data_svc.locate('abilities', dict(ability_id='123'))) self.assertEqual('127.0.0.1', BaseWorld.get_config('app.contact.http')) self.assertEqual('curl 127.0.0.1', BaseWorld.decode_bytes(post_ability[0].test))
def test_update_config(self, loop, data_svc, rest_svc): internal_rest_svc = rest_svc(loop) # check that an ability reflects the value in app. property pre_ability = loop.run_until_complete(data_svc.locate('abilities', dict(ability_id='123'))) assert '0.0.0.0' == BaseWorld.get_config('app.contact.http') assert 'curl 0.0.0.0' == BaseWorld.decode_bytes(pre_ability[0].test) # update property loop.run_until_complete(internal_rest_svc.update_config(data=dict(prop='app.contact.http', value='127.0.0.1'))) # verify ability reflects new value post_ability = loop.run_until_complete(data_svc.locate('abilities', dict(ability_id='123'))) assert '127.0.0.1' == BaseWorld.get_config('app.contact.http') assert 'curl 127.0.0.1' == BaseWorld.decode_bytes(post_ability[0].test)
def test_filter_bs(self, loop, setup_planning_test, planning_svc): _, agent, operation, ability = setup_planning_test link = Link.load( dict(command=BaseWorld.encode_string(test_string), paw=agent.paw, ability=ability, executor=next(ability.executors), status=0)) f0 = Fact(trait='1_2_3', value='0') f1 = Fact(trait='a.b.c', value='1') f2 = Fact(trait='a.b.d', value='2') f3 = Fact(trait='a.b.e', value='3') f4 = Fact(trait='a.b.e', value='4') f5 = Fact(trait='a.b.e', value='5') f6 = Fact(trait='a.b.e', value='6') gen = loop.run_until_complete( planning_svc.add_test_variants([link], agent, facts=[f0, f1, f2, f3, f4, f5, f6])) assert len(gen) == 4 assert BaseWorld.decode_bytes( gen[1].display['command']) == target_string
async def test_trim_links(self, setup_planning_test, planning_svc): """ This test covers both remove_links_with_unset_variables and remove_links_missing_requirements. It uses a fact set that causes add_test_variants to create three links. One of which is the original that has not been populated with facts, this one gets pruned off by remove_links_with_unset_variables. Of the remaining two links that are populated, one is pruned off by a requirement that requires that the character 0 is in the link's command. The tests show that only one link is returned by trim_links and that the returned link is the one that is populated and adheres to the requirement. """ ability, agent, operation, _ = setup_planning_test link = Link.load(dict(command=BaseWorld.encode_string(test_string), paw=agent.paw, ability=ability, executor=next(ability.executors), status=0)) facts = [ Fact(trait='1_2_3', value='0'), Fact(trait='1_2_3', value='4'), Fact(trait='a.b.c', value='1'), Fact(trait='a.b.d', value='2'), Fact(trait='a.b.e', value='3'), ] operation.all_facts = async_wrapper(facts) operation.planner = MagicMock() planning_svc.load_module = async_wrapper(RequirementFake()) link.ability.requirements = [Requirement('fake_requirement', [{'fake': 'relationship'}])] trimmed_links = await planning_svc.trim_links(operation, [link], agent) assert len(trimmed_links) == 1 assert BaseWorld.decode_bytes(trimmed_links[0].display['command']) == target_string
async def test_get_cleanup_links(self, setup_planning_test, planning_svc): ability, agent, operation, _ = setup_planning_test executor = next(ability.executors) operation.add_link(Link.load(dict(command='', paw=agent.paw, ability=ability, executor=executor, status=0))) links = await planning_svc.get_cleanup_links(operation=operation, agent=agent) link_list = list(links) assert len(link_list) == 1 assert BaseWorld.decode_bytes(link_list[0].command) == executor.cleanup[0]
def test_encode_and_decode_string(self): plaintext = 'unit testing string' encoded_text = 'dW5pdCB0ZXN0aW5nIHN0cmluZw==' encoded_str = BaseWorld.encode_string(plaintext) assert encoded_str == encoded_text decoded_str = BaseWorld.decode_bytes(encoded_text) assert decoded_str == plaintext
async def wrapper(*args, **kwargs): agent, instructions = await func(*args, **kwargs) log = dict(paw=agent.paw, instructions=[ BaseWorld.decode_bytes(i.command) for i in instructions ], date=datetime.now().strftime('%Y-%m-%d %H:%M:%S')) args[0].report[agent.contact].append(log) return agent, instructions
async def wrapper(*args, **kwargs): agent, instructions = await func(*args, **kwargs) log = dict(paw=agent.paw, instructions=[ BaseWorld.decode_bytes(i.command) for i in instructions ], date=BaseWorld.get_current_timestamp()) args[0].report[agent.contact.upper()].append(log) return agent, instructions
def test_link_fact_coverage(self, loop, setup_planning_test, planning_svc): _, agent, operation, ability = setup_planning_test link = Link.load(dict(command=BaseWorld.encode_string(test_string), paw=agent.paw, ability=ability, status=0)) f1 = Fact(trait='a.b.c', value='1') f2 = Fact(trait='a.b.d', value='2') f3 = Fact(trait='a.b.e', value='3') gen = loop.run_until_complete(planning_svc.add_test_variants([link], agent, facts=[f1, f2, f3])) assert len(gen) == 2 assert BaseWorld.decode_bytes(gen[1].display['command']) == target_string
async def test_link_fact_coverage(self, setup_planning_test, planning_svc): _, agent, operation, ability = setup_planning_test link = Link.load(dict(command=BaseWorld.encode_string(test_string), paw=agent.paw, ability=ability, executor=next(ability.executors), status=0)) f0 = Fact(trait='1_2_3', value='0') f1 = Fact(trait='a.b.c', value='1') f2 = Fact(trait='a.b.d', value='2') f3 = Fact(trait='a.b.e', value='3') gen = await planning_svc.add_test_variants([link], agent, facts=[f0, f1, f2, f3]) assert len(gen) == 2 assert BaseWorld.decode_bytes(gen[1].display['command']) == target_string
def test_replace_app_props(base_world): base_object = BaseObject() command = 'echo #{foo} #{app.foo} #{app.bar} #{app.foo.do.not.replace.me}' replaced = base_object.replace_app_props(BaseWorld.encode_string(command)) expected = 'echo #{foo} foo bar #{app.foo.do.not.replace.me}' assert expected == BaseWorld.decode_bytes(replaced)
async def enforce(self, link, operation): return '0' in BaseWorld.decode_bytes(link.display['command'])