6
6
from unittest import mock
7
7
8
8
import boto3
9
+ import pytest
9
10
from graphene .test import Client
10
11
from moto import mock_dynamodb , mock_s3
11
12
from pynamodb .connection .base import Connection # for mocking
40
41
}
41
42
}'''
42
43
44
+ INPUT_VARIABLES = {
45
+ 'headers' : ['series' , 'series_name' , 'X' , 'Y' ],
46
+ 'object_id' : 'SW52ZXJzaW9uU29sdXRpb246MTAxOTY2' ,
47
+ 'rows' : [['0' , 'foo' , '1.0' , '2.0' ], ['1' , 'bar' , '1.5' , '2.5' ]],
48
+ 'column_types' : ['integer' , 'string' , 'double' , 'double' ],
49
+ 'table_name' : 'Inversion Solution MFD table' ,
50
+ 'created' : '2025-08-06T23:32:58.526823Z' ,
51
+ 'table_type' : 'MFD_CURVES' ,
52
+ 'dimensions' : [],
53
+ }
54
+
43
55
44
56
class IncrId :
45
57
next_id = - 1
@@ -49,6 +61,11 @@ def get_next_id(self, *args):
49
61
return str (self .next_id ) + 'RANDM'
50
62
51
63
64
+ def json_dumps_mock (obj ):
65
+ raise RuntimeError (str (obj ))
66
+ return None
67
+
68
+
52
69
@mock .patch ('graphql_api.data.BaseDynamoDBData._write_object' , lambda self , object_id , object_type , body : None )
53
70
class TestFailingMutation (unittest .TestCase ):
54
71
"""
@@ -69,17 +86,8 @@ def test_create_252_exmple_table(self):
69
86
# {'message': 'Object of type EnumMeta is not JSON serializable', 'locations': [{'line': 2, 'column': 3}], 'path': ['create_table']}
70
87
71
88
print (CREATE_TABLE )
72
- input_variables = {
73
- 'headers' : ['series' , 'series_name' , 'X' , 'Y' ],
74
- 'object_id' : 'SW52ZXJzaW9uU29sdXRpb246MTAxOTY2' ,
75
- 'rows' : [['0' , 'foo' , '1.0' , '2.0' ], ['1' , 'bar' , '1.5' , '2.5' ]],
76
- 'column_types' : ['integer' , 'string' , 'double' , 'double' ],
77
- 'table_name' : 'Inversion Solution MFD table' ,
78
- 'created' : '2025-08-06T23:32:58.526823Z' ,
79
- 'table_type' : 'MFD_CURVES' ,
80
- 'dimensions' : [],
81
- }
82
- result = self .client .execute (CREATE_TABLE , variable_values = input_variables )
89
+
90
+ result = self .client .execute (CREATE_TABLE , variable_values = INPUT_VARIABLES )
83
91
print (result )
84
92
assert result ['data' ]['create_table' ]['table' ]['id' ] == 'VGFibGU6MFJBTkRN'
85
93
@@ -97,7 +105,6 @@ def setUp(self):
97
105
self ._bucket = self ._s3_conn .Bucket (S3_BUCKET_NAME )
98
106
self ._connection = Connection (region = REGION )
99
107
100
- # ToshiThingObject.create_table()
101
108
ToshiTableObject .create_table ()
102
109
ToshiIdentity .create_table ()
103
110
@@ -106,16 +113,14 @@ def setUp(self):
106
113
def test_create_one_table (self ):
107
114
108
115
print (CREATE_TABLE )
109
- input_variables = {
110
- 'headers' : ['series' , 'series_name' , 'X' , 'Y' ],
111
- 'object_id' : 'SW52ZXJzaW9uU29sdXRpb246MTAxOTY2' ,
112
- 'rows' : [['0' , 'foo' , '1.0' , '2.0' ], ['1' , 'bar' , '1.5' , '2.5' ]],
113
- 'column_types' : ['integer' , 'string' , 'double' , 'double' ],
114
- 'table_name' : 'Inversion Solution MFD table' ,
115
- 'created' : '2025-08-06T23:32:58.526823Z' ,
116
- 'table_type' : 'MFD_CURVES' ,
117
- 'dimensions' : [],
118
- }
119
- result = self .client .execute (CREATE_TABLE , variable_values = input_variables )
116
+
117
+ result = self .client .execute (CREATE_TABLE , variable_values = INPUT_VARIABLES )
120
118
print (result )
121
119
assert result ['data' ]['create_table' ]['table' ]['id' ] == 'VGFibGU6MTAwMDAw'
120
+
121
+ @mock .patch ('graphql_api.data.base_data.json_serialised' , json_dumps_mock )
122
+ def test_new_logging_exception_handing (self ):
123
+ print (CREATE_TABLE )
124
+ result = self .client .execute (CREATE_TABLE , variable_values = INPUT_VARIABLES )
125
+ print (result ['errors' ])
126
+ assert result ['errors' ][0 ]['message' ].find ("This object cannot be persisted to a PynamoDB.Model" ) != - 1
0 commit comments