def setUp(self):
        self.submit_buttons = SubmitButtons()
        self.test_code_plu = Code(
            Product(code="123", name="None", quantity_type="szt"))

        self.test_code_waga = Code(
            Product(code="123", name="None", quantity_type="kg"))
Exemple #2
0
    def make_result(self, number):
        """

        :param number:
        :type number: int
        :return: tuple
        """
        passed = True
        picked_code = Code(Product(
            code=str(number),
            name="Prod " + str(number),
            quantity_type="kg"))

        if number % 2 == 1:
            number = 100 - number
            passed = False

        entered_code = Code(Product(
            code=str(number),
            name="Prod " + str(number),
            quantity_type="kg"))

        return (
            picked_code,
            entered_code,
            passed
        )
Exemple #3
0
    def show_product(self, event=None, code=None):
        self.picked_code = code
        self.picked_code.reset()

        self.entered_code = Code()

        self.submit_buttons.reset_buttons()

        self.product_code.show_code(None, self.entered_code)
        self.product_name.show_code(None, self.picked_code)
        self.screen_keyboard.show_new_code(self.picked_code)
Exemple #4
0
    def test_get_first_number(self):
        code = Code(self.test_product_2)
        self.assertEqual(code.highlight_number, "2")

        number = code.get_first_number()
        self.assertEqual(number, "3")

        number = code.get_first_number()
        self.assertEqual(number, "4")

        number = code.get_first_number()
        self.assertEqual(number, None)
Exemple #5
0
    def test_code(self):
        for product in [self.test_product_1, self.test_product_2]:
            code = Code(product)

            self.assertEqual(product.code, code.code)
            self.assertEqual(product.name, code.name)
            self.assertEqual(product.quantity_type, code.quantity)
Exemple #6
0
    def test_reset(self):
        code = Code(self.test_product_1)
        self.assertEqual(code.highlight_number, "1")

        code.get_next_number()
        self.assertEqual(code.highlight_number, "2")

        code.reset()
        code.get_next_number()
        self.assertEqual(code.highlight_number, "2")
Exemple #7
0
    def test_add_number(self):
        code = Code(EmptyProduct())
        code.code = "123"

        self.assertEqual(code.code, "123")

        code.add_number("4")
        self.assertEqual(code.code, "1234")

        code.add_number(5)
        self.assertEqual(code.code, "12345")

        code.add_number("")
        self.assertEqual(code.code, "12345")
    def test_reset_buttons(self):
        screen_keyboard = ScreenKeyboard()
        screen_keyboard.show_new_code(Code(self.test_product_1))

        button = screen_keyboard.highlighted_button()
        self.assertEqual(button.text, "1")

        screen_keyboard.reset_buttons()
        self.assertFalse(button.is_highlighted())
    def test_show_new_code(self):
        screen_keyboard = ScreenKeyboard()
        screen_keyboard.show_new_code(Code(self.test_product_1))

        button = screen_keyboard.highlighted_button()
        self.assertEqual(button.text, "1")

        screen_keyboard.highlight_next_button()
        button = screen_keyboard.highlighted_button()
        self.assertEqual(button.text, "2")
    def setUp(self):
        self.test_product = Product(
            code="1",
            name="Test Product",
            quantity_type="szt"
        )
        self.test_product2 = Product(
            code="123",
            name="Test Product",
            quantity_type="szt"
        )
        self.test_product3 = Product(
            code="3",
            name="Test Product",
            quantity_type="szt"
        )
        self.test_code = Code(self.test_product)
        self.test_code2 = Code(self.test_product2)
        self.test_code3 = Code(self.test_product3)

        self.cm = CodeManager()
        self.cm.pick_product = Mock(return_value=self.test_code)

        self.product_name = ProductName()
        self.product_code = ProductCode()
        self.screen_keyboard = ScreenKeyboard()
        self.submit_buttons = SubmitButtons()

        self.learn = LearningWorkflow(
            cm = self.cm,
            product_code=self.product_code,
            product_name=self.product_name,
            screen_keyboard=self.screen_keyboard,
            submit_buttons=self.submit_buttons
        )

        pass
