22
22
from behave import *
23
23
from hamcrest import *
24
24
25
- from typedb .client import *
26
25
from tests .behaviour .config .parameters import parse_bool , parse_list , RootLabel , parse_label
27
26
from tests .behaviour .context import Context
27
+ from typedb .client import *
28
28
29
29
30
30
@step ("put {root_label:RootLabel} type: {type_label}" )
@@ -51,20 +51,20 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str):
51
51
context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).delete ()
52
52
53
53
54
- @step ("{root_label:RootLabel}({type_label}) is null: {is_null}" )
55
- def step_impl (context : Context , root_label : RootLabel , type_label : str , is_null ):
54
+ @step ("{root_label:RootLabel}({type_label:Label }) is null: {is_null}" )
55
+ def step_impl (context : Context , root_label : RootLabel , type_label : Label , is_null ):
56
56
is_null = parse_bool (is_null )
57
- assert_that (context .get_thing_type (root_label , type_label ) is None , is_ (is_null ))
57
+ assert_that (context .get_thing_type (root_label , type_label . name () ) is None , is_ (is_null ))
58
58
59
59
60
60
@step ("{root_label:RootLabel}({type_label}) set label: {new_label}" )
61
61
def step_impl (context : Context , root_label : RootLabel , type_label : str , new_label : str ):
62
62
context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).set_label (new_label )
63
63
64
64
65
- @step ("{root_label:RootLabel}({type_label}) get label: {get_label}" )
66
- def step_impl (context : Context , root_label : RootLabel , type_label : str , get_label : str ):
67
- assert_that (context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_label ().name (), is_ (get_label ))
65
+ @step ("{root_label:RootLabel}({type_label:Label }) get label: {get_label}" )
66
+ def step_impl (context : Context , root_label : RootLabel , type_label : Label , get_label : str ):
67
+ assert_that (context .get_thing_type (root_label , type_label . name () ).as_remote (context .tx ()).get_label ().name (), is_ (get_label ))
68
68
69
69
70
70
@step ("{root_label:RootLabel}({type_label}) set abstract: {is_abstract}; throws exception" )
@@ -229,18 +229,42 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type
229
229
context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).unset_owns (attribute_type )
230
230
231
231
232
+ def get_actual_owns_key_types (context : Context , root_label : RootLabel , type_label : str ):
233
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_owns (keys_only = True )]
234
+
235
+
232
236
@step ("{root_label:RootLabel}({type_label}) get owns key types contain" )
233
237
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
234
238
attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
235
- actuals = [ t . get_label () for t in context . get_thing_type ( root_label , type_label ). as_remote ( context . tx ()). get_owns ( keys_only = True )]
239
+ actuals = get_actual_owns_key_types ( context , root_label , type_label )
236
240
for attribute_label in attribute_labels :
237
241
assert_that (actuals , has_item (attribute_label ))
238
242
239
243
240
244
@step ("{root_label:RootLabel}({type_label}) get owns key types do not contain" )
241
245
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
242
246
attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
243
- actuals = [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_owns (keys_only = True )]
247
+ actuals = get_actual_owns_key_types (context , root_label , type_label )
248
+ for attribute_label in attribute_labels :
249
+ assert_that (actuals , not_ (has_item (attribute_label )))
250
+
251
+
252
+ def get_actual_owns_explicit_key_types (context : Context , root_label : RootLabel , type_label : str ):
253
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_owns_explicit (keys_only = True )]
254
+
255
+
256
+ @step ("{root_label:RootLabel}({type_label}) get owns explicit key types contain" )
257
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
258
+ attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
259
+ actuals = get_actual_owns_explicit_key_types (context , root_label , type_label )
260
+ for attribute_label in attribute_labels :
261
+ assert_that (actuals , has_item (attribute_label ))
262
+
263
+
264
+ @step ("{root_label:RootLabel}({type_label}) get owns explicit key types do not contain" )
265
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
266
+ attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
267
+ actuals = get_actual_owns_explicit_key_types (context , root_label , type_label )
244
268
for attribute_label in attribute_labels :
245
269
assert_that (actuals , not_ (has_item (attribute_label )))
246
270
@@ -279,22 +303,59 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type
279
303
context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).set_owns (attribute_type )
280
304
281
305
306
+ def get_actual_owns (context : Context , root_label : RootLabel , type_label : str ):
307
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_owns ()]
308
+
309
+
282
310
@step ("{root_label:RootLabel}({type_label}) get owns attribute types contain" )
283
311
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
284
312
attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
285
- actuals = [ t . get_label () for t in context . get_thing_type ( root_label , type_label ). as_remote ( context . tx ()). get_owns ()]
313
+ actuals = get_actual_owns ( context , root_label , type_label )
286
314
for attribute_label in attribute_labels :
287
315
assert_that (actuals , has_item (attribute_label ))
288
316
289
317
290
318
@step ("{root_label:RootLabel}({type_label}) get owns attribute types do not contain" )
291
319
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
292
320
attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
293
- actuals = [ t . get_label () for t in context . get_thing_type ( root_label , type_label ). as_remote ( context . tx ()). get_owns ()]
321
+ actuals = get_actual_owns ( context , root_label , type_label )
294
322
for attribute_label in attribute_labels :
295
323
assert_that (actuals , not_ (has_item (attribute_label )))
296
324
297
325
326
+ def get_actual_owns_explicit (context : Context , root_label : RootLabel , type_label : str ):
327
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_owns_explicit ()]
328
+
329
+
330
+ @step ("{root_label:RootLabel}({type_label}) get owns explicit attribute types contain" )
331
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
332
+ attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
333
+ actuals = get_actual_owns_explicit (context , root_label , type_label )
334
+ for attribute_label in attribute_labels :
335
+ assert_that (actuals , has_item (attribute_label ))
336
+
337
+
338
+ @step ("{root_label:RootLabel}({type_label}) get owns explicit attribute types do not contain" )
339
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
340
+ attribute_labels = [parse_label (s ) for s in parse_list (context .table )]
341
+ actuals = get_actual_owns_explicit (context , root_label , type_label )
342
+ for attribute_label in attribute_labels :
343
+ assert_that (actuals , not_ (has_item (attribute_label )))
344
+
345
+
346
+ @step ("{root_label:RootLabel}({type_label:Label}) get owns overridden attribute({attr_type_label}) is null: {is_null}" )
347
+ def step_impl (context : Context , root_label : RootLabel , type_label : Label , attr_type_label : str , is_null ):
348
+ is_null = parse_bool (is_null )
349
+ attribute_type = context .tx ().concepts ().get_attribute_type (attr_type_label )
350
+ assert_that (context .get_thing_type (root_label , type_label .name ()).as_remote (context .tx ()).get_owns_overridden (attribute_type ) is None , is_ (is_null ))
351
+
352
+
353
+ @step ("{root_label:RootLabel}({type_label:Label}) get owns overridden attribute({attr_type_label}) get label: {label}" )
354
+ def step_impl (context : Context , root_label : RootLabel , type_label : Label , attr_type_label : str , label : str ):
355
+ attribute_type = context .tx ().concepts ().get_attribute_type (attr_type_label )
356
+ assert_that (context .get_thing_type (root_label , type_label .name ()).as_remote (context .tx ()).get_owns_overridden (attribute_type ).get_label ().name (), is_ (label ))
357
+
358
+
298
359
@step ("{root_label:RootLabel}({type_label}) set plays role: {role_label:ScopedLabel} as {overridden_label:ScopedLabel}; throws exception" )
299
360
def step_impl (context : Context , root_label : RootLabel , type_label : str , role_label : Label , overridden_label : Label ):
300
361
role_type = context .tx ().concepts ().get_relation_type (role_label .scope ()).as_remote (context .tx ()).get_relates (role_label .name ())
@@ -345,18 +406,42 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str, role_lab
345
406
context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).unset_plays (role_type )
346
407
347
408
409
+ def get_actual_plays (context : Context , root_label : RootLabel , type_label : str ):
410
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_plays ()]
411
+
412
+
348
413
@step ("{root_label:RootLabel}({type_label}) get playing roles contain" )
349
414
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
350
415
role_labels = [parse_label (s ) for s in parse_list (context .table )]
351
- actuals = [ t . get_label () for t in context . get_thing_type ( root_label , type_label ). as_remote ( context . tx ()). get_plays ()]
416
+ actuals = get_actual_plays ( context , root_label , type_label )
352
417
for role_label in role_labels :
353
418
assert_that (role_label , is_in (actuals ))
354
419
355
420
356
421
@step ("{root_label:RootLabel}({type_label}) get playing roles do not contain" )
357
422
def step_impl (context : Context , root_label : RootLabel , type_label : str ):
358
423
role_labels = [parse_label (s ) for s in parse_list (context .table )]
359
- actuals = [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_plays ()]
424
+ actuals = get_actual_plays (context , root_label , type_label )
425
+ for role_label in role_labels :
426
+ assert_that (role_label , not_ (is_in (actuals )))
427
+
428
+
429
+ def get_actual_plays_explicit (context : Context , root_label : RootLabel , type_label : str ):
430
+ return [t .get_label () for t in context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).get_plays_explicit ()]
431
+
432
+
433
+ @step ("{root_label:RootLabel}({type_label}) get playing roles explicit contain" )
434
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
435
+ role_labels = [parse_label (s ) for s in parse_list (context .table )]
436
+ actuals = get_actual_plays_explicit (context , root_label , type_label )
437
+ for role_label in role_labels :
438
+ assert_that (role_label , is_in (actuals ))
439
+
440
+
441
+ @step ("{root_label:RootLabel}({type_label}) get playing roles explicit do not contain" )
442
+ def step_impl (context : Context , root_label : RootLabel , type_label : str ):
443
+ role_labels = [parse_label (s ) for s in parse_list (context .table )]
444
+ actuals = get_actual_plays_explicit (context , root_label , type_label )
360
445
for role_label in role_labels :
361
446
assert_that (role_label , not_ (is_in (actuals )))
362
447
0 commit comments