Exemplo n.º 1
0
    def test_create_product_alike(self, yesno):
        attribute_group = self.create_attribute_group()
        grid_attribute = self.create_grid_attribute(
            attribute_group=attribute_group, description=u'attr 1')
        grid_attribute2 = self.create_grid_attribute(
            attribute_group=attribute_group, description=u'attr 2')
        self.create_attribute_option(grid_attribute=grid_attribute,
                                     description=u'option for attr 1',
                                     order=1)
        self.create_attribute_option(grid_attribute=grid_attribute2,
                                     description=u'option for attr 2',
                                     order=2)

        cfop = self.create_cfop_data()
        pis_template = self.create_product_pis_template()
        cofins_template = self.create_product_cofins_template()
        grid_product = self.create_product(storable=True, is_grid=True)
        grid_product.sellable.default_sale_cfop = cfop
        grid_product.ncm = '12345678'
        grid_product.set_pis_template(pis_template)
        grid_product.set_cofins_template(cofins_template)
        grid_product.model = 'model'
        self.create_product_attribute(product=grid_product,
                                      attribute=grid_attribute)

        # We need the mocked yesno to return different values each time it
        # is called inside of run_wizard bellow
        values = [True, False]

        def fake_yes_no(*args, **kwargs):
            return values.pop(0)

        with contextlib.nested(
                mock.patch('stoq.lib.gui.wizards.productwizard.run_dialog'),
                mock.patch('stoq.lib.gui.wizards.productwizard.api.new_store'),
                mock.patch.object(self.store, 'commit'),
                mock.patch.object(self.store,
                                  'close')) as (run_dialog, new_store, commit,
                                                close):
            new_store.return_value = self.store
            run_dialog.return_value = grid_product
            yesno.side_effect = fake_yes_no
            ProductCreateWizard.run_wizard(None)
        # This is the second call to yesno()
        args, kwargs = run_dialog.call_args_list[1]
        template = kwargs['template']
        self.assertEqual(kwargs['product_type'], Product.TYPE_GRID)
        self.assertEqual(template, grid_product)
        self.assertEqual(template.ncm, grid_product.ncm)
        self.assertEqual(template._pis_template, grid_product._pis_template)
        self.assertEqual(template._cofins_template,
                         grid_product._cofins_template)
        self.assertEqual(template.sellable.default_sale_cfop,
                         grid_product.sellable.default_sale_cfop)
        self.assertEqual(template.ncm, '12345678')
        self.assertEqual(template.model, 'model')
        self.assertEqual(template._cofins_template, cofins_template)
        self.assertEqual(template._pis_template, pis_template)
        self.assertEqual(template.sellable.default_sale_cfop, cfop)
Exemplo n.º 2
0
    def test_create_inactive_group(self):
        inactive_group = self.create_attribute_group()
        inactive_group.is_active = False
        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)
        attribute_step = wizard.get_current_step()

        groups = attribute_step.slave.attribute_group
        for combo_model in groups.get_model_items():
            # The inactive group should not be shown on combo
            self.assertNotEqual(combo_model, inactive_group.description)
Exemplo n.º 3
0
    def test_create_inactive_attribute(self):
        attribute_group = self.create_attribute_group()
        attribute = self.create_grid_attribute(attribute_group=attribute_group)
        attribute.is_active = False

        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        attribute_step = wizard.get_current_step()
        attribute_step.slave.attribute_group.select_item_by_data(attribute_group)
        # Inactive attributes should not be shown
        self.assertEqual(attribute_step.slave._widgets, {})
Exemplo n.º 4
0
    def test_create_with_inactive_option(self):
        attribute_group = self.create_attribute_group()
        attribute = self.create_grid_attribute(attribute_group=attribute_group)
        option = self.create_attribute_option(grid_attribute=attribute)
        option.is_active = False

        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        attribute_step = wizard.get_current_step()
        attribute_step.slave.attribute_group.select_item_by_data(attribute_group)
        for check_box in attribute_step.slave._widgets.keys():
            self.assertEqual(check_box.get_sensitive(), False)
Exemplo n.º 5
0
    def test_create_with_attribute_not_selected(self, warning):
        attribute_group = self.create_attribute_group()
        self.create_grid_attribute(attribute_group=attribute_group)

        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        attribute_step = wizard.get_current_step()
        self.click(wizard.next_button)
        warning.reset_mock()
        # Selecting a group with a GridAttribute
        attribute_step.slave.attribute_group.select_item_by_data(attribute_group)
        self.click(wizard.next_button)
        warning.assert_called_once_with("You should select an attribute first")
Exemplo n.º 6
0
    def test_create_without_attribute(self, warning):
        attribute_group = self.create_attribute_group()

        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        attribute_step = wizard.get_current_step()
        self.click(wizard.next_button)
        # Testing without selecting a group
        warning.assert_called_once_with("You should select an attribute first")
        # Checking that we are in the same step after the warning
        self.assertEqual(wizard.get_current_step(), attribute_step)

        warning.reset_mock()
        # Selecting a group but it doesnt have a GridAttribute
        attribute_step.slave.attribute_group.select_item_by_data(attribute_group)
        self.click(wizard.next_button)
        warning.assert_called_once_with("You should select an attribute first")
