Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1 

2import os 

3import sys 

4import pytest 

5sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../../../") 

6import sdc_etl_libs.sdc_data_schema.schema_exceptions as SchemaExceptions 

7from sdc_etl_libs.sdc_data_schema.schema_toolbox import SchemaToolbox 

8 

9 

10def test_get_data_schema_from_file__happy_path(): 

11 """ 

12 Ensure a schema is returned when a schema is found. 

13 """ 

14 

15 result = SchemaToolbox.get_data_schema_from_file("_Tests/schema-test-do-not-delete") 

16 expected_result = { 

17 "namespace": "Test-For-File-Grab", 

18 "type": "object", 

19 "name": "test", 

20 "country_code": "USA", 

21 "estimated_row_size": "10b", 

22 "estimated_row_count": 3000, 

23 "endpoints": [], 

24 "fields": [] 

25 } 

26 assert result == expected_result 

27 

28 

29def test_get_data_schema_from_file__not_found(): 

30 """ 

31 Ensure DataSchemaNotFound is raised if a schema is not found. 

32 """ 

33 

34 with pytest.raises(SchemaExceptions.DataSchemaNotFound) as exc_info: 

35 result = SchemaToolbox.get_data_schema_from_file("Test/this-schema-does-not-exist-and-never-will") 

36 

37 

38def test_get_endpoint_data_from_schema__happy_path(mocker): 

39 """ 

40 Given a tag that exists, ensure the right schema endpoint data is returned. 

41 """ 

42 

43 schema_mock = { 

44 "namespace": "Test", 

45 "type": "object", 

46 "name": "test", 

47 "country_code": "USA", 

48 "estimated_row_size": "10b", 

49 "estimated_row_count": 3000, 

50 "endpoints": [ 

51 { 

52 "type": "sink", 

53 "tag": "SDC_sink_0", 

54 "description": "This is SDC_sink_0" 

55 }, 

56 { 

57 "type": "sink", 

58 "tag": "SDC_sink_1", 

59 "description": "This is SDC_sink_1" 

60 } 

61 ], 

62 "fields": [] 

63 } 

64 

65 result = SchemaToolbox.get_endpoint_data_from_schema(schema_mock, "SDC_sink_0") 

66 

67 assert result["description"] == "This is SDC_sink_0" 

68 

69 

70def test_get_endpoint_data_from_schema__tag_does_not_exist(mocker): 

71 """ 

72 Given a tag that does not exist, ensure that DataSchemaEndpointTagNotFound is raised. 

73 """ 

74 

75 schema_mock = { 

76 "namespace": "Test", 

77 "type": "object", 

78 "name": "test", 

79 "country_code": "USA", 

80 "estimated_row_size": "10b", 

81 "estimated_row_count": 3000, 

82 "endpoints": [ 

83 { 

84 "type": "sink", 

85 "tag": "SDC_sink_0", 

86 "description": "This is SDC_sink_0" 

87 }, 

88 { 

89 "type": "sink", 

90 "tag": "SDC_sink_1", 

91 "description": "This is SDC_sink_1" 

92 } 

93 ], 

94 "fields": [] 

95 } 

96 

97 with pytest.raises(SchemaExceptions.DataSchemaEndpointTagNotFound): 

98 SchemaToolbox.get_endpoint_data_from_schema(schema_mock, "SDC_sink_100000")