Пример #1
0
    def test_sms_schedule(self):
        self._create_registrations(self.event_0, 3)

        # check subscription scheduler
        schedulers = self.env['event.mail'].search([
            ('event_id', '=', self.event_0.id),
            ('interval_type', '=', 'after_sub')
        ])
        self.assertEqual(len(schedulers), 1)
        self.assertEqual(
            schedulers.scheduled_date, self.event_0.create_date,
            'event: incorrect scheduled date for checking controller')

        # verify that subscription scheduler was auto-executed after each registration
        self.assertEqual(len(schedulers.mail_registration_ids), 3)
        self.assertTrue(
            all(m.mail_sent is True for m in schedulers.mail_registration_ids))
        self.assertEqual(
            schedulers.mapped('mail_registration_ids.registration_id'),
            self.event_0.registration_ids)
        sanitized_numbers = []
        for registration in self.event_0.registration_ids:
            reg_sanitized_number = phone_validation.phone_format(
                registration.phone, 'BE', '32', force_format='E164')
            sanitized_numbers.append(reg_sanitized_number)
            self.assertSMSOutgoing(
                self.env['res.partner'], reg_sanitized_number,
                '%s registration confirmation.' %
                self.event_0.organizer_id.name)

        # clear notification queue to avoid conflicts when checking next notifications
        self.env['mail.notification'].search([('sms_number', 'in',
                                               sanitized_numbers)]).unlink()
        self.env['sms.sms'].search([('number', 'in', sanitized_numbers)
                                    ]).unlink()

        # check before event scheduler
        schedulers = self.env['event.mail'].search([
            ('event_id', '=', self.event_0.id),
            ('interval_type', '=', 'before_event')
        ])
        self.assertEqual(len(schedulers), 1, 'event: wrong scheduler creation')
        self.assertEqual(schedulers[0].scheduled_date,
                         self.event_0.date_begin + relativedelta(days=-3))

        # execute event reminder scheduler explicitly
        schedulers.execute()

        # verify that subscription scheduler was auto-executed after each registration
        for registration in self.event_0.registration_ids:
            reg_sanitized_number = phone_validation.phone_format(
                registration.phone, 'BE', '32', force_format='E164')
            self.assertSMSOutgoing(
                self.env['res.partner'], reg_sanitized_number,
                '%s reminder' % self.event_0.organizer_id.name)
Пример #2
0
    def setUpClass(cls):
        super(TestMassSMS, cls).setUpClass()
        cls._test_body = 'Mass SMS in your face'

        records = cls.env['mail.test.sms']
        partners = cls.env['res.partner']
        country_be_id = cls.env.ref('base.be').id,
        country_us_id = cls.env.ref('base.us').id,

        for x in range(10):
            partners += cls.env['res.partner'].with_context(**cls._test_context).create({
                'name': 'Partner_%s' % (x),
                'email': '*****@*****.**' % (x),
                'country_id': country_be_id,
                'mobile': '045600%s%s99' % (x, x)
            })
            records += cls.env['mail.test.sms'].with_context(**cls._test_context).create({
                'name': 'MassSMSTest_%s' % (x),
                'customer_id': partners[x].id,
                'phone_nbr': '045600%s%s44' % (x, x)
            })
        cls.records = cls._reset_mail_context(records)
        cls.records_numbers = [phone_validation.phone_format(r.phone_nbr, 'BE', '32', force_format='E164') for r in cls.records]
        cls.partners = partners

        cls.sms_template = cls.env['sms.template'].create({
            'name': 'Test Template',
            'model_id': cls.env['ir.model']._get('mail.test.sms').id,
            'body': 'Dear ${object.display_name} this is a mass SMS.',
        })

        cls.partner_numbers = [
            phone_validation.phone_format(partner.mobile, partner.country_id.code, partner.country_id.phone_code, force_format='E164')
            for partner in partners
        ]

        cls.mailing = cls.env['mailing.mailing'].with_user(cls.user_marketing).create({
            'name': 'Xmas Spam',
            'subject': 'Xmas Spam',
            'mailing_model_id': cls.env['ir.model']._get('mail.test.sms').id,
            'mailing_type': 'sms',
            'mailing_domain': '%s' % repr([('name', 'ilike', 'MassSMSTest')]),
            'sms_template_id': cls.sms_template.id,
            'sms_allow_unsubscribe': False,
        })
Пример #3
0
 def setUpClass(cls):
     super(TestRecipients, cls).setUpClass()
     cls.partner_numbers = [
         phone_validation.phone_format(partner.mobile,
                                       partner.country_id.code,
                                       partner.country_id.phone_code,
                                       force_format='E164')
         for partner in (cls.partner_1 | cls.partner_2)
     ]
Пример #4
0
 def phone_format(self, number, country=None, company=None):
     country = country or self._phone_get_country()
     if not country:
         return number
     return phone_validation.phone_format(
         number,
         country.code if country else None,
         country.phone_code if country else None,
         force_format='INTERNATIONAL',
         raise_exception=False)
Пример #5
0
    def setUpClass(cls):
        super(BaseFunctionalTest, cls).setUpClass()
        cls.user_employee.write({'login': '******'})

        # update country to belgium in order to test sanitization of numbers
        cls.user_employee.company_id.write(
            {'country_id': cls.env.ref('base.be').id})

        # some numbers for testing
        cls.random_numbers_str = '+32456998877, 0456665544'
        cls.random_numbers = cls.random_numbers_str.split(', ')
        cls.random_numbers_san = [
            phone_validation.phone_format(number,
                                          'BE',
                                          '32',
                                          force_format='E164')
            for number in cls.random_numbers
        ]
        cls.test_numbers = ['+32456010203', '0456 04 05 06', '0032456070809']
        cls.test_numbers_san = [
            phone_validation.phone_format(number,
                                          'BE',
                                          '32',
                                          force_format='E164')
            for number in cls.test_numbers
        ]

        # some numbers for mass testing
        cls.mass_numbers = ['04561%s2%s3%s' % (x, x, x) for x in range(0, 10)]
        cls.mass_numbers_san = [
            phone_validation.phone_format(number,
                                          'BE',
                                          '32',
                                          force_format='E164')
            for number in cls.mass_numbers
        ]