feat: Se implementa patron Factory
This commit is contained in:
@@ -18,7 +18,7 @@ def test_print_bill():
|
||||
json.dumps(
|
||||
load_json('test/fixtures/bill.json')
|
||||
)),
|
||||
"ip_printer": "192.168.1.105",
|
||||
"ip_printer": "",
|
||||
"user_name": "Juan"
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_print_customer_order():
|
||||
json.dumps(
|
||||
load_json('test/fixtures/customer_order.json')
|
||||
)),
|
||||
"ip_printer": "192.168.1.100",
|
||||
"ip_printer": "",
|
||||
"user_name": "Juan"
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ def test_print_customer_order_deleted_lines():
|
||||
load_json(
|
||||
'test/fixtures/customer_order_deleted_lines.json')
|
||||
)),
|
||||
"ip_printer": "192.168.1.110",
|
||||
"ip_printer": "",
|
||||
"user_name": "Juan"
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ def test_print_bar_order():
|
||||
json.dumps(
|
||||
load_json('test/fixtures/customer_order.json')
|
||||
)),
|
||||
"ip_printer": "192.168.1.110",
|
||||
"ip_printer": "",
|
||||
"user_name": "Juan"
|
||||
}
|
||||
|
||||
|
||||
41
Api/test/test_printerfactory.py
Normal file
41
Api/test/test_printerfactory.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from escpos.printer import Dummy
|
||||
from ..printer_factory import PrinterFactory
|
||||
|
||||
|
||||
class TestPrinterFactory(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.factory_dummy = PrinterFactory(type_="dummy")
|
||||
self.factory_network = PrinterFactory(
|
||||
type_="network", host="192.168.1.100")
|
||||
|
||||
def test_create_dummy_printer(self):
|
||||
"""Test creación de impresora dummy"""
|
||||
|
||||
printer = self.factory_dummy._get_printer()
|
||||
self.assertIsInstance(printer, Dummy)
|
||||
|
||||
@patch('Api.printer_factory.Network')
|
||||
def test_create_network_printer(self, mock_network):
|
||||
"""Test creación de impresora de red con mock"""
|
||||
|
||||
mock_printer_instance = MagicMock()
|
||||
mock_network.return_value = mock_printer_instance
|
||||
|
||||
printer = self.factory_network._get_printer()
|
||||
|
||||
mock_network.assert_called_once_with("192.168.1.100", 9100)
|
||||
|
||||
self.assertEqual(printer, mock_printer_instance)
|
||||
|
||||
def test_create_unknown_printer_type(self):
|
||||
"""Test para tipo de impresora desconocido"""
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
PrinterFactory(type_="invalid_type")._get_printer()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user