Example #1
0
 def test_false_html(self):
     """``False`` HTML handled correctly."""
     with mute_logger(self.logger):
         self.assertEqual(self.text_from_html(False), "")
     with self.assertRaises(TypeError):
         with mute_logger(self.logger):
             self.text_from_html(False, fail=True)
Example #2
0
 def test_empty_html(self):
     """Empty HTML handled correctly."""
     with mute_logger(self.logger):
         self.assertEqual(self.text_from_html(""), "")
     with self.assertRaises(etree.XMLSyntaxError):
         with mute_logger(self.logger):
             self.text_from_html("", fail=True)
Example #3
0
    def test_empty_html(self):
        """Empty HTML handled correctly."""
        with mute_logger(self.logger):
            for laps, text in self.imgs_from_html(""):
                self.assertTrue(False)  # You should never get here

        with self.assertRaises(etree.XMLSyntaxError):
            with mute_logger(self.logger):
                list(self.imgs_from_html("", fail=True))
Example #4
0
    def test_bad_html(self):
        """Bad HTML handled correctly.
        Newer versions of lxml parse this as
        '<html><body><p>&lt;<bad/></p></body></html>'
        so the exception is not guaranteed and the result may vary. """
        with mute_logger(self.logger):
            self.assertIn(self.text_from_html("<<bad>"), ("<", ""))

        try:
            with mute_logger(self.logger):
                res = self.text_from_html("<<bad>", fail=True)
            self.assertEqual(res, "<")
        except etree.ParserError:
            pass
Example #5
0
    def test_bad_html(self):
        """Bad HTML handled correctly."""
        with mute_logger(self.logger):
            for laps, text in self.imgs_from_html("<<bad>"):
                self.assertTrue(False)  # You should never get here

        try:
            # Newer versions of lxml parse this as
            # '<html><body><p>&lt;<bad/></p></body></html>'
            # so the exception is not guaranteed
            with mute_logger(self.logger):
                images = list(self.imgs_from_html("<<bad>", fail=True))
            self.assertFalse(images)
        except etree.ParserError:
            pass
Example #6
0
    def test_unique_codes(self):
        product = self.env['product.product'].create({
            'name': 'bbc_sale_test_product',
            'type': 'consu',
            'default_code': '__test_unique_code',
            'ean13': '1122334455666',
        })
        product2 = product.copy()
        with self.assertRaisesRegexp(ValidationError, '__test_unique_code'):
            with mute_logger('openerp.models'):
                product2.write({'default_code': '__test_unique_code'})

        product3 = product.copy()
        with self.assertRaisesRegexp(ValidationError, '1122334455666'):
            with mute_logger('openerp.models'):
                product3.write({'ean13': '1122334455666'})
Example #7
0
    def test_false_html(self):
        """``False`` HTML handled correctly."""
        with mute_logger(self.logger):
            for laps, text in self.imgs_from_html(False):
                self.assertTrue(False)  # You should never get here

        with self.assertRaises(TypeError):
            list(self.imgs_from_html(False, fail=True))
Example #8
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self._set_field_groups(self.res_partner, "email", GROUP_SYSTEM)

        pid = self.res_partner.search(self.cr, self.demo_uid, [], limit=1)[0]
        part = self.res_partner.browse(self.cr, self.demo_uid, pid)
        # accessing fields must no raise exceptions...
        part.name
        # ... except if they are restricted
        with self.assertRaises(AccessError) as cm:
            with mute_logger("openerp.models"):
                part.email
Example #9
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self._set_field_groups(self.res_partner, 'email', GROUP_SYSTEM)

        pid = self.res_partner.search(self.cr, self.demo_uid, [], limit=1)[0]
        part = self.res_partner.browse(self.cr, self.demo_uid, pid)
        # accessing fields must no raise exceptions...
        part.name
        # ... except if they are restricted
        with self.assertRaises(AccessError) as cm:
            with mute_logger('openerp.models'):
                part.email
Example #10
0
 def test_dead_mans_switch_client(self):
     # test unconfigured case
     self.env['ir.config_parameter'].search([
         ('key', '=', 'dead_mans_switch_client.url')
     ]).unlink()
     with mute_logger('openerp.addons.dead_mans_switch_client.models'
                      '.dead_mans_switch_client'):
         self.env['dead.mans.switch.client'].alive()
     # test configured case
     self.env['ir.config_parameter'].set_param(
         'dead_mans_switch_client.url', 'fake_url')
     with self.assertRaises(ValueError):
         self.env['dead.mans.switch.client'].alive()
Example #11
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self._set_field_groups(self.res_partner, 'email', GROUP_TECHNICAL_FEATURES)

        pid = self.res_partner.search(self.cr, self.demo_uid, [], limit=1)[0]
        part = self.res_partner.browse(self.cr, self.demo_uid, pid)
        # accessing fields must no raise exceptions...
        part.name
        # ... except if they are restricted
        with self.assertRaises(openerp.osv.orm.except_orm) as cm:
            with mute_logger('openerp.models'):
                part.email

        self.assertEqual(cm.exception.args[0], 'AccessError')
Example #12
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self._set_field_groups(self.res_partner, 'email', GROUP_TECHNICAL_FEATURES)

        pid = self.res_partner.search(self.cr, self.demo_uid, [], limit=1)[0]
        part = self.res_partner.browse(self.cr, self.demo_uid, pid)
        # accessing fields must no raise exceptions...
        part.name
        # ... except if they are restricted
        with self.assertRaises(openerp.osv.orm.except_orm) as cm:
            with mute_logger('openerp.models'):
                part.email

        self.assertEqual(cm.exception.args[0], 'AccessError')
