@@ -39,6 +39,8 @@ def load_csv_impl(path, *args):
3939 yield make_row ('b1' )
4040 yield None
4141 yield make_row ('b3' )
42+ elif path == 'path/d.csv' :
43+ yield make_row ('d1' )
4244 else :
4345 # fail the test for any other path
4446 raise Exception ('unexpected path' )
@@ -47,10 +49,14 @@ def load_csv_impl(path, *args):
4749 mock_database = MagicMock ()
4850 mock_csv_importer = MagicMock ()
4951 mock_csv_importer .find_csv_files .return_value = [
52+ # a good file
5053 ('path/a.csv' , ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 20200420 , 1 )),
54+ # a file with a data error
5155 ('path/b.csv' , ('src_b' , 'sig_b' , 'week' , 'msa' , 202016 , 202017 , 1 )),
5256 # emulate a file that's named incorrectly
5357 ('path/c.csv' , None ),
58+ # another good file
59+ ('path/d.csv' , ('src_d' , 'sig_d' , 'week' , 'msa' , 202016 , 202017 , 1 )),
5460 ]
5561 mock_csv_importer .load_csv = load_csv_impl
5662 mock_file_archiver = MagicMock ()
@@ -61,27 +67,29 @@ def load_csv_impl(path, *args):
6167 csv_importer_impl = mock_csv_importer ,
6268 file_archiver_impl = mock_file_archiver )
6369
64- # verify that five rows were added to the database
65- self .assertEqual (mock_database .insert_or_update .call_count , 5 )
66- call_args_list = mock_database .insert_or_update .call_args_list
67- actual_args = [args for (args , kwargs ) in call_args_list ]
70+ # verify that appropriate rows were added to the database
71+ self .assertEqual (mock_database .insert_or_update_bulk .call_count , 2 )
72+ call_args_list = mock_database .insert_or_update_bulk .call_args_list
73+ actual_args = [[(a .source , a .signal , a .time_type , a .geo_type , a .time_value ,
74+ a .geo_value , a .value , a .stderr , a .sample_size , a .issue , a .lag )
75+ for a in call .args [0 ]] for call in call_args_list ]
6876 expected_args = [
69- ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a1' , 'a1' , 'a1' , 'a1' , 20200420 , 1 ),
70- ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a2' , 'a2' , 'a2' , 'a2' , 20200420 , 1 ),
71- ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a3' , 'a3' , 'a3' , 'a3' , 20200420 , 1 ),
72- ('src_b' , 'sig_b' , 'week' , 'msa' , 202016 , 'b1' , 'b1' , 'b1' , 'b1' , 202017 , 1 ),
73- ('src_b' , 'sig_b' , 'week' , 'msa' , 202016 , 'b3' , 'b3' , 'b3' , 'b3' , 202017 , 1 ),
77+ [('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a1' , 'a1' , 'a1' , 'a1' , 20200420 , 1 ),
78+ ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a2' , 'a2' , 'a2' , 'a2' , 20200420 , 1 ),
79+ ('src_a' , 'sig_a' , 'day' , 'hrr' , 20200419 , 'a3' , 'a3' , 'a3' , 'a3' , 20200420 , 1 )],
80+ [('src_d' , 'sig_d' , 'week' , 'msa' , 202016 , 'd1' , 'd1' , 'd1' , 'd1' , 202017 , 1 )]
7481 ]
7582 self .assertEqual (actual_args , expected_args )
7683
77- # verify that one file was successful (a) and two failed (b, c)
78- self .assertEqual (mock_file_archiver .archive_file .call_count , 3 )
84+ # verify that two files were successful (a, d ) and two failed (b, c)
85+ self .assertEqual (mock_file_archiver .archive_file .call_count , 4 )
7986 call_args_list = mock_file_archiver .archive_file .call_args_list
8087 actual_args = [args for (args , kwargs ) in call_args_list ]
8188 expected_args = [
8289 ('path' , 'data_dir/archive/successful/src_a' , 'a.csv' , True ),
8390 ('path' , 'data_dir/archive/failed/src_b' , 'b.csv' , False ),
8491 ('path' , 'data_dir/archive/failed/unknown' , 'c.csv' , False ),
92+ ('path' , 'data_dir/archive/successful/src_d' , 'd.csv' , True ),
8593 ]
8694 self .assertEqual (actual_args , expected_args )
8795
@@ -133,7 +141,7 @@ def test_database_exception_is_handled(self):
133141
134142 data_dir = 'data_dir'
135143 mock_database = MagicMock ()
136- mock_database .insert_or_update .side_effect = Exception ('testing' )
144+ mock_database .insert_or_update_bulk .side_effect = Exception ('testing' )
137145 mock_csv_importer = MagicMock ()
138146 mock_csv_importer .find_csv_files .return_value = [
139147 ('path/file.csv' , ('src' , 'sig' , 'day' , 'hrr' , 20200423 , 20200424 , 1 )),
@@ -149,8 +157,8 @@ def test_database_exception_is_handled(self):
149157 csv_importer_impl = mock_csv_importer ,
150158 file_archiver_impl = mock_file_archiver )
151159
152- # verify that a row insertion was attempted
153- self .assertTrue (mock_database .insert_or_update .called )
160+ # verify that insertions were attempted
161+ self .assertTrue (mock_database .insert_or_update_bulk .called )
154162
155163 # verify that the file was archived as having failed
156164 self .assertTrue (mock_file_archiver .archive_file .called )
0 commit comments