Skip to content

Commit

Permalink
Fix/226 mfd table resolvers pt2 (#228)
Browse files Browse the repository at this point in the history
* fix for mfd_table resolver; new testing package;
* Bump version: 0.2.3 → 0.2.4
  • Loading branch information
chrisbc authored Jul 10, 2024
1 parent b7be92e commit 4c59938
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.2.4
commit = True
tag = False

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = 'GNS Science'
__email__ = '[email protected]'
__version__ = '0.2.3'
__version__ = '0.2.4'
8 changes: 5 additions & 3 deletions graphql_api/schema/custom/inversion_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "AGPL3"
Expand Down

0 comments on commit 4c59938

Please sign in to comment.