55 maybe_convert_to_schema_field_urn ,
66 clean_gql_response ,
77 clean_get_entity_response ,
8+ truncate_descriptions ,
89)
910from datahub .ingestion .graph .links import make_url_for_urn
1011
1112
12- def test_inject_urls_for_urns ():
13+ def test_inject_urls_for_urns () -> None :
1314 mock_graph = Mock ()
1415 mock_graph .url_for .side_effect = lambda urn : make_url_for_urn (
1516 "https://xyz.com" , urn
@@ -58,7 +59,7 @@ def test_inject_urls_for_urns():
5859 assert mock_graph .url_for .call_count == 2
5960
6061
61- def test_maybe_convert_to_schema_field_urn_with_column ():
62+ def test_maybe_convert_to_schema_field_urn_with_column () -> None :
6263 dataset_urn = "urn:li:dataset:(urn:li:dataPlatform:snowflake,analytics_db.raw_schema.users,PROD)"
6364 column = "user_id"
6465
@@ -70,15 +71,15 @@ def test_maybe_convert_to_schema_field_urn_with_column():
7071 )
7172
7273
73- def test_maybe_convert_to_schema_field_urn_without_column ():
74+ def test_maybe_convert_to_schema_field_urn_without_column () -> None :
7475 original_urn = "urn:li:dataset:(urn:li:dataPlatform:snowflake,analytics_db.raw_schema.users,PROD)"
7576
7677 result = maybe_convert_to_schema_field_urn (original_urn , None )
7778
7879 assert result == original_urn
7980
8081
81- def test_maybe_convert_to_schema_field_urn_with_incorrect_entity ():
82+ def test_maybe_convert_to_schema_field_urn_with_incorrect_entity () -> None :
8283 chart_urn = "urn:li:chart:(looker,baz)"
8384
8485 # Ok if no column is provided
@@ -91,8 +92,8 @@ def test_maybe_convert_to_schema_field_urn_with_incorrect_entity():
9192 maybe_convert_to_schema_field_urn (chart_urn , column )
9293
9394
94- def test_clean_gql_response_with_dict ():
95- response = {
95+ def test_clean_gql_response_with_dict () -> None :
96+ response : dict = {
9697 "__typename" : "Dataset" ,
9798 "urn" : "urn:li:dataset:(urn:li:dataPlatform:snowflake,analytics_db.raw_schema.users,PROD)" ,
9899 "name" : "users" ,
@@ -112,7 +113,7 @@ def test_clean_gql_response_with_dict():
112113 assert result == expected_result
113114
114115
115- def test_clean_gql_response_with_nested_empty_objects ():
116+ def test_clean_gql_response_with_nested_empty_objects () -> None :
116117 response = {
117118 "urn" : "urn:li:dataset:(urn:li:dataPlatform:snowflake,analytics_db.raw_schema.users,PROD)" ,
118119 "name" : "users" ,
@@ -141,7 +142,7 @@ def test_clean_gql_response_with_nested_empty_objects():
141142 assert result == expected_result
142143
143144
144- def test_clean_get_entity_response_with_schema_metadata ():
145+ def test_clean_get_entity_response_with_schema_metadata () -> None :
145146 raw_response = {
146147 "urn" : "urn:li:dataset:(urn:li:dataPlatform:snowflake,analytics_db.raw_schema.users,PROD)" ,
147148 "name" : "users" ,
@@ -195,3 +196,57 @@ def test_clean_get_entity_response_with_schema_metadata():
195196 }
196197
197198 assert result == expected_result
199+
200+
201+ def test_truncate_descriptions () -> None :
202+ result = {
203+ "downstreams" : {
204+ "searchResults" : [
205+ {
206+ "entity" : {
207+ "description" : "Description with  and more content that exceeds the limit" ,
208+ "properties" : {
209+ "description" : "Description with image <img src='data:image/png;base64,encoded_data' /> and more content that exceeds the limit"
210+ },
211+ "fields" : [
212+ {
213+ "fieldPath" : "description" ,
214+ "description" : "Description with image <img src='data:image/png;base64,encoded_data' /> and more content that exceeds the limit" ,
215+ },
216+ {
217+ "fieldPath" : "description" ,
218+ "description" : "Simple description" ,
219+ },
220+ ],
221+ }
222+ }
223+ ]
224+ }
225+ }
226+
227+ truncate_descriptions (result , 50 )
228+
229+ assert result == {
230+ "downstreams" : {
231+ "searchResults" : [
232+ {
233+ "entity" : {
234+ "description" : "Description with image and more content that exceeds the limit" ,
235+ "properties" : {
236+ "description" : "Description with image and more content that exceeds the limit"
237+ },
238+ "fields" : [
239+ {
240+ "fieldPath" : "description" ,
241+ "description" : "Description with image and more content that exceeds the limit" ,
242+ },
243+ {
244+ "fieldPath" : "description" ,
245+ "description" : "Simple description" ,
246+ },
247+ ],
248+ }
249+ }
250+ ]
251+ }
252+ }
0 commit comments