Example #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)

        grid_product = self.create_product(storable=True, is_grid=True)
        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("stoqlib.gui.wizards.productwizard.run_dialog"),
            mock.patch("stoqlib.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]
        self.assertEquals(kwargs["product_type"], Product.TYPE_GRID)
        self.assertEquals(kwargs["template"], grid_product)
Example #2
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('stoqlib.gui.wizards.productwizard.run_dialog'),
                mock.patch('stoqlib.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)
Example #3
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.pis_template = pis_template
        grid_product.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('stoqlib.gui.wizards.productwizard.run_dialog'),
                mock.patch('stoqlib.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)
Example #4
0
 def _new_product(self):
     ProductCreateWizard.run_wizard(self)