def test_json_string_creation_nodes_and_links(self): property_tree = GenomePropertiesTree(*self.properties) test_json = property_tree.to_json(nodes_and_links=True) expected_json = '''{ "nodes": [{"id": "GenProp0002", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null}, {"id": "GenProp0003", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null}, {"id": "GenProp0066", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null}, {"id": "GenProp0089", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null}, {"id": "GenProp0092", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null}], "links": [{"parent": "GenProp0002", "child": "GenProp0066"}, {"parent": "GenProp0003", "child": "GenProp0066"}, {"parent": "GenProp0066", "child": "GenProp0089"}, {"parent": "GenProp0066", "child": "GenProp0092"}]}''' test_json_parsed = json.loads(test_json) expected_json_parsed = json.loads(expected_json) test_json_nodes = test_json_parsed['nodes'] expected_json_nodes = expected_json_parsed['nodes'] test_json_links = test_json_parsed['links'] expected_json_links = expected_json_parsed['links'] self.assertCountEqual(test_json_nodes, expected_json_nodes) self.assertCountEqual(test_json_links, expected_json_links)
def test_json_string_creation(self): property_tree = GenomePropertiesTree(*self.properties) test_json = property_tree.to_json() expected_json_one = '''{"id": "GenProp0002", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null, "children": [{"id": "GenProp0066", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null, "children": [ {"id": "GenProp0089", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null, "children": []}, {"id": "GenProp0092", "name": "Coenzyme F420 utilization", "type": "GUILD", "description": null, "notes": null, "children": []}]}]}''' test_json_parsed = json.loads(test_json) expected_json_parsed_one = json.loads(expected_json_one) """Root could be either GenProp0002 or GenProp0003. See Note 1 in test_find_root_node().""" expected_json_parsed_two = deepcopy(expected_json_parsed_one) expected_json_parsed_two['id'] = 'GenProp0003' self.assertIn(test_json_parsed, [expected_json_parsed_one, expected_json_parsed_two])