def _recreate_config_file(): with app_resources.stream("config/server-docker-dev.yaml") as f: cfg = yaml.safe_load(f) # test webserver works in host cfg["main"]['host'] = '127.0.0.1' cfg["director"]["host"] = "127.0.0.1" with config_file_path.open('wt') as f: yaml.dump(cfg, f, default_flow_style=False)
async def test_checked_permissions(access_model): R = UserRole # alias MOCKPATH = "data/fake-template-projects.json" with resources.stream(MOCKPATH) as fh: data = json.load(fh) current = {} for prj in data: if prj["uuid"] == "template-uuid-1234-a1a7-f7d4f3a8f26b": current = prj break assert current, "Did '%s' changed??" % MOCKPATH # updates both allowed and not allowed fields candidate = copy.deepcopy(current) candidate["workbench"]["template-uuid-409d-998c-c1f04de67f8b"]["inputs"][ "Kr"] = 66 # ReadOnly! candidate["workbench"]["template-uuid-409d-998c-c1f04de67f8b"]["inputs"][ "Na"] = 66 # ReadWrite assert not await access_model.can( R.ANONYMOUS, "study.pipeline.node.inputs.update", context={ "current": current, "candidate": candidate }, ) # updates allowed fields candidate = copy.deepcopy(current) candidate["workbench"]["template-uuid-409d-998c-c1f04de67f8b"]["inputs"][ "Na"] = 66 # ReadWrite assert await access_model.can( R.ANONYMOUS, "study.pipeline.node.inputs.update", context={ "current": current, "candidate": candidate }, ) # udpates not permitted fields candidate = copy.deepcopy(current) candidate["description"] = "not allowed to write here" assert not await access_model.can( R.ANONYMOUS, "study.pipeline.node.inputs.update", context={ "current": current, "candidate": candidate }, )
def load_template_projects(): projects = [] projects_names = [ name for name in resources.listdir("data") if "template-projects" in name ] for name in projects_names: with resources.stream(f"data/{name}") as fp: projects.extend(json.load(fp)) return projects
def test_validate_component_schema(resource_name, api_version_prefix): try: with resources.stream( f"api/{api_version_prefix}/schemas/{resource_name}") as fh: schema_under_test = json.load(fh) validator = jsonschema.validators.validator_for(schema_under_test) validator.check_schema(schema_under_test) except jsonschema.SchemaError as err: pytest.fail(msg=str(err))
def test_resource_io_utils(app_resources): assert not resources.exists("fake_resource_name") for resource_name in app_resources: # existence assert resources.exists(resource_name) # context management ostream = None with resources.stream(resource_name) as ostream: assert isinstance(ostream, io.IOBase) assert ostream.read() assert ostream.closed
def _webserver_dev_config(webserver_environ: Dict, docker_stack: Dict) -> Dict: """ Swarm with integration stack already started Configuration for a webserver provided it runs in host NOTE: Prefer using 'app_config' below instead of this as a function-scoped fixture """ config_file_path = current_dir / "webserver_dev_config.yaml" # recreate config-file with app_resources.stream("config/server-docker-dev.yaml") as f: cfg = yaml.safe_load(f) # test webserver works in host cfg["main"]["host"] = "127.0.0.1" with config_file_path.open("wt") as f: yaml.dump(cfg, f, default_flow_style=False) # Emulates cli config_environ = {} config_environ.update(webserver_environ) config_environ.update( create_environ(skip_host_environ=True) ) # TODO: can be done monkeypathcing os.environ and calling create_environ as well # validates cfg_dict = trafaret_config.read_and_validate(config_file_path, app_schema, vars=config_environ) # WARNING: changes to this fixture during testing propagates to other tests. Use cfg = deepcopy(cfg_dict) # FIXME: freeze read/only json obj yield cfg_dict # clean up # to debug configuration uncomment next line config_file_path.unlink() return cfg_dict
def load_data(name): with resources.stream(name) as fp: return json.load(fp)