예제 #1
0
 def test_traverse_breadth_first(self, sync, nodes):
     tree = Tree(sync)
     root = tree.build(nodes[0])
     root.display()
     for i, node in enumerate(traverse_breadth_first(root)):
         if i == 0:
             assert node.table == 'book'
         if i == 1:
             assert node.table == 'publisher'
         if i == 2:
             assert node.table == 'book_language'
         if i == 3:
             assert node.table == 'author'
         if i == 4:
             assert node.table == 'language'
         if i == 5:
             assert node.table == 'subject'
         if i == 6:
             assert node.table == 'city'
         if i == 7:
             assert node.table == 'country'
         if i == 8:
             assert node.table == 'continent'
예제 #2
0
 def test_traverse_post_order(self, sync, nodes):
     tree = Tree(sync)
     root = tree.build(nodes)
     root.display()
     for i, node in enumerate(traverse_post_order(root)):
         if i == 0:
             assert node.table == "publisher"
         if i == 1:
             assert node.table == "book_language"
         if i == 2:
             assert node.table == "continent"
         if i == 3:
             assert node.table == "country"
         if i == 4:
             assert node.table == "city"
         if i == 5:
             assert node.table == "author"
         if i == 6:
             assert node.table == "language"
         if i == 7:
             assert node.table == "subject"
         if i == 8:
             assert node.table == "book"
 def test_invalid_relationship_type(self, sync):
     nodes = [{
         'table':
         'book',
         'children': [{
             'table': 'rating',
             'relationship': {
                 'variant': 'object',
                 'type': 'qwerty'
             }
         }]
     }]
     with pytest.raises(RelationshipTypeError) as excinfo:
         Tree(sync).build(nodes[0])
     assert 'Relationship type "qwerty" is invalid' in str(excinfo.value)
 def test_invalid_relationship_type(self, sync):
     nodes = {
         "table":
         "book",
         "children": [{
             "table": "publisher",
             "relationship": {
                 "variant": "object",
                 "type": "qwerty"
             },
         }],
     }
     with pytest.raises(RelationshipTypeError) as excinfo:
         Tree(sync).build(nodes)
     assert 'Relationship type "qwerty" is invalid' in str(excinfo.value)
 def test_invalid_relationship_attribute(self, sync):
     nodes = [{
         'table':
         'book',
         'children': [{
             'table': 'rating',
             'relationship': {
                 'foo': 'object',
                 'type': 'one_to_one'
             }
         }]
     }]
     with pytest.raises(RelationshipAttributeError) as excinfo:
         Tree(sync).build(nodes[0])
     assert f"Relationship attribute {set(['foo'])} is invalid" in str(
         excinfo.value)
 def test_invalid_relationship_variant(self, sync):
     nodes = [{
         'table':
         'book',
         'children': [{
             'table': 'rating',
             'relationship': {
                 'variant': 'abcdefg',
                 'type': 'one_to_one'
             }
         }]
     }]
     with pytest.raises(RelationshipVariantError) as excinfo:
         Tree(sync).build(nodes[0])
     assert 'Relationship variant "abcdefg" is invalid' in str(
         excinfo.value)
 def test_invalid_relationship_attribute(self, sync):
     nodes = {
         "table":
         "book",
         "children": [{
             "table": "publisher",
             "relationship": {
                 "foo": "object",
                 "type": "one_to_one"
             },
         }],
     }
     with pytest.raises(RelationshipAttributeError) as excinfo:
         Tree(sync).build(nodes)
     assert f"Relationship attribute {set(['foo'])} is invalid" in str(
         excinfo.value)
 def test_invalid_relationship_variant(self, sync):
     nodes = {
         "table":
         "book",
         "children": [{
             "table": "publisher",
             "relationship": {
                 "variant": "abcdefg",
                 "type": "one_to_one",
             },
         }],
     }
     with pytest.raises(RelationshipVariantError) as excinfo:
         Tree(sync).build(nodes)
     assert 'Relationship variant "abcdefg" is invalid' in str(
         excinfo.value)