Exemple #11
0
    def __init__(self, cm, product_name, product_code, screen_keyboard,
                 submit_buttons):
        """  This is a class that will be responsible for test workflow.
            Order of functions is top-bottom, that's alse the order of the workflow.

        :param cm:
        :type cm: CodeManager

        :param product_name:
        :type product_name: ProductName

        :param product_code:
        :type product_code: ProductCode

        :param screen_keyboard:
        :type screen_keyboard: ScreenKeyboard

        :param submit_buttons:
        :type submit_buttons: SubmitButtons
        """

        self.cm = cm
        self.product_name = product_name
        self.product_code = product_code
        self.screen_keyboard = screen_keyboard
        self.submit_buttons = submit_buttons

        self.picked_code = None
        self.entered_code = Code()

        event_dispatcher.bind(on_pick_a_product=self.pick_a_product)
        event_dispatcher.bind(on_show_product=self.show_product)
        event_dispatcher.bind(
            on_handle_user_enter_number=self.handle_user_enter_number)
        event_dispatcher.bind(on_show_next_number=self.show_next_number)
        event_dispatcher.bind(
            on_handle_user_submit_code=self.handle_user_submit_code)
Exemple #12
0
    def test_equals(self):
        code1 = Code(self.test_product_1)
        code2 = Code(self.test_product_2)

        self.assertFalse(code1 == code2)

        code1.code = "123"
        code2.code = "123"

        self.assertTrue(code1 == code2)
Exemple #13
0
 def pick_product(self):
     self.product = self.products.pick_random()
     self.code = Code(self.product)
     kodlog.info("I picked product: " + self.code.name)
     return self.code
Exemple #14
0
class LearningWorkflow(Workflow):
    def __init__(self, cm, product_name, product_code, screen_keyboard,
                 submit_buttons):
        """  This is a class that will be responsible for test workflow.
            Order of functions is top-bottom, that's alse the order of the workflow.

        :param cm:
        :type cm: CodeManager

        :param product_name:
        :type product_name: ProductName

        :param product_code:
        :type product_code: ProductCode

        :param screen_keyboard:
        :type screen_keyboard: ScreenKeyboard

        :param submit_buttons:
        :type submit_buttons: SubmitButtons
        """

        self.cm = cm
        self.product_name = product_name
        self.product_code = product_code
        self.screen_keyboard = screen_keyboard
        self.submit_buttons = submit_buttons

        self.picked_code = None
        self.entered_code = Code()

        event_dispatcher.bind(on_pick_a_product=self.pick_a_product)
        event_dispatcher.bind(on_show_product=self.show_product)
        event_dispatcher.bind(
            on_handle_user_enter_number=self.handle_user_enter_number)
        event_dispatcher.bind(on_show_next_number=self.show_next_number)
        event_dispatcher.bind(
            on_handle_user_submit_code=self.handle_user_submit_code)

    def pick_a_product(self, event=None):
        self.picked_code = self.cm.pick_product()
        event_dispatcher.do_show_product(self.picked_code)

    def show_product(self, event=None, code=None):
        self.picked_code = code
        self.picked_code.reset()

        self.entered_code = Code()

        self.submit_buttons.reset_buttons()

        self.product_code.show_code(None, self.entered_code)
        self.product_name.show_code(None, self.picked_code)
        self.screen_keyboard.show_new_code(self.picked_code)

    def handle_user_enter_number(self, event, number):
        if self.screen_keyboard.highlighted_button().text == number:
            self.entered_code.add_number(number)
            self.product_code.show_code(None, self.entered_code)

            if self._codes_equal():
                self.screen_keyboard.reset_buttons()
                self.submit_buttons.highlight_submit_button(self.picked_code)
            else:
                event_dispatcher.do_show_next_number(self.entered_code)
        else:
            event_dispatcher.do_show_product(self.screen_keyboard.code)

    def show_next_number(self, event, code):
        self.screen_keyboard.highlight_next_button()

    def handle_user_submit_code(
        self,
        event,
        quantity,
    ):
        if self._codes_equal() and self.picked_code.has_quantity(quantity):
            event_dispatcher.do_pick_a_product()
        else:
            event_dispatcher.do_show_product(self.picked_code)

    def _codes_equal(self):
        return self.entered_code == self.picked_code
Exemple #15
0
    def test_has_quantity(self):
        code = Code(self.test_product_1)

        self.assertTrue(code.has_quantity("szt"))
        self.assertFalse(code.has_quantity("kg"))

        code = Code(self.test_product_2)
        self.assertTrue(code.has_quantity("kg"))
        self.assertFalse(code.has_quantity("szt"))

        code = Code(EmptyProduct())
        self.assertTrue(code.has_quantity("szt"))
        self.assertFalse(code.has_quantity("kg"))