def test_query_single_node_success(self, client, node_name, result_file): """Query single node.""" train_id = gbl.get_train_ids()[0] params = dict(train_id=train_id, name=node_name) url = get_url(BASE_URL, params) response = client.get(url) assert response.status_code == 200 self.compare_result_with_file(response.get_json(), result_file)
def test_search_nodes_success(self, client, search_content, offset, limit, result_file): """Search node with parameters: offset is 0, limit is 1000.""" train_id = gbl.get_train_ids()[0] params = dict(train_id=train_id, search=search_content, offset=offset, limit=limit) url = get_url(BASE_URL, params) response = client.get(url) assert response.status_code == 200 self.compare_result_with_file(response.get_json(), result_file)
def test_metadata(self, client): """Test getting image metadata.""" plugin_name = PluginNameEnum.IMAGE.value train_id = gbl.get_train_ids()[0] tag_name = gbl.get_tags(train_id, plugin_name)[0] expected_metadata = gbl.get_metadata(train_id, tag_name) params = dict(train_id=train_id, tag=tag_name) url = get_url(BASE_URL, params) response = client.get(url) metadata = response.get_json().get("metadatas") assert metadata == expected_metadata
def test_plugins_with_special_manual_update(self, client, manual_update): """Test passing manual_update with special character, wrong value, and wrong type.""" train_id = gbl.get_train_ids()[0] params = dict(train_id=train_id, manual_update=manual_update) url = get_url(BASE_URL, params) response = client.get(url) assert response.status_code == 400 response = response.get_json() assert response['error_code'] == '50540002' assert response['error_msg'] == "Invalid parameter value. The value of " \ "manual_update must be 'false' or 'true'."
def test_single_image_with_invalid_step(self, client): """Test getting single image with invalid step.""" train_id = gbl.get_train_ids()[0] params = dict(train_id=train_id, tag="tag_name_0/image", step=1000) url = get_url(BASE_URL, params) response = client.get(url) assert response.status_code == 400 response = response.get_json() assert response['error_code'] == '50540002' assert response['error_msg'] == "Invalid parameter value. Can not find the step " \ "with given train job id and tag."
def test_single_image_with_special_tag(self, client, tag): """Test passing tag with special character, invalid value, and wrong type.""" train_id = gbl.get_train_ids()[0] params = dict(train_id=train_id, tag=tag, step=1) url = get_url(BASE_URL, params) response = client.get(url) assert response.status_code == 400 response = response.get_json() assert response['error_code'] == '50540002' assert response['error_msg'] == "Invalid parameter value. Can not find any data " \ "in this train job by given tag."
def test_single_image(self, client): """Test getting single image.""" step = 1 plugin_name = PluginNameEnum.IMAGE.value train_id = gbl.get_train_ids()[0] tag_name = gbl.get_tags(train_id, plugin_name)[0] expected_image_tensor = gbl.get_single_image(train_id, tag_name, step) params = dict(train_id=train_id, tag=tag_name, step=step) url = get_url(BASE_URL, params) response = client.get(url) recv_image_tensor = get_image_tensor_from_bytes(response.data) assert expected_image_tensor.any() == recv_image_tensor.any()
def test_metadata(self, client): """Test getting scalar metadata.""" plugin_name = PluginNameEnum.SCALAR.value train_id = gbl.get_train_ids()[0] tag_name = gbl.get_tags(train_id, plugin_name)[0] expected_metadata = gbl.get_metadata(train_id, tag_name) params = dict(train_id=train_id, tag=tag_name) url = get_url(BASE_URL, params) response = client.get(url) metadata = response.get_json().get("metadatas") for metadata, expected_metadata in zip(metadata, expected_metadata): assert metadata.get("wall_time") == expected_metadata.get("wall_time") assert metadata.get("step") == expected_metadata.get("step") assert metadata.get("value") - expected_metadata.get("value") < 1e-6
def test_plugins(self, client): """Test getting plugins.""" train_id = gbl.get_train_ids()[0] expected_plugins = gbl.summaries_metadata.get(train_id).get("plugins") params = dict(train_id=train_id) url = get_url(BASE_URL, params) response = client.get(url) plugins = response.get_json().get('plugins') for plugin_name in PluginNameEnum.list_members(): if plugin_name == PluginNameEnum.GRAPH.value: assert len(plugins.get(plugin_name)) == len( expected_plugins.get(plugin_name)) else: assert sorted(plugins.get(plugin_name)) == sorted( expected_plugins.get(plugin_name))