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

1import json 

2import os 

3import pytest 

4import sys 

5from sdc_etl_libs.sdc_data_schema.schema_toolbox import SchemaToolbox 

6from sdc_etl_libs.sdc_file_helpers.SDCFileNameHelpers import SDCFileNameHelpers 

7 

8data_schema_1 = json.loads(open(os.path.dirname(os.path.abspath(__file__)) + "/test_schema_dynamic_file_1.json").read()) 

9ep_schema_1 = SchemaToolbox.get_endpoint_data_from_schema(data_schema_1, "test_sink_0", validate_=True) 

10ep_schema_2 = SchemaToolbox.get_endpoint_data_from_schema(data_schema_1, "test_sink_1", validate_=True) 

11 

12 

13def test_get_dynamic_filename_with_expected_params(): 

14 """ 

15 Ensure calling get_file_name_from_schema with expected parameters works properly 

16 """ 

17 

18 kwargs = {"file_name_params": {"START_DATE": "2020-01-01", "END_DATE": "2020-01-08"}} 

19 assert SDCFileNameHelpers.get_file_name_from_schema( 

20 ep_schema_1, kwargs=kwargs) == "outfile_2020-01-01_2020-01-08.csv" 

21 

22 

23def test_get_dynamic_filename_with_no_file_name_params(): 

24 """ 

25 Ensure calling get_file_name_from_schema with no file_name_params when file_name_params 

26 are expected results in an exception 

27 """ 

28 

29 with pytest.raises(Exception) as e: 

30 assert SDCFileNameHelpers.get_file_name_from_schema(ep_schema_1) 

31 assert str(e.value) == "Required parameters are missing" 

32 

33 

34def test_get_static_filename_with_unexpected_params(): 

35 """ 

36 Ensure calling get_file_name_from_schema with file_name_params when no file_name_params 

37 are expected results in an error. 

38 """ 

39 

40 kwargs = {"file_name_params": {"START_DATE": "2020-01-01"}} 

41 with pytest.raises(Exception) as e: 

42 assert SDCFileNameHelpers.get_file_name_from_schema(ep_schema_2, kwargs=kwargs) 

43 assert str(e.value) == 'Passed parameter "START_DATE" not expected by schema' 

44 

45 

46def test_get_static_filename_with_no_file_name_params(): 

47 """ 

48 Ensure calling get_file_name_from_schema with no file_name_params when no file_name_params 

49 are expected works properly. 

50 """ 

51 

52 assert SDCFileNameHelpers.get_file_name_from_schema(ep_schema_2) == "outfile.csv"