def test_transform_model_value(self): """Test that values are transformed by the correct filter before writing""" transforms = { 'test1': lambda x: x * 2, 'test2': lambda x: x * 4 } writer = RecordModelWriter(self.csv_columns, {}, transforms) self.assertEqual(writer.transform_model_value(2, 'test1'), 2 * 2) self.assertEqual(writer.transform_model_value(2, 'test2'), 2 * 4)
def test_get_model_value_for_column(self): """Test that values are pulled from the correct model fields""" writer = RecordModelWriter(self.csv_columns, {'test1': 'other1'}, {}) record = mock.MagicMock(test1=1, other1=2) self.assertEqual(writer.get_model_value_for_column(record, 'other1'), 2)
def test_write_header(self): """Test that the header written to a file""" writer = RecordModelWriter(self.csv_columns, {}, {}) writer.write_header(self.outfile) self.assertEqual(self.outfile.getvalue(), 'test1,test2\r\n')
def test_write_record(self): """Test that writer outputs to a file""" writer = RecordModelWriter(self.csv_columns, {}, {}) record = mock.MagicMock(test1=1, test2=2, no_out=3) writer.write_record(record, self.outfile) self.assertEqual(self.outfile.getvalue(), '1,2\r\n')
def test_transform_model_value(self): """Test that values are transformed by the correct filter before writing""" transforms = {'test1': lambda x: x * 2, 'test2': lambda x: x * 4} writer = RecordModelWriter(self.csv_columns, {}, transforms) self.assertEqual(writer.transform_model_value(2, 'test1'), 2 * 2) self.assertEqual(writer.transform_model_value(2, 'test2'), 2 * 4)