class ReaderBase(TestCase): result = None reader = None read_fixture = [ 'type, cash, price, bonus_ratio', '"white",15, 2, 3', '"milk", 12, 2, 5', '"dark", 13, 4, 1', '"white", 6, 2, 2', '"bozo", 3, 2, 1', ] expected_result = [['"white"', '15', ' 2', ' 3'], ['"milk"', ' 12', ' 2', ' 5'], ['"dark"', ' 13', ' 4', ' 1'], ['"white"', ' 6', ' 2', ' 2'], ['"bozo"', ' 3', ' 2', ' 1']] def setUp(self): self.reader = Reader("") @patch("utils.reader.Reader.read") def test_read_and_split(self, read): read.return_value = self.read_fixture self.assertEqual(self.reader.result(), self.expected_result) @patch("utils.reader.Reader.read") def test_split(self, read): read.return_value = ['Skip heading..\n', 'valid,data\n'] expected = [['valid', 'data']] self.assertEqual(self.reader.split(), expected)
def run_pipeline(self): customer_order = CustomerOrder() read = Reader(self._file) line_order = ValidateInput() self._line_item = [] for order in read.result(): line_order.set(order) if line_order.valid_types: customer_order.order_type = line_order.value[0] customer_order.cash = line_order.value[1] customer_order.price = line_order.value[2] customer_order.bonus_ratio = line_order.value[3] self._line_item.append(customer_order.final_order)