2222from behave import *
2323from hamcrest import *
2424
25- from typedb .client import *
2625from tests .behaviour .config .parameters import parse_bool , parse_list , RootLabel , parse_label
2726from tests .behaviour .context import Context
27+ from typedb .client import *
2828
2929
3030@step ("put {root_label:RootLabel} type: {type_label}" )
@@ -51,20 +51,20 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str):
5151 context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).delete ()
5252
5353
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 ):
5656 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 ))
5858
5959
6060@step ("{root_label:RootLabel}({type_label}) set label: {new_label}" )
6161def step_impl (context : Context , root_label : RootLabel , type_label : str , new_label : str ):
6262 context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).set_label (new_label )
6363
6464
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 ))
6868
6969
7070@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
229229 context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).unset_owns (attribute_type )
230230
231231
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+
232236@step ("{root_label:RootLabel}({type_label}) get owns key types contain" )
233237def step_impl (context : Context , root_label : RootLabel , type_label : str ):
234238 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 )
236240 for attribute_label in attribute_labels :
237241 assert_that (actuals , has_item (attribute_label ))
238242
239243
240244@step ("{root_label:RootLabel}({type_label}) get owns key types do not contain" )
241245def step_impl (context : Context , root_label : RootLabel , type_label : str ):
242246 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 )
244268 for attribute_label in attribute_labels :
245269 assert_that (actuals , not_ (has_item (attribute_label )))
246270
@@ -279,22 +303,59 @@ def step_impl(context: Context, root_label: RootLabel, type_label: str, att_type
279303 context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).set_owns (attribute_type )
280304
281305
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+
282310@step ("{root_label:RootLabel}({type_label}) get owns attribute types contain" )
283311def step_impl (context : Context , root_label : RootLabel , type_label : str ):
284312 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 )
286314 for attribute_label in attribute_labels :
287315 assert_that (actuals , has_item (attribute_label ))
288316
289317
290318@step ("{root_label:RootLabel}({type_label}) get owns attribute types do not contain" )
291319def step_impl (context : Context , root_label : RootLabel , type_label : str ):
292320 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 )
294322 for attribute_label in attribute_labels :
295323 assert_that (actuals , not_ (has_item (attribute_label )))
296324
297325
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+
298359@step ("{root_label:RootLabel}({type_label}) set plays role: {role_label:ScopedLabel} as {overridden_label:ScopedLabel}; throws exception" )
299360def step_impl (context : Context , root_label : RootLabel , type_label : str , role_label : Label , overridden_label : Label ):
300361 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
345406 context .get_thing_type (root_label , type_label ).as_remote (context .tx ()).unset_plays (role_type )
346407
347408
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+
348413@step ("{root_label:RootLabel}({type_label}) get playing roles contain" )
349414def step_impl (context : Context , root_label : RootLabel , type_label : str ):
350415 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 )
352417 for role_label in role_labels :
353418 assert_that (role_label , is_in (actuals ))
354419
355420
356421@step ("{root_label:RootLabel}({type_label}) get playing roles do not contain" )
357422def step_impl (context : Context , root_label : RootLabel , type_label : str ):
358423 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 )
360445 for role_label in role_labels :
361446 assert_that (role_label , not_ (is_in (actuals )))
362447
0 commit comments