Exemplo n.º 7
0
    def test_create_package_product(self, run_dialog):
        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.package.set_active(True)
        self.click(wizard.next_button)

        # ProductEditor step
        editor_step = wizard.get_current_step()
        # Checking that the slave is attached
        self.assertEqual(hasattr(editor_step.slave, 'package_slave'), True)

        # Package slave
        package_slave = editor_step.slave.get_slave('Pack content')
        self.assertNotSensitive(package_slave,
                                ['add_button', 'remove_button', 'edit_button'])

        package_slave.component_combo.select_item_by_position(0)
        selected = package_slave.component_combo.get_selected()
        temp = TemporaryProductComponent(package_slave.store,
                                         product=package_slave._product,
                                         component=selected,
                                         price=10)
        # After select a component add button will be sensitive
        self.assertSensitive(package_slave, ['add_button'])
        # And the other remain not sensitive
        self.assertNotSensitive(package_slave,
                                ['remove_button', 'edit_button'])
        run_dialog.return_value = temp
        self.click(package_slave.add_button)

        args, kwargs = run_dialog.call_args
        self.assertEqual(args[0], ProductPackageComponentEditor)
        self.assertTrue(isinstance(args[2], StoqlibStore))
        self.assertTrue(isinstance(args[3], TemporaryProductComponent))
        self.assertTrue(hasattr(args[3], 'product'))
        self.assertTrue(hasattr(args[3], 'component'))
        self.assertTrue(hasattr(args[3], 'quantity'))
        self.assertTrue(hasattr(args[3], 'design_reference'))
        self.assertTrue(hasattr(args[3], 'price'))
Exemplo n.º 8
0
    def test_create_with_attribute_without_option(self, warning):
        attribute_group = self.create_attribute_group()
        self.create_grid_attribute(attribute_group=attribute_group)

        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        attribute_step = wizard.get_current_step()
        self.click(wizard.next_button)
        warning.reset_mock()
        # Selecting a group with a GridAttribute
        attribute_step.slave.attribute_group.select_item_by_data(attribute_group)
        self.click(wizard.next_button)
        warning.assert_called_once_with("You should select an attribute first")

        warning.reset_mock()
        # At this point we dont have any attribute_option for grid_attribute
        for i in attribute_step.slave._widgets.keys():
            self.assertEqual(i.get_sensitive(), False)
        self.click(wizard.next_button)
        warning.assert_called_once_with("You should select an attribute first")
Exemplo n.º 9
0
    def test_create_grid_product(self, warning):
        attribute_group = self.create_attribute_group()
        grid_attribute = self.create_grid_attribute(
            attribute_group=attribute_group, description=u'attr 1')
        grid_attribute2 = self.create_grid_attribute(
            attribute_group=attribute_group, description=u'attr 2')
        self.create_attribute_option(grid_attribute=grid_attribute,
                                     description=u'option for attr 1',
                                     order=1)
        self.create_attribute_option(grid_attribute=grid_attribute2,
                                     description=u'option for attr 2',
                                     order=2)

        # Creating the wizard
        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.grid.set_active(True)
        self.click(wizard.next_button)

        # ProductAttributeEditorStep
        attribute_step = wizard.get_current_step()
        # Testing simulating combo selection change to cover everything
        attribute_step.slave.attribute_group.select(attribute_group)
        attribute_step.slave.attribute_group.select(None)
        # Selecting the attribute_group on the combo
        attribute_step.slave.attribute_group.select(attribute_group)
        # Set to active all grid_attributes for that group
        for attribute in attribute_step.slave._widgets.keys():
            self.assertEqual(attribute.get_sensitive(), True)
            attribute.set_active(True)
        self.click(wizard.next_button)

        # ProductEditorStep
        editor_step = wizard.get_current_step()
        # Getting ProductGridSlave
        grid_slave = editor_step.slave.get_slave('Grid')
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), False)

        # Trying add a child without description
        for combo in grid_slave._widgets.values():
            # Position 0 (zero) is empty
            combo.select_item_by_position(1)
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), True)
        self.click(grid_slave.add_product_button)
        warning.assert_called_once_with(
            'You should fill the description first')

        # Filling the description and try again
        editor_step.slave.description.update('grid test')
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), True)
        self.click(grid_slave.add_product_button)
        # Testing the sensitivity right after adding a child
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), False)

        # One combo not filled with an valid option
        combo = list(grid_slave._widgets.values())[0]
        # Position 0 (zero) is empty
        combo.select_item_by_position(0)
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), False)

        # Trying add a child with exactly the same attribute_option
        for combo in grid_slave._widgets.values():
            combo.select_item_by_position(1)
        self.assertEqual(grid_slave.add_product_button.get_sensitive(), False)
Exemplo n.º 10
0
 def _new_product(self):
     ProductCreateWizard.run_wizard(self)