class TestReceiveQuoteWizard(GUITest):
    def _check_start_step(self, uitest=''):
        if uitest:
            self.check_wizard(self.wizard, uitest)
        self.click(self.wizard.next_button)

    @mock.patch('stoqlib.gui.wizards.purchasequotewizard.run_dialog')
    @mock.patch('stoqlib.gui.wizards.purchasequotewizard.yesno')
    def testCreate(self, yesno, run_dialog):
        # Allow creating purchases in the past.
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS",
                                              u"1")

        quotation = self.create_quotation()
        quotation.identifier = 12345
        quotation.group.identifier = 67890

        def _purchase_clone():
            self.purchase_clone = Domain.clone(self.purchase)
            return self.purchase_clone

        purchase = self.purchase = quotation.purchase
        purchase.clone = _purchase_clone
        purchase.open_date = localdate(2012, 1, 1).date()
        self.create_purchase_order_item(purchase)

        self.wizard = ReceiveQuoteWizard(self.store)
        start_step = self.wizard.get_current_step()
        start_step.search.refresh()
        start_step.search.results.select(start_step.search.results[0])
        self._check_start_step('wizard-receivequote-start-step')
        self._check_start_step('wizard-receivequote-item-step')

        item_step = self.wizard.get_current_step()
        new_store = 'stoqlib.gui.wizards.purchasequotewizard.api.new_store'
        with mock.patch(new_store) as new_store:
            with mock.patch.object(self.store, 'commit'):
                with mock.patch.object(self.store, 'close'):
                    new_store.return_value = self.store
                    self.click(item_step.create_order_button)
                    run_dialog.assert_called_once_with(PurchaseWizard,
                                                       self.wizard, self.store,
                                                       self.purchase_clone)
                    yesno.assert_called_once_with(
                        'Should we close the quotes used to compose the '
                        'purchase order ?', gtk.RESPONSE_NO, 'Close quotes',
                        "Don't close")

        self.click(self.wizard.next_button)

        models = [quotation, quotation.group, purchase]
        models.extend(purchase.get_items())
        self.check_wizard(self.wizard,
                          'wizard-receivequote-finish-step',
                          models=models)
class TestReceiveQuoteWizard(GUITest):
    def _check_start_step(self, uitest=''):
        if uitest:
            self.check_wizard(self.wizard, uitest)
        self.click(self.wizard.next_button)

    @mock.patch('stoqlib.gui.wizards.purchasequotewizard.run_dialog')
    @mock.patch('stoqlib.gui.wizards.purchasequotewizard.yesno')
    def test_create(self, yesno, run_dialog):
        # Allow creating purchases in the past.
        sysparam.set_bool(self.store, 'ALLOW_OUTDATED_OPERATIONS', True)

        quotation = self.create_quotation()
        quotation.identifier = 12345
        quotation.group.identifier = 67890

        def _purchase_clone():
            self.purchase_clone = Domain.clone(self.purchase)
            return self.purchase_clone

        purchase = self.purchase = quotation.purchase
        purchase.clone = _purchase_clone
        purchase.open_date = localdate(2012, 1, 1).date()
        self.create_purchase_order_item(purchase)

        self.wizard = ReceiveQuoteWizard(self.store)
        start_step = self.wizard.get_current_step()
        start_step.search.refresh()
        start_step.search.results.select(start_step.search.results[0])
        self._check_start_step('wizard-receivequote-start-step')
        self._check_start_step('wizard-receivequote-item-step')

        item_step = self.wizard.get_current_step()
        new_store = 'stoqlib.gui.wizards.purchasequotewizard.api.new_store'
        with mock.patch(new_store) as new_store:
            with mock.patch.object(self.store, 'commit'):
                with mock.patch.object(self.store, 'close'):
                    new_store.return_value = self.store
                    self.click(item_step.create_order_button)
                    run_dialog.assert_called_once_with(PurchaseWizard,
                                                       self.wizard,
                                                       self.store,
                                                       self.purchase_clone)
                    yesno.assert_called_once_with(
                        'Should we close the quotes used to compose the '
                        'purchase order ?', gtk.RESPONSE_NO, 'Close quotes',
                        "Don't close")

        self.click(self.wizard.next_button)

        models = [quotation, quotation.group, purchase]
        models.extend(purchase.get_items())
        self.check_wizard(self.wizard, 'wizard-receivequote-finish-step',
                          models=models)
class TestReceiveQuoteWizard(GUITest):
    def _check_start_step(self, uitest=""):
        if uitest:
            self.check_wizard(self.wizard, uitest)
        self.click(self.wizard.next_button)

    @mock.patch("stoqlib.gui.wizards.purchasequotewizard.run_dialog")
    @mock.patch("stoqlib.gui.wizards.purchasequotewizard.yesno")
    def testCreate(self, yesno, run_dialog):
        # Allow creating purchases in the past.
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS", u"1")

        quotation = self.create_quotation()
        quotation.identifier = 12345
        quotation.group.identifier = 67890

        def _purchase_clone():
            self.purchase_clone = Domain.clone(self.purchase)
            return self.purchase_clone

        purchase = self.purchase = quotation.purchase
        purchase.clone = _purchase_clone
        purchase.open_date = datetime.date(2012, 1, 1)
        self.create_purchase_order_item(purchase)

        self.wizard = ReceiveQuoteWizard(self.store)
        start_step = self.wizard.get_current_step()
        start_step.search.refresh()
        start_step.search.results.select(start_step.search.results[0])
        self._check_start_step("wizard-receivequote-start-step")
        self._check_start_step("wizard-receivequote-item-step")

        item_step = self.wizard.get_current_step()
        new_store = "stoqlib.gui.wizards.purchasequotewizard.api.new_store"
        with mock.patch(new_store) as new_store:
            with mock.patch.object(self.store, "commit"):
                with mock.patch.object(self.store, "close"):
                    new_store.return_value = self.store
                    self.click(item_step.create_order_button)
                    run_dialog.assert_called_once_with(PurchaseWizard, self.wizard, self.store, self.purchase_clone)
                    yesno.assert_called_once_with(
                        "Should we close the quotes used to compose the " "purchase order ?",
                        gtk.RESPONSE_NO,
                        "Close quotes",
                        "Don't close",
                    )

        self.click(self.wizard.next_button)

        models = [quotation, quotation.group, purchase]
        models.extend(purchase.get_items())
        self.check_wizard(self.wizard, "wizard-receivequote-finish-step", models=models)