def save_data(csvfile): """ initiate the save task for each chunk of the input csv file :param csvfile: an open csv file :return: None """ for chunk in csvfile.chunks(): reader = get_reader(chunk) save_chunk.delay(list(reader)) csvfile.close()
def test_save_chunk_valid_data(self, save_record_mock): data = [ ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '*****@*****.**'], ] call_list = [ call('*****@*****.**', data[0]), call('*****@*****.**', data[1]), call('*****@*****.**', data[2]), call('*****@*****.**', data[3]), ] save_chunk.delay(data) self.assertEqual(call_list, save_record_mock.delay.call_args_list)
def test_save_chunk_mixed_data(self, save_record_mock): data = [ ['1', '2', '3', '4'], ['1', '2', '3', '4'], ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '4'], ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '4'], ['1', '2', '3', '*****@*****.**'], ['1', '2', '3', '4'], ['1', '2', '3', '4'], ['1', '2', '3', '4'], ] call_list = [ call('*****@*****.**', data[2]), call('*****@*****.**', data[4]), call('*****@*****.**', data[6]) ] save_chunk.delay(data) self.assertEqual(call_list, save_record_mock.delay.call_args_list)
def test_save_chunk_with_no_emails(self, save_record_mock): save_chunk.delay(['test1', 'test2']) self.assertFalse(save_record_mock.delay.called)
def test_save_chunk_with_empty_data(self, save_record_mock): save_chunk.delay([]) self.assertFalse(save_record_mock.delay.called)