def test_export(session_with_pywr_network, root_user_id): pywr_network_id, pywr_json_filename = session_with_pywr_network # Fetch the network network = hydra_base.get_network(pywr_network_id, user_id=root_user_id, include_data='Y') # Fetch all the attributes attributes = hydra_base.get_attributes() # TODO not sure why this returns SQLAlchemy object? # TODO rename this to map/lookup attributes = {attr.id: JSONObject(attr) for attr in attributes} # We also need the template to get the node types template = JSONObject( hydra_base.get_template_by_name(pywr_template_name('Full'))) exporter = PywrHydraExporter(network, attributes, template) pywr_data_exported = exporter.get_pywr_data() # Check transformed data is about right with open(pywr_json_filename) as fh: pywr_data = json.load(fh) assert_identical_pywr_data(pywr_data, pywr_data_exported)
def session_with_pywr_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id): project = projectmaker.create() template = JSONObject( hydra_base.get_template_by_name(pywr_template_name('Full'))) importer = PywrHydraImporter(pywr_json_filename, template) # First the attributes must be added. attributes = [ JSONObject(a) for a in importer.add_attributes_request_data() ] # The response attributes have ids now. response_attributes = hydra_base.add_attributes(attributes) # Convert to a simple dict for local processing. attribute_ids = {a.name: a.id for a in response_attributes} # Now we try to create the network network = importer.add_network_request_data(attribute_ids, project.id) hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id) return hydra_network.id, pywr_json_filename
def test_add_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id): project = projectmaker.create() template = JSONObject( hydra_base.get_template_by_name(pywr_template_name('Full'))) importer = PywrHydraImporter(pywr_json_filename, template) # First the attributes must be added. attributes = [ JSONObject(a) for a in importer.add_attributes_request_data() ] # The response attributes have ids now. response_attributes = hydra_base.add_attributes(attributes) # Convert to a simple dict for local processing. # TODO change this variable name to map or lookup attribute_ids = {a.name: a.id for a in response_attributes} # Now we try to create the network network = importer.add_network_request_data(attribute_ids, project.id) # Check transformed data is about right with open(pywr_json_filename) as fh: pywr_data = json.load(fh) assert_hydra_pywr(network, pywr_data) hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id)
def test_add_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id): project = projectmaker.create() template = JSONObject(hydra_base.get_template_by_name(pywr_template_name('Full'))) importer = PywrHydraImporter(pywr_json_filename, template) # First the attributes must be added. attributes = [JSONObject(a) for a in importer.add_attributes_request_data()] # The response attributes have ids now. response_attributes = hydra_base.add_attributes(attributes) # Convert to a simple dict for local processing. # TODO change this variable name to map or lookup attribute_ids = {a.name: a.id for a in response_attributes} # Now we try to create the network network = importer.add_network_request_data(attribute_ids, project.id) # Check transformed data is about right with open(pywr_json_filename) as fh: pywr_data = json.load(fh) assert_hydra_pywr(network, pywr_data) hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id)
def session_with_pywr_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id): project = projectmaker.create() template = JSONObject(hydra_base.get_template_by_name(pywr_template_name('Full'))) importer = PywrHydraImporter(pywr_json_filename, template) # First the attributes must be added. attributes = [JSONObject(a) for a in importer.add_attributes_request_data()] # The response attributes have ids now. response_attributes = hydra_base.add_attributes(attributes) # Convert to a simple dict for local processing. attribute_ids = {a.name: a.id for a in response_attributes} # Now we try to create the network network = importer.add_network_request_data(attribute_ids, project.id) hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id) return hydra_network.id, pywr_json_filename