diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d8de5e1..c484a4b 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.2.4 commit = True tag = False diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6d05b..c133703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ # Changelog +## [0.2.4] - 2024-07-10 +### Added + - new e2e_workflow test package to reproduce end-user workflows + - fixed casing for new mfd_table resolver. + ## [0.2.3] - 2024-07-10 ### Changed - InversionSolutionInterface.mfd_table resolver now uses tables - InversionSolutionInterface.produced_by_id is removed (was deprecated) + ## [0.2.2] - 2024-06-27 ### Changed - Schema.nodes resolver now handles all InversionSolution types diff --git a/graphql_api/__init__.py b/graphql_api/__init__.py index 0190eaf..b5d4b16 100644 --- a/graphql_api/__init__.py +++ b/graphql_api/__init__.py @@ -2,4 +2,4 @@ __author__ = 'GNS Science' __email__ = 'nshm@gns.cri.nz' -__version__ = '0.2.3' +__version__ = '0.2.4' diff --git a/graphql_api/schema/custom/inversion_solution.py b/graphql_api/schema/custom/inversion_solution.py index 30ba1d5..a8c0514 100644 --- a/graphql_api/schema/custom/inversion_solution.py +++ b/graphql_api/schema/custom/inversion_solution.py @@ -61,9 +61,11 @@ class InversionSolutionInterface(graphene.Interface): ) def resolve_mfd_table(root, info, **args): - for table in root.tables: - if table.get('table_type') == 'MFD_CURVES_V2': - return Table.get_node(None, table['table_id']) + if root.tables: + for table in root.tables: + if table.get('table_type').upper() == 'MFD_CURVES_V2': + _clazz, _id = from_global_id(table['table_id']) + return Table.get_node(None, _id) produced_by = graphene.Field(AutomationTaskUnion) diff --git a/graphql_api/tests/e2e_workflows/test_inversion_solution_table_e2e.py b/graphql_api/tests/e2e_workflows/test_inversion_solution_table_e2e.py new file mode 100644 index 0000000..5345fe5 --- /dev/null +++ b/graphql_api/tests/e2e_workflows/test_inversion_solution_table_e2e.py @@ -0,0 +1,95 @@ +import unittest + +import boto3 +from graphene.test import Client +from moto import mock_dynamodb, mock_s3 +from pynamodb.connection.base import Connection # for mocking + +from graphql_api.config import REGION, S3_BUCKET_NAME +from graphql_api.data import data_manager +from graphql_api.dynamodb.models import ToshiFileObject, ToshiIdentity, ToshiTableObject +from graphql_api.schema import root_schema +from graphql_api.schema.search_manager import SearchManager + + +@mock_dynamodb +@mock_s3 +class TestInversionSolutionWithMFDWorkflow(unittest.TestCase): + + def setUp(self): + self.client = Client(root_schema) + + # S3 + self._s3 = boto3.resource('s3', region_name=REGION) + self._s3.create_bucket(Bucket=S3_BUCKET_NAME) + + # Dynamo + self._connection = Connection(region=REGION) + + ToshiTableObject.create_table() + ToshiFileObject.create_table() + ToshiIdentity.create_table() + + self._data_manager = data_manager.DataManager(search_manager=SearchManager('test', 'test', {'fake': 'auth'})) + + def test_link_inversion_solution_with_mfd_table(self): + + SETUP = ''' + mutation m0 { + create_inversion_solution(input: {file_name: "MyINversion", file_size: 200}) { + ok + inversion_solution { + id + } + } + + create_table( + input: { + object_id: "R2VuZXJhbFRhc2s6MjE3Qk1YREw=", + created: "2021-06-11T02:37:26.009506+00:00", + rows: [["1", "1.01"], ["2", "2.2"]], meta: [{k: "some_metric", v: "20"}], + table_type: MFD_CURVES_V2, + dimensions: [ + {k: "grid_spacings", v: ["0.1"]}, + {k: "IML_periods", v: ["0", "0.1"]}, {k: "tags", v: ["opensha", "testing"]}, {k: "gmpes", v: ["ASK_2014"]}]} + ) { + + table { + id + table_type + } + } + + append_inversion_solution_tables( + input: {id: "SW52ZXJzaW9uU29sdXRpb246MTAwMDAw", tables: [{produced_by_id: "PRODUCER_ID", + label: "MyLabelledTable", table_id: "VGFibGU6MTAwMDAw", table_type: MFD_CURVES_V2}]} + ) { + ok + } + }''' + + result = self.client.execute(SETUP) + print(result) + # assert 0 + VERIFY = ''' + query { + node(id: "SW52ZXJzaW9uU29sdXRpb246MTAwMDAw") { + __typename + ... on InversionSolution { + id + created + file_name + # mfd_table_id + mfd_table { id } + # hazard_table_id + created + } + } + } + ''' + result = self.client.execute(VERIFY) + + print(result) + assert not result.get('errors') + assert result['data']['node']['mfd_table']['id'] + assert result['data']['node']['mfd_table']['id'] == 'VGFibGU6MTAwMDAw' diff --git a/package.json b/package.json index f9a8211..e82de37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nzshm22-toshi-api", - "version": "0.2.3", + "version": "0.2.4", "description": "A graphql API for NZSHM22 shared resources using AWS lambda, S3, Dynamodb and ElasticSearch", "directories": { "lib": "lib" diff --git a/pyproject.toml b/pyproject.toml index d526e3b..e55c8ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nshm-toshi-api" -version = "0.2.3" +version = "0.2.4" description = "the object store used by NZSHM project" authors = ["Chris Chamberlain "] license = "AGPL3"