From 6e49c1bedad841adb41c81ac0fea69f60799c487 Mon Sep 17 00:00:00 2001 From: m55624 Date: Tue, 27 Jun 2017 14:39:35 +0100 Subject: [PATCH 1/2] gh-20 - added Gaffer shell tests --- python-shell/src/test/test_gaffer.py | 1553 +++++++++++++++++++++++++- 1 file changed, 1552 insertions(+), 1 deletion(-) diff --git a/python-shell/src/test/test_gaffer.py b/python-shell/src/test/test_gaffer.py index c624af9e2..c06f73cb9 100755 --- a/python-shell/src/test/test_gaffer.py +++ b/python-shell/src/test/test_gaffer.py @@ -20,7 +20,16 @@ class GafferTest(unittest.TestCase): - def test_create_edge_seed(self): + def test_entity_seed(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.data.EntitySeed', + 'vertex': 'vertex' + }, + g.EntitySeed("vertex").to_json() + ) + + def test_edge_seed(self): self.assertEqual( { 'class': 'uk.gov.gchq.gaffer.operation.data.EdgeSeed', @@ -71,6 +80,1548 @@ def test_create_edge_seed(self): g.EdgeSeed(1, 2, False).to_json() ) + def test_comparator(self): + self.assertEqual( + { + 'class': 'test_class_name' + }, + g.Comparator("test_class_name", {}).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'field1': 'field2', + 'field3': 'field4' + }, + g.Comparator("test_class_name", { + 'field1': 'field2', + 'field3': 'field4'}).to_json() + ) + + def test_element_property_comparator(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.comparison' + '.ElementPropertyComparator', + 'groups': 'groups', + 'property': 'property', + 'reversed': False + + }, + g.ElementPropertyComparator("groups", "property", False).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.comparison' + '.ElementPropertyComparator', + 'groups': 'groups', + 'property': 'property', + 'reversed': True + + }, + g.ElementPropertyComparator("groups", "property", True).to_json() + ) + + def test_seed_pair(self): + first_entity_seed = g.EntitySeed("vertex") + second_entity_seed = g.EntitySeed("vertex1") + first_edge_seed = g.EdgeSeed("src", "dest", g.DirectedType.DIRECTED) + second_edge_seed = g.EdgeSeed("src1", "dest1", g.DirectedType.DIRECTED) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.commonutil.pair.Pair', + 'first': first_entity_seed.to_json_wrapped(), + 'second': second_entity_seed.to_json_wrapped() + }, + g.SeedPair(first_entity_seed, second_entity_seed).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.commonutil.pair.Pair', + 'first': first_edge_seed.to_json_wrapped(), + 'second': second_edge_seed.to_json_wrapped() + }, + g.SeedPair(first_edge_seed, second_edge_seed).to_json() + ) + + def test_element(self): + self.assertEqual( + { + 'class': 'test_class', + 'group': 'group' + }, + g.Element("test_class", "group").to_json() + ) + + self.assertEqual( + { + 'class': 'test_class', + 'group': 'group', + 'properties': {"prop1": 1} + }, + g.Element("test_class", "group", {"prop1": 1}).to_json() + ) + + def test_entity(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'group', + 'vertex': 'vertex', + }, + g.Entity("group", "vertex").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'group', + 'vertex': 'vertex', + 'properties': {"prop1": 1} + }, + g.Entity("group", "vertex", {"prop1": 1}).to_json() + ) + + def test_edge(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.Edge', + 'group': 'group', + 'source': 'source', + 'destination': 'destination', + 'directed': True + + }, + g.Edge("group", "source", "destination", True).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.Edge', + 'group': 'group', + 'source': 'source', + 'destination': 'destination', + 'directed': False + + }, + g.Edge("group", "source", "destination", False).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.data.element.Edge', + 'group': 'group', + 'source': 'source', + 'destination': 'destination', + 'directed': False, + 'properties': {"prop1": 1} + + }, + g.Edge("group", "source", "destination", False, + {"prop1": 1}).to_json() + ) + + def test_view(self): + self.assertEqual( + {}, + g.View().to_json() + ) + + self.assertEqual( + { + 'entities': { + 'test': {'class': 'uk.gov.gchq.gaffer.data.element.Edge', + 'group': 'test', + 'source': 'source', + 'destination': 'destination', + 'directed': False}} + }, + g.View( + [ + g.ElementDefinition( + group='test' + ), + g.Edge("test", "source", "destination", False) + ]).to_json() + ) + + self.assertEqual( + { + 'edges': { + 'test': {'class': 'uk.gov.gchq.gaffer.data.element.Edge', + 'group': 'test', + 'source': 'source', + 'destination': 'destination', + 'directed': False}} + }, + g.View( + edges=[ + g.ElementDefinition( + group='test' + ), + g.Edge("test", "source", "destination", False) + ]).to_json() + ) + + def test_element_definition(self): + self.maxDiff = None + self.assertEqual( + { + 'groupBy': [], + }, + g.ElementDefinition('testGroup').to_json() + ) + + self.assertEqual( + { + 'groupBy': [], + 'transientProperties': {'description': 'java.lang.String'} + }, + g.ElementDefinition('test_group', + [g.Property('description', + 'java.lang.String')]).to_json() + ) + + self.assertEqual( + { + 'groupBy': ["test_group"], + 'transientProperties': {'description': 'java.lang.String'} + }, + g.ElementDefinition('test_group', + [g.Property('description', 'java.lang.String')], + ["test_group"]).to_json() + ) + + self.assertEqual( + { + 'groupBy': ["test_group"], + 'transientProperties': {'description': 'java.lang.String'}, + 'preAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}] + }, + g.ElementDefinition('test_group', + [g.Property('description', 'java.lang.String')], + ["test_group"], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )]).to_json() + ) + + self.assertEqual( + { + 'groupBy': ["test_group"], + 'transientProperties': {'description': 'java.lang.String'}, + 'preAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}], + 'postAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}] + }, + g.ElementDefinition('test_group', + [g.Property('description', 'java.lang.String')], + ["test_group"], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )]).to_json() + ) + + self.assertEqual( + { + 'groupBy': ["test_group"], + 'transientProperties': {'description': 'java.lang.String'}, + 'preAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}], + 'postAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}], + 'transformFunctions': [{'function': {'class': 'test_class'}, + 'projection': + ['description'], + 'selection': + ['SOURCE', 'DESTINATION', 'count']}] + }, + g.ElementDefinition('test_group', + [g.Property('description', 'java.lang.String')], + ["test_group"], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )], + [ + g.TransformFunction( + 'test_class', + ['SOURCE', 'DESTINATION', 'count'], + ['description'] + ) + ]).to_json() + ) + + self.assertEqual( + { + 'groupBy': ["test_group"], + 'transientProperties': {'description': 'java.lang.String'}, + 'preAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}], + 'postAggregationFilterFunctions': + [{'predicate': {'class': + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + 'value': { + 'java.lang.Long': 1}}, + 'selection': ['count']}], + 'transformFunctions': [{'function': {'class': 'test_class'}, + 'projection': + ['description'], + 'selection': + ['SOURCE', 'DESTINATION', + 'count']}], + 'postTransformFilterFunctions': [{'function': {'class': 'test_class'}, + 'projection': + ['description'], + 'selection': + ['SOURCE', 'DESTINATION', + 'count']} + + ] + }, + g.ElementDefinition('test_group', + [g.Property('description', 'java.lang.String')], + ["test_group"], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsMoreThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )], + [g.FilterFunction( + 'uk.gov.gchq.koryphe' + '.impl.predicate.IsLessThan', + ['count'], + {'value': {'java.lang.Long': 1}} + )], + [ + g.TransformFunction( + 'test_class', + ['SOURCE', 'DESTINATION', 'count'], + ['description'] + ) + ], + [ + g.TransformFunction( + 'test_class', + ['SOURCE', 'DESTINATION', 'count'], + ['description'] + ) + ]).to_json() + ) + + def test_property(self): + self.assertEqual( + { + "test_name": "test_class_name" + }, + g.Property("test_name", "test_class_name").to_json() + ) + + def test_gaffer_function(self): + self.assertEqual( + { + 'test_classType': {'class': 'test_class'} + }, + g.GafferFunction("test_class", "test_classType").to_json() + ) + + self.assertEqual( + { + 'test_classType': {'class': 'test_class', + "function_field1": "test_field1"} + }, + g.GafferFunction("test_class", "test_classType", + {"function_field1": "test_field1"}).to_json() + ) + + def test_filter_function(self): + self.assertEqual( + { + 'predicate': {'class': 'test_class'}, + 'selection': 'selection' + }, + g.FilterFunction("test_class", "selection").to_json() + ) + + self.assertEqual( + { + 'predicate': {'class': 'test_class', + 'function_field1': 'test_field1'}, + 'selection': 'selection' + }, + g.FilterFunction("test_class", "selection", + {"function_field1": "test_field1"}).to_json() + ) + + def test_transform_function(self): + self.assertEqual( + { + 'function': {'class': 'test_class'}, + 'selection': 'selection', + 'projection': 'projection' + }, + g.TransformFunction("test_class", "selection", "projection") + .to_json() + ) + + self.assertEqual( + { + 'function': {'class': 'test_class'}, + 'selection': 'selection', + 'projection': {'function_field1': 'test_field1'} + }, + g.TransformFunction("test_class", "selection", + {"function_field1": "test_field1"}).to_json() + ) + + def test_operation_chain(self): + test_op_chain1 = g.Operation("test_class") + operations = [test_op_chain1] + self.assertEqual( + { + 'operations': [{'class': 'test_class'}] + }, + g.OperationChain(operations).to_json() + ) + + test_op_chain2 = g.Operation("test_class", g.View()) + operations.append(test_op_chain2) + self.assertEqual( + { + 'operations': [{'class': 'test_class'}, + {'class': 'test_class', 'view': {}}] + }, + g.OperationChain(operations).to_json() + ) + + test_op_chain3 = g.Operation("test_class", g.View(), + {'option1': 'option'}) + operations.append(test_op_chain3) + self.assertEqual( + { + 'operations': [{'class': 'test_class'}, + {'class': 'test_class', 'view': {}}, + {'class': 'test_class', 'view': {}, + 'options': {'option1': 'option'}}] + }, + g.OperationChain(operations).to_json() + ) + + def test_operation(self): + self.assertEqual( + { + 'class': 'test_class' + }, + g.Operation("test_class").to_json() + ) + + self.assertEqual( + { + 'class': 'test_class', + 'view': {} + }, + g.Operation("test_class", g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class', + 'view': {}, + 'options': {'option1': 'option'} + + }, + g.Operation("test_class", g.View(), {"option1": "option"}).to_json() + ) + + def test_add_elements(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.add.AddElements', + 'skipInvalidElements': False, + 'validate': True + }, + g.AddElements().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.add.AddElements', + 'skipInvalidElements': True, + 'validate': False + }, + g.AddElements(skip_invalid_elements=True, validate=False).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.add.AddElements', + 'skipInvalidElements': False, + 'validate': True, + 'view': {} + }, + g.AddElements(view=g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.add.AddElements', + 'skipInvalidElements': False, + 'validate': True, + 'view': {}, + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'group', + 'vertex': 'vertex'}] + }, + g.AddElements(view=g.View(), + elements=[g.Entity("group", "vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.add.AddElements', + 'skipInvalidElements': False, + 'validate': True, + 'view': {}, + 'options': {'options1': 'option'}, + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'group', + 'vertex': 'vertex'}] + }, + g.AddElements(view=g.View(), + elements=[g.Entity("group", "vertex")], + options={'options1': 'option'}).to_json() + ) + + def test_generate_elements(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'} + }, + g.GenerateElements("generate_class_elements").to_json() + ) + + # Needs writing to include element_generator_fields + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'} + }, + g.GenerateElements("generate_class_elements").to_json() + ) + + # Needs writing to include objects + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'} + }, + g.GenerateElements("generate_class_elements").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'}, + 'view': {} + }, + g.GenerateElements("generate_class_elements", + view=g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'}, + 'view': {}, + 'options': {'option1': 'option'} + }, + g.GenerateElements("generate_class_elements", + view=g.View(), options={'option1': 'option'}) + .to_json() + ) + + def test_generate_objects(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'} + }, + g.GenerateObjects("test_class_name").to_json() + ) + + # Needs writing to test element_generator_fields + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'} + }, + g.GenerateObjects("test_class_name").to_json() + ) + + # Needs writing to test elements + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'} + }, + g.GenerateObjects("test_class_name").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'}, + 'view': {} + }, + g.GenerateObjects("test_class_name", view=g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'}, + 'view': {}, + 'options': {'option1': 'option'} + }, + g.GenerateObjects("test_class_name", view=g.View(), options={"option1": "option"}).to_json() + ) + + def test_export_to_gaffer_result_cache(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.ExportToGafferResultCache' + }, + g.ExportToGafferResultCache().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.ExportToGafferResultCache', + 'key': 'test_key' + }, + g.ExportToGafferResultCache("test_key").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.ExportToGafferResultCache', + 'key': 'test_key', + 'opAuths': 'test_op_auths' + }, + g.ExportToGafferResultCache("test_key", "test_op_auths").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.ExportToGafferResultCache', + 'key': 'test_key', + 'opAuths': 'test_op_auths', + 'options': {'option1': 'option'} + }, + g.ExportToGafferResultCache("test_key", "test_op_auths", + {'option1': 'option'}).to_json() + ) + + def test_get_gaffer_result_cache_export(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.GetGafferResultCacheExport' + }, + g.GetGafferResultCacheExport().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.GetGafferResultCacheExport', + 'jobId': 'test_job_id' + }, + g.GetGafferResultCacheExport("test_job_id").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.GetGafferResultCacheExport', + 'jobId': 'test_job_id', + 'key': 'test_key' + }, + g.GetGafferResultCacheExport("test_job_id", "test_key").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.resultcache.GetGafferResultCacheExport', + 'jobId': 'test_job_id', + 'key': 'test_key', + 'options': {"option1": "option"} + }, + g.GetGafferResultCacheExport("test_job_id", "test_key", + {"option1": "option"}).to_json() + ) + + def test_export_to_set(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.ExportToSet' + }, + g.ExportToSet().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.ExportToSet', + 'key': 'test_key' + }, + g.ExportToSet("test_key").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.ExportToSet', + 'key': 'test_key', + 'options': {"option1": "option"} + }, + g.ExportToSet("test_key", {"option1": "option"}).to_json() + ) + + def test_get_set_export(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.GetSetExport' + }, + g.GetSetExport().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.GetSetExport', + 'jobId': 'test_job_id' + }, + g.GetSetExport("test_job_id").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.GetSetExport', + 'jobId': 'test_job_id', + 'key': 'test_key' + }, + g.GetSetExport("test_job_id", "test_key").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.export.set.GetSetExport', + 'jobId': 'test_job_id', + 'key': 'test_key', + 'options': {'option1': 'option'} + }, + g.GetSetExport("test_job_id", "test_key", + {'option1': 'option'}).to_json() + ) + + def test_get_job_details(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails' + }, + g.GetJobDetails().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails', + 'jobId': 'test_job_id' + }, + g.GetJobDetails("test_job_id").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails', + 'jobId': 'test_job_id', + 'options': {'option1': 'option'} + }, + g.GetJobDetails("test_job_id", {"option1": "option"}).to_json() + ) + + def test_get_all_job_details(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.job.GetAllJobDetails' + }, + g.GetAllJobDetails().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl' + '.job.GetAllJobDetails', + 'options': {'option1': 'option'} + }, + g.GetAllJobDetails({"option1": "option"}).to_json() + ) + + def test_get_operation(self): + self.assertEqual( + { + 'class': 'test_class_name' + }, + g.GetOperation("test_class_name").to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}] + }, + g.GetOperation("test_class_name", + [g.EntitySeed("test_vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetOperation("test_class_name", + [g.EntitySeed("test_vertex")], + g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'directedType': 'DIRECTED', + 'includeIncomingOutGoing': 'DIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetOperation("test_class_name", + [g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.DIRECTED, + g.DirectedType.DIRECTED, + g.SeedMatchingType.EQUAL).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'directedType': 'UNDIRECTED', + 'includeIncomingOutGoing': 'UNDIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetOperation("test_class_name", + [g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.UNDIRECTED, + g.DirectedType.UNDIRECTED, + g.SeedMatchingType.EQUAL).to_json() + ) + + self.assertEqual( + { + 'class': 'test_class_name', + 'directedType': 'DIRECTED', + 'includeIncomingOutGoing': 'DIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'options': {'option1': 'option'} + }, + g.GetOperation("test_class_name", + [g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.DIRECTED, + g.DirectedType.DIRECTED, + g.SeedMatchingType.EQUAL, + {"option1": "option"}).to_json() + ) + + def test_get_elements(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements' + }, + g.GetElements().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}] + }, + g.GetElements([g.EntitySeed("test_vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetElements([g.EntitySeed("test_vertex")], + g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements', + 'directedType': 'DIRECTED', + 'includeIncomingOutGoing': 'DIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetElements([g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.DIRECTED, + g.DirectedType.DIRECTED, + g.SeedMatchingType.EQUAL).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements', + 'directedType': 'UNDIRECTED', + 'includeIncomingOutGoing': 'UNDIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetElements([g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.UNDIRECTED, + g.DirectedType.UNDIRECTED, + g.SeedMatchingType.EQUAL).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetElements', + 'directedType': 'DIRECTED', + 'includeIncomingOutGoing': 'DIRECTED', + 'seedMatching': 'EQUAL', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'options': {'option1': 'option'} + }, + g.GetElements([g.EntitySeed("test_vertex")], + g.View(), + g.DirectedType.DIRECTED, + g.DirectedType.DIRECTED, + g.SeedMatchingType.EQUAL, + {"option1": "option"}).to_json() + ) + + def test_get_adjacent_ids(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds' + }, + g.GetAdjacentIds().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}] + }, + g.GetAdjacentIds([g.EntitySeed("test_vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.GetAdjacentIds([g.EntitySeed("test_vertex")], g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'includeIncomingOutGoing': 'INCOMING' + }, + g.GetAdjacentIds([g.EntitySeed("test_vertex")], g.View(), + g.InOutType.IN).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'includeIncomingOutGoing': 'OUTGOING' + }, + g.GetAdjacentIds([g.EntitySeed("test_vertex")], g.View(), + g.InOutType.OUT).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'options': {'option1': 'option'} + }, + g.GetAdjacentIds([g.EntitySeed("test_vertex")], g.View(), + options={"option1": "option"}).to_json() + ) + + def test_get_all_elements(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAllElements' + }, + g.GetAllElements().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAllElements', + 'view': {} + }, + g.GetAllElements(g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAllElements', + 'view': {}, + 'directedType': 'DIRECTED' + }, + g.GetAllElements(g.View(), g.DirectedType.DIRECTED).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAllElements', + 'view': {}, + 'directedType': 'UNDIRECTED' + }, + g.GetAllElements(g.View(), g.DirectedType.UNDIRECTED).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.get.GetAllElements', + 'view': {}, + 'directedType': 'UNDIRECTED', + 'options': {'option1': 'option'} + }, + g.GetAllElements(g.View(), g.DirectedType.UNDIRECTED, + {"option1": "option"}).to_json() + ) + + def test_named_operation(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.NamedOperation', + 'operationName': 'test_op_name' + }, + g.NamedOperation("test_op_name").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.NamedOperation', + 'operationName': 'test_op_name', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}] + }, + g.NamedOperation("test_op_name", + [g.EntitySeed("test_vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.NamedOperation', + 'operationName': 'test_op_name', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {} + }, + g.NamedOperation("test_op_name", [g.EntitySeed("test_vertex")], + g.View()).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.NamedOperation', + 'operationName': 'test_op_name', + 'input': [{'class': 'uk.gov.gchq.gaffer' + '.operation.data.EntitySeed', + 'vertex': 'test_vertex'}], + 'view': {}, + 'options': {'option1': 'option'} + }, + g.NamedOperation("test_op_name", [g.EntitySeed("test_vertex")], + g.View(), {"option1": "option"}).to_json() + ) + + def test_add_named_operation(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': False + }, + g.AddNamedOperation("test_operation_chain", "test_name").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': False, + 'description': 'test_description' + }, + g.AddNamedOperation("test_operation_chain", "test_name", "test_description").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': False, + 'description': 'test_description', + 'readAccessRoles': 'test_read_access_roles' + }, + g.AddNamedOperation("test_operation_chain", "test_name", + "test_description", 'test_read_access_roles').to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': False, + 'description': 'test_description', + 'readAccessRoles': 'test_read_access_roles', + 'writeAccessRoles': 'test_write_access_roles' + }, + g.AddNamedOperation("test_operation_chain", "test_name", + "test_description", 'test_read_access_roles', + 'test_write_access_roles').to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': True, + 'description': 'test_description', + 'readAccessRoles': 'test_read_access_roles', + 'writeAccessRoles': 'test_write_access_roles' + }, + g.AddNamedOperation("test_operation_chain", "test_name", + "test_description", 'test_read_access_roles', + 'test_write_access_roles', True).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named.operation.AddNamedOperation', + 'operationChain': 'test_operation_chain', + 'operationName': 'test_name', + 'overwriteFlag': False, + 'description': 'test_description', + 'readAccessRoles': 'test_read_access_roles', + 'writeAccessRoles': 'test_write_access_roles', + 'options': {'option1': 'option'} + }, + g.AddNamedOperation("test_operation_chain", "test_name", + "test_description", 'test_read_access_roles', + 'test_write_access_roles', False, + {"option1": "option"}).to_json() + ) + + def test_delete_named_operation(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named' + '.operation.DeleteNamedOperation', + 'operationName': 'test_name' + }, + g.DeleteNamedOperation("test_name").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named' + '.operation.DeleteNamedOperation', + 'operationName': 'test_name', + 'options': {'option1': 'option'} + }, + g.DeleteNamedOperation("test_name", {"option1": "option"}).to_json() + ) + + def test_get_all_named_operations(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named' + '.operation.GetAllNamedOperations' + }, + g.GetAllNamedOperations().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.named' + '.operation.GetAllNamedOperations', + 'options': {'options1': 'option'} + }, + g.GetAllNamedOperations({'options1': 'option'}).to_json() + ) + + def test_discard_output(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.DiscardOutput' + }, + g.DiscardOutput().to_json() + ) + + def test_count_groups(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.CountGroups' + }, + g.CountGroups().to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.CountGroups', + 'limit': 10 + }, + g.CountGroups(10).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.CountGroups', + 'limit': 10, + 'options': {"option1": "option"} + }, + g.CountGroups(10, {"option1": "option"}).to_json() + ) + + def test_limit(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.Limit', + 'resultLimit': 10 + }, + g.Limit(10).to_json() + ) + + def test_to_set(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToSet' + }, + g.ToSet().to_json() + ) + + def test_to_array(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToArray' + }, + g.ToArray().to_json() + ) + + def test_to_entity_seeds(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.output.ToEntitySeeds' + }, + g.ToEntitySeeds().to_json() + ) + + def test_to_vertices(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToVertices', + 'edgeVertices': 'test_edge_vertices' + }, + g.ToVertices("test_edge_vertices").to_json() + ) + + def test_to_csv(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToCsv', + 'elementGenerator': 'test_element_generator', + 'includeHeader': True + }, + g.ToCsv("test_element_generator").to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToCsv', + 'elementGenerator': 'test_element_generator', + 'includeHeader': False + }, + g.ToCsv("test_element_generator", False).to_json() + ) + + def test_to_map_csv(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.output.ToMap', + 'elementGenerator': 'test_element_generator' + }, + g.ToMapCsv("test_element_generator").to_json() + ) + + def test_sort(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Sort', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}] + }, + g.Sort([g.ElementPropertyComparator("test_groups", + "test_property")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Sort', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}], + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'test_group', + 'vertex': 'test_vertex'}] + }, + g.Sort([g.ElementPropertyComparator("test_groups", + "test_property")], + [g.Entity("test_group", "test_vertex")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Sort', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}], + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'test_group', + 'vertex': 'test_vertex'}], + 'resultLimit': 10 + }, + g.Sort([g.ElementPropertyComparator("test_groups", + "test_property")], + [g.Entity("test_group", "test_vertex")], 10).to_json() + ) + + def test_max(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Max', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}] + }, + g.Max([g.ElementPropertyComparator("test_groups", + "test_property")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Max', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}], + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'test_group', + 'vertex': 'test_vertex'}] + }, + g.Max([g.ElementPropertyComparator("test_groups", + "test_property")], + [g.Entity("test_group", "test_vertex")]).to_json() + ) + + def test_min(self): + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Min', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}] + + }, + g.Min([g.ElementPropertyComparator("test_groups", + "test_property")]).to_json() + ) + + self.assertEqual( + { + 'class': 'uk.gov.gchq.gaffer.operation.impl.compare.Min', + 'comparators': [{'class': 'uk.gov.gchq.gaffer.data.' + 'element.comparison' + '.ElementPropertyComparator', + 'groups': 'test_groups', + 'property': 'test_property', + 'reversed': False}], + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'test_group', + 'vertex': 'test_vertex'}] + }, + g.Min([g.ElementPropertyComparator("test_groups", + "test_property")], + [g.Entity("test_group", "test_vertex")]).to_json() + ) + if __name__ == "__main__": unittest.main() From cdf1714bb296f759cab13786f25bdbbd10fd2241 Mon Sep 17 00:00:00 2001 From: m55624 Date: Wed, 28 Jun 2017 09:09:33 +0100 Subject: [PATCH 2/2] gh-20 - finished tests and fixed issues in gaffer.py --- python-shell/src/gafferpy/gaffer.py | 8 +- python-shell/src/test/test_gaffer.py | 305 +++++++++++++-------------- 2 files changed, 156 insertions(+), 157 deletions(-) diff --git a/python-shell/src/gafferpy/gaffer.py b/python-shell/src/gafferpy/gaffer.py index 17ee61dbc..6841d6a5d 100755 --- a/python-shell/src/gafferpy/gaffer.py +++ b/python-shell/src/gafferpy/gaffer.py @@ -486,8 +486,8 @@ def to_json(self): element_generator = {'class': self.generator_class_name} if self.element_generator_fields is not None: - for field in self.element_generator_fields: - element_generator[field.key] = field.value + for key, value in self.element_generator_fields.items(): + element_generator[key] = value operation['elementGenerator'] = element_generator return operation @@ -518,8 +518,8 @@ def to_json(self): element_generator = {'class': self.generator_class_name} if self.element_generator_fields is not None: - for field in self.element_generator_fields: - element_generator[field.key] = field.value + for key, value in self.element_generator_fields.items(): + element_generator[key] = value operation['elementGenerator'] = element_generator return operation diff --git a/python-shell/src/test/test_gaffer.py b/python-shell/src/test/test_gaffer.py index c06f73cb9..f3a6aa4f6 100755 --- a/python-shell/src/test/test_gaffer.py +++ b/python-shell/src/test/test_gaffer.py @@ -63,21 +63,21 @@ def test_edge_seed(self): self.assertEqual( { 'class': 'uk.gov.gchq.gaffer.operation.data.EdgeSeed', - 'source': 1, - 'destination': 2, + 'source': 'src', + 'destination': 'dest', 'directed': 'DIRECTED' }, - g.EdgeSeed(1, 2, True).to_json() + g.EdgeSeed("src", "dest", True).to_json() ) self.assertEqual( { 'class': 'uk.gov.gchq.gaffer.operation.data.EdgeSeed', - 'source': 1, - 'destination': 2, + 'source': 'src', + 'destination': 'dest', 'directed': 'UNDIRECTED' }, - g.EdgeSeed(1, 2, False).to_json() + g.EdgeSeed("src", "dest", False).to_json() ) def test_comparator(self): @@ -95,8 +95,8 @@ def test_comparator(self): 'field3': 'field4' }, g.Comparator("test_class_name", { - 'field1': 'field2', - 'field3': 'field4'}).to_json() + "field1": "field2", + "field3": "field4"}).to_json() ) def test_element_property_comparator(self): @@ -161,9 +161,9 @@ def test_element(self): { 'class': 'test_class', 'group': 'group', - 'properties': {"prop1": 1} + 'properties': {'prop': 'prop1'} }, - g.Element("test_class", "group", {"prop1": 1}).to_json() + g.Element("test_class", "group", {"prop": "prop1"}).to_json() ) def test_entity(self): @@ -181,9 +181,9 @@ def test_entity(self): 'class': 'uk.gov.gchq.gaffer.data.element.Entity', 'group': 'group', 'vertex': 'vertex', - 'properties': {"prop1": 1} + 'properties': {'prop': 'prop1'} }, - g.Entity("group", "vertex", {"prop1": 1}).to_json() + g.Entity("group", "vertex", {"prop": "prop1"}).to_json() ) def test_edge(self): @@ -218,11 +218,11 @@ def test_edge(self): 'source': 'source', 'destination': 'destination', 'directed': False, - 'properties': {"prop1": 1} + 'properties': {'prop': 'prop1'} }, g.Edge("group", "source", "destination", False, - {"prop1": 1}).to_json() + {"prop": "prop1"}).to_json() ) def test_view(self): @@ -243,7 +243,7 @@ def test_view(self): g.View( [ g.ElementDefinition( - group='test' + group="test" ), g.Edge("test", "source", "destination", False) ]).to_json() @@ -261,7 +261,7 @@ def test_view(self): g.View( edges=[ g.ElementDefinition( - group='test' + group="test" ), g.Edge("test", "source", "destination", False) ]).to_json() @@ -273,196 +273,183 @@ def test_element_definition(self): { 'groupBy': [], }, - g.ElementDefinition('testGroup').to_json() + g.ElementDefinition("testGroup").to_json() ) self.assertEqual( { 'groupBy': [], - 'transientProperties': {'description': 'java.lang.String'} + 'transientProperties': {'test_prop': 'test_prop_class'} }, - g.ElementDefinition('test_group', - [g.Property('description', - 'java.lang.String')]).to_json() + g.ElementDefinition("test_group", + [g.Property("test_prop", + "test_prop_class")]).to_json() ) self.assertEqual( { - 'groupBy': ["test_group"], - 'transientProperties': {'description': 'java.lang.String'} + 'groupBy': ['test_group'], + 'transientProperties': {'test_prop': 'test_prop_class'} }, - g.ElementDefinition('test_group', - [g.Property('description', 'java.lang.String')], + g.ElementDefinition("test_group", + [g.Property("test_prop", "test_prop_class")], ["test_group"]).to_json() ) self.assertEqual( { - 'groupBy': ["test_group"], - 'transientProperties': {'description': 'java.lang.String'}, + 'groupBy': ['test_group'], + 'transientProperties': {'test_prop': 'test_prop_class'}, 'preAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', + 'test_filter_class', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}] + 'test_value_class': 1}}, + 'selection': ['test_selection']}] }, - g.ElementDefinition('test_group', - [g.Property('description', 'java.lang.String')], + g.ElementDefinition("test_group", + [g.Property("test_prop", "test_prop_class")], ["test_group"], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class", + ["test_selection"], + {"value": {"test_value_class": 1}} )]).to_json() ) self.assertEqual( { - 'groupBy': ["test_group"], - 'transientProperties': {'description': 'java.lang.String'}, + 'groupBy': ['test_group'], + 'transientProperties': {'test_prop': 'test_prop_class'}, 'preAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', + 'test_filter_class', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}], + 'test_value_class': 1}}, + 'selection': ['test_selection']}], 'postAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', + 'test_filter_class_1', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}] + 'test_value_class_1': 1}}, + 'selection': ['test_selection_1']}] }, - g.ElementDefinition('test_group', - [g.Property('description', 'java.lang.String')], + g.ElementDefinition("test_group", + [g.Property("test_prop", "test_prop_class")], ["test_group"], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class", + ["test_selection"], + {"value": {"test_value_class": 1}} )], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class_1", + ["test_selection_1"], + {"value": {"test_value_class_1": 1}} )]).to_json() ) self.assertEqual( { - 'groupBy': ["test_group"], - 'transientProperties': {'description': 'java.lang.String'}, + 'groupBy': ['test_group'], + 'transientProperties': {'test_prop': 'test_prop_class'}, 'preAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', + 'test_filter_class', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}], + 'test_value_class': 1}}, + 'selection': ['test_selection']}], 'postAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', + 'test_filter_class_1', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}], + 'test_value_class_1': 1}}, + 'selection': ['test_selection_1']}], 'transformFunctions': [{'function': {'class': 'test_class'}, 'projection': ['description'], 'selection': - ['SOURCE', 'DESTINATION', 'count']}] + ['src', 'dest', 'count']}] }, - g.ElementDefinition('test_group', - [g.Property('description', 'java.lang.String')], + g.ElementDefinition("test_group", + [g.Property("test_prop", "test_prop_class")], ["test_group"], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class", + ["test_selection"], + {"value": {"test_value_class": 1}} )], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class_1", + ["test_selection_1"], + {"value": {"test_value_class_1": 1}} )], [ g.TransformFunction( - 'test_class', - ['SOURCE', 'DESTINATION', 'count'], - ['description'] + "test_class", + ["src", "dest", "count"], + ["description"] ) ]).to_json() ) self.assertEqual( { - 'groupBy': ["test_group"], - 'transientProperties': {'description': 'java.lang.String'}, + 'groupBy': ['test_group'], + 'transientProperties': {'test_prop': 'test_prop_class'}, 'preAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', + 'test_filter_class', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}], + 'test_value_class': 1}}, + 'selection': ['test_selection']}], 'postAggregationFilterFunctions': [{'predicate': {'class': - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', + 'test_filter_class_1', 'value': { - 'java.lang.Long': 1}}, - 'selection': ['count']}], + 'test_value_class_1': 1}}, + 'selection': ['test_selection_1']}], 'transformFunctions': [{'function': {'class': 'test_class'}, 'projection': ['description'], 'selection': - ['SOURCE', 'DESTINATION', + ['src', 'dest', 'count']}], - 'postTransformFilterFunctions': [{'function': {'class': 'test_class'}, + 'postTransformFilterFunctions': [{'function': {'class': + 'test_class_1'}, 'projection': ['description'], 'selection': - ['SOURCE', 'DESTINATION', + ['src', 'dest', 'count']} ] }, - g.ElementDefinition('test_group', - [g.Property('description', 'java.lang.String')], + g.ElementDefinition("test_group", + [g.Property("test_prop", "test_prop_class")], ["test_group"], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsMoreThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class", + ["test_selection"], + {"value": {"test_value_class": 1}} )], [g.FilterFunction( - 'uk.gov.gchq.koryphe' - '.impl.predicate.IsLessThan', - ['count'], - {'value': {'java.lang.Long': 1}} + "test_filter_class_1", + ["test_selection_1"], + {"value": {"test_value_class_1": 1}} )], [ g.TransformFunction( - 'test_class', - ['SOURCE', 'DESTINATION', 'count'], - ['description'] + "test_class", + ["src", "dest", "count"], + ["description"] ) ], [ g.TransformFunction( - 'test_class', - ['SOURCE', 'DESTINATION', 'count'], - ['description'] + "test_class_1", + ["src", "dest", "count"], + ["description"] ) ]).to_json() ) @@ -470,7 +457,7 @@ def test_element_definition(self): def test_property(self): self.assertEqual( { - "test_name": "test_class_name" + 'test_name': 'test_class_name' }, g.Property("test_name", "test_class_name").to_json() ) @@ -486,7 +473,7 @@ def test_gaffer_function(self): self.assertEqual( { 'test_classType': {'class': 'test_class', - "function_field1": "test_field1"} + 'function_field1': 'test_field1'} }, g.GafferFunction("test_class", "test_classType", {"function_field1": "test_field1"}).to_json() @@ -542,24 +529,24 @@ def test_operation_chain(self): g.OperationChain(operations).to_json() ) - test_op_chain2 = g.Operation("test_class", g.View()) + test_op_chain2 = g.Operation("test_class_1", g.View()) operations.append(test_op_chain2) self.assertEqual( { 'operations': [{'class': 'test_class'}, - {'class': 'test_class', 'view': {}}] + {'class': 'test_class_1', 'view': {}}] }, g.OperationChain(operations).to_json() ) - test_op_chain3 = g.Operation("test_class", g.View(), - {'option1': 'option'}) + test_op_chain3 = g.Operation("test_class_2", g.View(), + {"option1": "option"}) operations.append(test_op_chain3) self.assertEqual( { 'operations': [{'class': 'test_class'}, - {'class': 'test_class', 'view': {}}, - {'class': 'test_class', 'view': {}, + {'class': 'test_class_1', 'view': {}}, + {'class': 'test_class_2', 'view': {}, 'options': {'option1': 'option'}}] }, g.OperationChain(operations).to_json() @@ -647,7 +634,7 @@ def test_add_elements(self): }, g.AddElements(view=g.View(), elements=[g.Entity("group", "vertex")], - options={'options1': 'option'}).to_json() + options={"options1": "option"}).to_json() ) def test_generate_elements(self): @@ -660,24 +647,26 @@ def test_generate_elements(self): g.GenerateElements("generate_class_elements").to_json() ) - # Needs writing to include element_generator_fields self.assertEqual( { 'class': 'uk.gov.gchq.gaffer.operation.impl' '.generate.GenerateElements', - 'elementGenerator': {'class': 'generate_class_elements'} + 'elementGenerator': {'class': 'generate_class_elements', + 'field1': 'value1'} }, - g.GenerateElements("generate_class_elements").to_json() + g.GenerateElements("generate_class_elements", + {"field1": "value1"}).to_json() ) - # Needs writing to include objects self.assertEqual( { 'class': 'uk.gov.gchq.gaffer.operation.impl' - '.generate.GenerateElements', - 'elementGenerator': {'class': 'generate_class_elements'} + '.generate.GenerateElements', + 'elementGenerator': {'class': 'generate_class_elements'}, + 'input': ['test_object'] }, - g.GenerateElements("generate_class_elements").to_json() + g.GenerateElements("generate_class_elements", + objects=["test_object"]).to_json() ) self.assertEqual( @@ -700,40 +689,46 @@ def test_generate_elements(self): 'options': {'option1': 'option'} }, g.GenerateElements("generate_class_elements", - view=g.View(), options={'option1': 'option'}) - .to_json() + view=g.View(), options={"option1": "option"}) + .to_json() ) def test_generate_objects(self): self.assertEqual( { - 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateObjects', 'elementGenerator': {'class': 'test_class_name'} }, g.GenerateObjects("test_class_name").to_json() ) - # Needs writing to test element_generator_fields self.assertEqual( { - 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', - 'elementGenerator': {'class': 'test_class_name'} + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name', + 'key1': 'value1'}, }, - g.GenerateObjects("test_class_name").to_json() + g.GenerateObjects("test_class_name", {"key1": "value1"}).to_json() ) - # Needs writing to test elements self.assertEqual( { - 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', - 'elementGenerator': {'class': 'test_class_name'} + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateObjects', + 'elementGenerator': {'class': 'test_class_name'}, + 'input': [{'class': 'uk.gov.gchq.gaffer.data.element.Entity', + 'group': 'group', + 'vertex': 'vertex'}] }, - g.GenerateObjects("test_class_name").to_json() + g.GenerateObjects("test_class_name", elements=[g.Entity("group", "vertex")]).to_json() ) self.assertEqual( { - 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateObjects', 'elementGenerator': {'class': 'test_class_name'}, 'view': {} }, @@ -742,12 +737,14 @@ def test_generate_objects(self): self.assertEqual( { - 'class': 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects', + 'class': 'uk.gov.gchq.gaffer.operation' + '.impl.generate.GenerateObjects', 'elementGenerator': {'class': 'test_class_name'}, 'view': {}, 'options': {'option1': 'option'} }, - g.GenerateObjects("test_class_name", view=g.View(), options={"option1": "option"}).to_json() + g.GenerateObjects("test_class_name", view=g.View(), + options={"option1": "option"}).to_json() ) def test_export_to_gaffer_result_cache(self): @@ -787,7 +784,7 @@ def test_export_to_gaffer_result_cache(self): 'options': {'option1': 'option'} }, g.ExportToGafferResultCache("test_key", "test_op_auths", - {'option1': 'option'}).to_json() + {"option1": "option"}).to_json() ) def test_get_gaffer_result_cache_export(self): @@ -824,7 +821,7 @@ def test_get_gaffer_result_cache_export(self): '.export.resultcache.GetGafferResultCacheExport', 'jobId': 'test_job_id', 'key': 'test_key', - 'options': {"option1": "option"} + 'options': {'option1': 'option'} }, g.GetGafferResultCacheExport("test_job_id", "test_key", {"option1": "option"}).to_json() @@ -853,7 +850,7 @@ def test_export_to_set(self): 'class': 'uk.gov.gchq.gaffer.operation.impl' '.export.set.ExportToSet', 'key': 'test_key', - 'options': {"option1": "option"} + 'options': {'option1': 'option'} }, g.ExportToSet("test_key", {"option1": "option"}).to_json() ) @@ -895,7 +892,7 @@ def test_get_set_export(self): 'options': {'option1': 'option'} }, g.GetSetExport("test_job_id", "test_key", - {'option1': 'option'}).to_json() + {"option1": "option"}).to_json() ) def test_get_job_details(self): @@ -1298,7 +1295,8 @@ def test_add_named_operation(self): 'overwriteFlag': False, 'description': 'test_description' }, - g.AddNamedOperation("test_operation_chain", "test_name", "test_description").to_json() + g.AddNamedOperation("test_operation_chain", "test_name", + "test_description").to_json() ) self.assertEqual( @@ -1311,7 +1309,8 @@ def test_add_named_operation(self): 'readAccessRoles': 'test_read_access_roles' }, g.AddNamedOperation("test_operation_chain", "test_name", - "test_description", 'test_read_access_roles').to_json() + "test_description", + "test_read_access_roles").to_json() ) self.assertEqual( @@ -1325,8 +1324,8 @@ def test_add_named_operation(self): 'writeAccessRoles': 'test_write_access_roles' }, g.AddNamedOperation("test_operation_chain", "test_name", - "test_description", 'test_read_access_roles', - 'test_write_access_roles').to_json() + "test_description", "test_read_access_roles", + "test_write_access_roles").to_json() ) self.assertEqual( @@ -1340,8 +1339,8 @@ def test_add_named_operation(self): 'writeAccessRoles': 'test_write_access_roles' }, g.AddNamedOperation("test_operation_chain", "test_name", - "test_description", 'test_read_access_roles', - 'test_write_access_roles', True).to_json() + "test_description", "test_read_access_roles", + "test_write_access_roles", True).to_json() ) self.assertEqual( @@ -1356,8 +1355,8 @@ def test_add_named_operation(self): 'options': {'option1': 'option'} }, g.AddNamedOperation("test_operation_chain", "test_name", - "test_description", 'test_read_access_roles', - 'test_write_access_roles', False, + "test_description", "test_read_access_roles", + "test_write_access_roles", False, {"option1": "option"}).to_json() ) @@ -1396,7 +1395,7 @@ def test_get_all_named_operations(self): '.operation.GetAllNamedOperations', 'options': {'options1': 'option'} }, - g.GetAllNamedOperations({'options1': 'option'}).to_json() + g.GetAllNamedOperations({"options1": "option"}).to_json() ) def test_discard_output(self):