def validate_groundtruth_response(self, request_type, body): uri = "https://uri.com" manifest = {"groundtruth_uri": uri, "request_type": request_type} self.register_http_response(uri, manifest, body) basemodels.validate_manifest_uris(manifest)
def test_groundtruth_and_taskdata_valid(self): taskdata_uri = "https://td.com" groundtruth_uri = "https://gt.com" manifest = { "taskdata_uri": taskdata_uri, "groundtruth_uri": groundtruth_uri, "request_type": "image_label_binary" } taskdata = [{ "task_key": "407fdd93-687a-46bb-b578-89eb96b4109d", "datapoint_uri": "https://domain.com/file1.jpg", "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa" }, { "task_key": "20bd4f3e-4518-4602-b67a-1d8dfabcce0c", "datapoint_uri": "https://domain.com/file2.jpg", "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa" }] groundtruth = { "https://domain.com/123/file1.jpeg": ["false", "false", "false"], "https://domain.com/456/file2.jpeg": ["false", "true", "false"], } self.register_http_response(taskdata_uri, manifest, taskdata) self.register_http_response(groundtruth_uri, manifest, groundtruth) basemodels.validate_manifest_uris(manifest)
def test_taskdata_uri_invalid(self): uri = "https://uri.com" manifest = {"taskdata_uri": uri} body = [{"task_key": "not_uuid", "datapoint_uri": "not_uri"}] self.register_http_response(uri, manifest, body) with self.assertRaises(schematics.exceptions.BaseError): basemodels.validate_manifest_uris(manifest)
def test_taskdata_invalid_format(self): """ should raise if taskdata_uri contains object instead of array """ uri = "https://uri.com" manifest = {"taskdata_uri": uri} body = {"key": [1, 2, 3]} self.register_http_response(uri, manifest, body) with self.assertRaises(schematics.exceptions.BaseError): basemodels.validate_manifest_uris(manifest)
def test_taskdata_empty(self): """ should raise if taskdata_uri contains no entries """ uri = "https://uri.com" manifest = {"taskdata_uri": uri} body = [] self.register_http_response(uri, manifest, body) with self.assertRaises(schematics.exceptions.BaseError): basemodels.validate_manifest_uris(manifest)
def test_taskdata_uri_valid(self): uri = "https://uri.com" manifest = {"taskdata_uri": uri} body = [{ "task_key": "407fdd93-687a-46bb-b578-89eb96b4109d", "datapoint_uri": "https://domain.com/file1.jpg", "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa" }, { "task_key": "20bd4f3e-4518-4602-b67a-1d8dfabcce0c", "datapoint_uri": "https://domain.com/file2.jpg", "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa" }] self.register_http_response(uri, manifest, body) basemodels.validate_manifest_uris(manifest)
def test_no_uris(self): """ should not raise if there are no uris to validate """ manifest = {} basemodels.validate_manifest_uris(manifest)