Example #13
0
 def test_smtp_error(self):
     with mock.patch(mock_send_email) as mock_func:
         mock_func.side_effect = Warning('Test error')
         with mute_logger('openerp.addons.mail.mail_mail'):
             self.mailing.send_mail()
         for stat in self.mailing.statistics_ids:
             if stat.mail_mail_id:
                 stat.mail_mail_id.send()
             tracking = self.env['mail.tracking.email'].search([
                 ('mail_id_int', '=', stat.mail_mail_id_int),
             ])
             self.assertEqual('error', tracking.state)
             self.assertEqual('Warning', tracking.error_type)
             self.assertEqual('Test error', tracking.error_description)
         self.assertTrue(self.contact_a.email_bounced)
Example #14
0
 def test_document_page_tags(self):
     testtag = self.env['document.page.tag'].name_create('test')
     # check we're charitable on duplicates
     self.assertEqual(
         testtag,
         self.env['document.page.tag'].name_create('Test'),
     )
     # check we can't create nonunique tags
     with self.assertRaises(IntegrityError):
         with mute_logger('odoo.sql_db'):
             testtag2 = self.env['document.page.tag'].create({
                 'name':
                 'test2',
             })
             testtag2.write({'name': 'test'})
Example #15
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self.res_partner._columns['email'].groups = GROUP_TECHNICAL_FEATURES
        try:
            P = self.res_partner
            pid = P.search(self.cr, self.demo_uid, [], limit=1)[0]
            part = P.browse(self.cr, self.demo_uid, pid)
            # accessing fields must no raise exceptions...
            part.name
            # ... except if they are restricted
            with self.assertRaises(openerp.osv.orm.except_orm) as cm:
                with mute_logger('openerp.osv.orm'):
                    part.email

            self.assertEqual(cm.exception.args[0], 'Access Denied')
        finally:
            self.res_partner._columns['email'].groups = False
Example #16
0
    def test_fields_browse_restriction(self):
        """Test access to records having restricted fields"""
        self.res_partner._columns['email'].groups = GROUP_TECHNICAL_FEATURES
        try:
            P = self.res_partner
            pid = P.search(self.cr, self.demo_uid, [], limit=1)[0]
            part = P.browse(self.cr, self.demo_uid, pid)
            # accessing fields must no raise exceptions...
            part.name
            # ... except if they are restricted
            with self.assertRaises(openerp.osv.orm.except_orm) as cm:
                with mute_logger('openerp.osv.orm'):
                    part.email

            self.assertEqual(cm.exception.args[0], 'Access Denied')
        finally:
            self.res_partner._columns['email'].groups = False
Example #17
0
    def test_database_cleanup(self):
        # create an orphaned column
        self.cr.execute(
            'alter table res_users add column database_cleanup_test int')
        purge_columns = self.env['cleanup.purge.wizard.column'].create({})
        purge_columns.purge_all()
        # must be removed by the wizard
        with self.assertRaises(ProgrammingError):
            with mute_logger('openerp.sql_db'):
                with self.registry.cursor() as cr:
                    cr.execute('select database_cleanup_test from res_users')

        # create a data entry pointing nowhere
        self.cr.execute('select max(id) + 1 from res_users')
        self.env['ir.model.data'].create({
            'module': 'database_cleanup',
            'name': 'test_no_data_entry',
            'model': 'res.users',
            'res_id': self.cr.fetchone()[0],
        })
        purge_data = self.env['cleanup.purge.wizard.data'].create({})
        purge_data.purge_all()
        # must be removed by the wizard
        with self.assertRaises(ValueError):
            self.env.ref('database_cleanup.test_no_data_entry')

        # create a nonexistent model
        self.env['ir.model'].create({
            'name': 'Database cleanup test model',
            'model': 'x_database.cleanup.test.model',
        })
        self.env.cr.execute(
            'insert into ir_attachment (name, res_model, res_id, type) values '
            "('test attachment', 'database.cleanup.test.model', 42, 'binary')")
        self.registry.models.pop('x_database.cleanup.test.model')
        self.registry._pure_function_fields.pop(
            'x_database.cleanup.test.model')
        purge_models = self.env['cleanup.purge.wizard.model'].create({})
        purge_models.purge_all()
        # must be removed by the wizard
        self.assertFalse(self.env['ir.model'].search([
            ('model', '=', 'x_database.cleanup.test.model'),
        ]))

        # create a nonexistent module
        self.env['ir.module.module'].create({
            'name': 'database_cleanup_test',
            'state': 'to upgrade',
        })
        purge_modules = self.env['cleanup.purge.wizard.module'].create({})
        # this reloads our registry, and we don't want to run tests twice
        # we also need the original registry for further tests, so save a
        # reference to it
        original_registry = RegistryManager.registries[self.env.cr.dbname]
        config.options['test_enable'] = False
        purge_modules.purge_all()
        config.options['test_enable'] = True
        # must be removed by the wizard
        self.assertFalse(self.env['ir.module.module'].search([
            ('name', '=', 'database_cleanup_test'),
        ]))
        # reset afterwards
        RegistryManager.registries[self.env.cr.dbname] = original_registry

        # create an orphaned table
        self.env.cr.execute('create table database_cleanup_test (test int)')
        purge_tables = self.env['cleanup.purge.wizard.table'].create({})
        self.assertIn('database_cleanup_test',
                      purge_tables.purge_line_ids.mapped('name'))
        purge_tables.purge_line_ids.filtered(
            lambda x: x.name == 'database_cleanup_test').purge()
        with self.assertRaises(ProgrammingError):
            with mute_logger('openerp.sql_db'):
                with self.registry.cursor() as cr:
                    self.env.cr.execute('select * from database_cleanup_test')