-
Notifications
You must be signed in to change notification settings - Fork 209
/
test_description_metadata.py
124 lines (112 loc) · 5.21 KB
/
test_description_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright Contributors to the Amundsen project.
# SPDX-License-Identifier: Apache-2.0
import unittest
from databuilder.models.table_metadata import DescriptionMetadata
from databuilder.serializers import neo4_serializer
class TestDescriptionMetadata(unittest.TestCase):
def test_raise_exception_when_missing_data(self) -> None:
# assert raise when missing description node key
self.assertRaises(
Exception,
DescriptionMetadata(text='test_text').next_node
)
DescriptionMetadata(text='test_text', description_key='test_key').next_node()
DescriptionMetadata(text='test_text', start_key='start_key').next_node()
# assert raise when missing relation start label
self.assertRaises(
Exception,
DescriptionMetadata(text='test_text', start_key='start_key').next_relation
)
DescriptionMetadata(text='test_text', start_key='test_key', start_label='Table').next_relation()
# assert raise when missing relation start key
self.assertRaises(
Exception,
DescriptionMetadata(text='test_text', description_key='test_key', start_label='Table').next_relation
)
def test_serialize_table_description_metadata(self) -> None:
description_metadata = DescriptionMetadata(
text='test text 1',
start_label='Table',
start_key='test_start_key'
)
node_row = description_metadata.next_node()
actual = []
while node_row:
node_row_serialized = neo4_serializer.serialize_node(node_row)
actual.append(node_row_serialized)
node_row = description_metadata.next_node()
expected = [
{'description': 'test text 1', 'KEY': 'test_start_key/_description',
'LABEL': 'Description', 'description_source': 'description'},
]
self.assertEqual(actual, expected)
relation_row = description_metadata.next_relation()
actual = []
while relation_row:
relation_row_serialized = neo4_serializer.serialize_relationship(relation_row)
actual.append(relation_row_serialized)
relation_row = description_metadata.next_relation()
expected = [
{'START_KEY': 'test_start_key', 'START_LABEL': 'Table', 'END_KEY': 'test_start_key/_description',
'END_LABEL': 'Description', 'TYPE': 'DESCRIPTION', 'REVERSE_TYPE': 'DESCRIPTION_OF'}
]
self.assertEqual(actual, expected)
def test_serialize_column_description_metadata(self) -> None:
description_metadata = DescriptionMetadata(
text='test text 2',
start_label='Column',
start_key='test_start_key',
description_key='customized_key'
)
node_row = description_metadata.next_node()
actual = []
while node_row:
node_row_serialized = neo4_serializer.serialize_node(node_row)
actual.append(node_row_serialized)
node_row = description_metadata.next_node()
expected = [
{'description': 'test text 2', 'KEY': 'customized_key',
'LABEL': 'Description', 'description_source': 'description'},
]
self.assertEqual(actual, expected)
relation_row = description_metadata.next_relation()
actual = []
while relation_row:
relation_row_serialized = neo4_serializer.serialize_relationship(relation_row)
actual.append(relation_row_serialized)
relation_row = description_metadata.next_relation()
expected = [
{'START_KEY': 'test_start_key', 'START_LABEL': 'Column', 'END_KEY': 'customized_key',
'END_LABEL': 'Description', 'TYPE': 'DESCRIPTION', 'REVERSE_TYPE': 'DESCRIPTION_OF'}
]
self.assertEqual(actual, expected)
def test_serialize_column_with_source_description_metadata(self) -> None:
description_metadata = DescriptionMetadata(
text='test text 3',
start_label='Column',
start_key='test_start_key',
description_key='customized_key',
source='external',
)
node_row = description_metadata.next_node()
actual = []
while node_row:
node_row_serialized = neo4_serializer.serialize_node(node_row)
actual.append(node_row_serialized)
node_row = description_metadata.next_node()
expected = [
{'description': 'test text 3', 'KEY': 'customized_key',
'LABEL': 'Programmatic_Description', 'description_source': 'external'},
]
self.assertEqual(actual, expected)
relation_row = description_metadata.next_relation()
actual = []
while relation_row:
relation_row_serialized = neo4_serializer.serialize_relationship(relation_row)
actual.append(relation_row_serialized)
relation_row = description_metadata.next_relation()
expected = [
{'START_KEY': 'test_start_key', 'START_LABEL': 'Column', 'END_KEY': 'customized_key',
'END_LABEL': 'Programmatic_Description', 'TYPE': 'DESCRIPTION', 'REVERSE_TYPE': 'DESCRIPTION_OF'}
]
self.assertEqual(actual, expected)