Skip to content

Commit 4c59938

Browse files
authored
Fix/226 mfd table resolvers pt2 (#228)
* fix for mfd_table resolver; new testing package; * Bump version: 0.2.3 → 0.2.4
1 parent b7be92e commit 4c59938

File tree

7 files changed

+110
-7
lines changed

7 files changed

+110
-7
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.3
2+
current_version = 0.2.4
33
commit = True
44
tag = False
55

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Changelog
22

3+
## [0.2.4] - 2024-07-10
4+
### Added
5+
- new e2e_workflow test package to reproduce end-user workflows
6+
- fixed casing for new mfd_table resolver.
7+
38
## [0.2.3] - 2024-07-10
49
### Changed
510
- InversionSolutionInterface.mfd_table resolver now uses tables
611
- InversionSolutionInterface.produced_by_id is removed (was deprecated)
712

13+
814
## [0.2.2] - 2024-06-27
915
### Changed
1016
- Schema.nodes resolver now handles all InversionSolution types

graphql_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = 'GNS Science'
44
__email__ = '[email protected]'
5-
__version__ = '0.2.3'
5+
__version__ = '0.2.4'

graphql_api/schema/custom/inversion_solution.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ class InversionSolutionInterface(graphene.Interface):
6161
)
6262

6363
def resolve_mfd_table(root, info, **args):
64-
for table in root.tables:
65-
if table.get('table_type') == 'MFD_CURVES_V2':
66-
return Table.get_node(None, table['table_id'])
64+
if root.tables:
65+
for table in root.tables:
66+
if table.get('table_type').upper() == 'MFD_CURVES_V2':
67+
_clazz, _id = from_global_id(table['table_id'])
68+
return Table.get_node(None, _id)
6769

6870
produced_by = graphene.Field(AutomationTaskUnion)
6971

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import unittest
2+
3+
import boto3
4+
from graphene.test import Client
5+
from moto import mock_dynamodb, mock_s3
6+
from pynamodb.connection.base import Connection # for mocking
7+
8+
from graphql_api.config import REGION, S3_BUCKET_NAME
9+
from graphql_api.data import data_manager
10+
from graphql_api.dynamodb.models import ToshiFileObject, ToshiIdentity, ToshiTableObject
11+
from graphql_api.schema import root_schema
12+
from graphql_api.schema.search_manager import SearchManager
13+
14+
15+
@mock_dynamodb
16+
@mock_s3
17+
class TestInversionSolutionWithMFDWorkflow(unittest.TestCase):
18+
19+
def setUp(self):
20+
self.client = Client(root_schema)
21+
22+
# S3
23+
self._s3 = boto3.resource('s3', region_name=REGION)
24+
self._s3.create_bucket(Bucket=S3_BUCKET_NAME)
25+
26+
# Dynamo
27+
self._connection = Connection(region=REGION)
28+
29+
ToshiTableObject.create_table()
30+
ToshiFileObject.create_table()
31+
ToshiIdentity.create_table()
32+
33+
self._data_manager = data_manager.DataManager(search_manager=SearchManager('test', 'test', {'fake': 'auth'}))
34+
35+
def test_link_inversion_solution_with_mfd_table(self):
36+
37+
SETUP = '''
38+
mutation m0 {
39+
create_inversion_solution(input: {file_name: "MyINversion", file_size: 200}) {
40+
ok
41+
inversion_solution {
42+
id
43+
}
44+
}
45+
46+
create_table(
47+
input: {
48+
object_id: "R2VuZXJhbFRhc2s6MjE3Qk1YREw=",
49+
created: "2021-06-11T02:37:26.009506+00:00",
50+
rows: [["1", "1.01"], ["2", "2.2"]], meta: [{k: "some_metric", v: "20"}],
51+
table_type: MFD_CURVES_V2,
52+
dimensions: [
53+
{k: "grid_spacings", v: ["0.1"]},
54+
{k: "IML_periods", v: ["0", "0.1"]}, {k: "tags", v: ["opensha", "testing"]}, {k: "gmpes", v: ["ASK_2014"]}]}
55+
) {
56+
57+
table {
58+
id
59+
table_type
60+
}
61+
}
62+
63+
append_inversion_solution_tables(
64+
input: {id: "SW52ZXJzaW9uU29sdXRpb246MTAwMDAw", tables: [{produced_by_id: "PRODUCER_ID",
65+
label: "MyLabelledTable", table_id: "VGFibGU6MTAwMDAw", table_type: MFD_CURVES_V2}]}
66+
) {
67+
ok
68+
}
69+
}'''
70+
71+
result = self.client.execute(SETUP)
72+
print(result)
73+
# assert 0
74+
VERIFY = '''
75+
query {
76+
node(id: "SW52ZXJzaW9uU29sdXRpb246MTAwMDAw") {
77+
__typename
78+
... on InversionSolution {
79+
id
80+
created
81+
file_name
82+
# mfd_table_id
83+
mfd_table { id }
84+
# hazard_table_id
85+
created
86+
}
87+
}
88+
}
89+
'''
90+
result = self.client.execute(VERIFY)
91+
92+
print(result)
93+
assert not result.get('errors')
94+
assert result['data']['node']['mfd_table']['id']
95+
assert result['data']['node']['mfd_table']['id'] == 'VGFibGU6MTAwMDAw'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nzshm22-toshi-api",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "A graphql API for NZSHM22 shared resources using AWS lambda, S3, Dynamodb and ElasticSearch",
55
"directories": {
66
"lib": "lib"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nshm-toshi-api"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
description = "the object store used by NZSHM project"
55
authors = ["Chris Chamberlain <[email protected]>"]
66
license = "AGPL3"

0 commit comments

Comments
 (0)