@@ -92,7 +92,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
92
92
data_integrator_unit = ops_test .model .applications [f"{ INTEGRATOR_APP_NAME } 1" ].units [0 ]
93
93
results = await juju_ .run_action (data_integrator_unit , "get-credentials" )
94
94
95
- logger .info ("Checking that the charmed_read role can read from the database " )
95
+ logger .info ("Checking that the charmed_read role can read from an existing table " )
96
96
rows = await execute_queries_on_unit (
97
97
primary_unit_address ,
98
98
results ["mysql" ]["username" ],
@@ -107,26 +107,26 @@ async def test_charmed_read_role(ops_test: OpsTest):
107
107
"test_data_2" ,
108
108
]), "Unexpected data in charmed_read_database with charmed_read role"
109
109
110
- logger .info ("Checking that the charmed_read role cannot create a new table" )
110
+ logger .info ("Checking that the charmed_read role cannot write into an existing table" )
111
111
with pytest .raises (ProgrammingError ):
112
112
await execute_queries_on_unit (
113
113
primary_unit_address ,
114
114
results ["mysql" ]["username" ],
115
115
results ["mysql" ]["password" ],
116
116
[
117
- "CREATE TABLE charmed_read_database.new_table (`id` SERIAL PRIMARY KEY, ` data` TEXT )" ,
117
+ "INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_3' )" ,
118
118
],
119
119
commit = True ,
120
120
)
121
121
122
- logger .info ("Checking that the charmed_read role cannot write to an existing table" )
122
+ logger .info ("Checking that the charmed_read role cannot create a new table" )
123
123
with pytest .raises (ProgrammingError ):
124
124
await execute_queries_on_unit (
125
125
primary_unit_address ,
126
126
results ["mysql" ]["username" ],
127
127
results ["mysql" ]["password" ],
128
128
[
129
- "INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_3'), ('test_data_4' )" ,
129
+ "CREATE TABLE charmed_read_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT )" ,
130
130
],
131
131
commit = True ,
132
132
)
@@ -191,6 +191,22 @@ async def test_charmed_dml_role(ops_test: OpsTest):
191
191
data_integrator_2_unit = ops_test .model .applications [f"{ INTEGRATOR_APP_NAME } 2" ].units [0 ]
192
192
results = await juju_ .run_action (data_integrator_2_unit , "get-credentials" )
193
193
194
+ logger .info ("Checking that the charmed_dml role can read from an existing table" )
195
+ rows = await execute_queries_on_unit (
196
+ primary_unit_address ,
197
+ results ["mysql" ]["username" ],
198
+ results ["mysql" ]["password" ],
199
+ [
200
+ "SELECT `data` FROM charmed_dml_database.test_table" ,
201
+ ],
202
+ commit = True ,
203
+ )
204
+
205
+ assert sorted (rows ) == sorted ([
206
+ "test_data_1" ,
207
+ "test_data_2" ,
208
+ ]), "Unexpected data in charmed_read_database with charmed_read role"
209
+
194
210
logger .info ("Checking that the charmed_dml role can write into an existing table" )
195
211
await execute_queries_on_unit (
196
212
primary_unit_address ,
@@ -202,14 +218,14 @@ async def test_charmed_dml_role(ops_test: OpsTest):
202
218
commit = True ,
203
219
)
204
220
205
- logger .info ("Checking that the charmed_dml role cannot read from an existing table" )
221
+ logger .info ("Checking that the charmed_dml role cannot create a new table" )
206
222
with pytest .raises (ProgrammingError ):
207
223
await execute_queries_on_unit (
208
224
primary_unit_address ,
209
225
results ["mysql" ]["username" ],
210
226
results ["mysql" ]["password" ],
211
227
[
212
- "SELECT `data` FROM charmed_dml_database.test_table " ,
228
+ "CREATE TABLE charmed_dml_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT) " ,
213
229
],
214
230
commit = True ,
215
231
)
0 commit comments