def test_should_get_the_correct_registration_processor(self): self.assertTrue( isinstance(get_registration_processor(self.trial_organization), TrialAccountRegistrationProcessor)) self.assertTrue( isinstance(get_registration_processor(self.paid_organization), PaidAccountRegistrationProcessor))
def test_should_process_registration_data_for_trial_acccount_in_french( self): processor = get_registration_processor(self.trial_organization) site = Site(domain='test', name='test_site') kwargs = dict(invoice_period='', preferred_payment='') processor.process(self.user2, site, 'fr', kwargs) emails = [mail.outbox.pop() for i in range(len(mail.outbox))] self.assertEqual(1, len(emails)) sent_email = emails[0] self.assertEqual("html", sent_email.content_subtype) self.assertEqual(settings.EMAIL_HOST_USER, sent_email.from_email) self.assertEqual(['*****@*****.**'], sent_email.to) self.assertEqual([settings.HNI_SUPPORT_EMAIL_ID], sent_email.bcc) ctx_dict = { 'activation_key': RegistrationProfile.objects.get(user=self.user2).activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': site, 'name': self.user2.first_name + ' ' + self.user2.last_name } self.assertEqual( render_to_string( 'registration/activation_email_subject_for_trial_account_in_fr.txt' ), sent_email.subject) self.assertEqual( render_to_string( 'registration/activation_email_for_trial_account_in_fr.html', ctx_dict), sent_email.body)
def test_should_process_registration_data_for_paid_acccount_in_english( self): with patch.object(ProSMSAccountRegistrationProcessor, '_get_invoice_total') as get_invoice_total_patch: get_invoice_total_patch.return_value = PRO_SMS_MONTHLY_PRICING, '1 month' processor = get_registration_processor(self.paid_organization) site = Site(domain='test', name='test_site') kwargs = dict(invoice_period='', preferred_payment='') processor.process(self.user1, site, 'en', kwargs) emails = [mail.outbox.pop() for i in range(len(mail.outbox))] self.assertEqual(1, len(emails)) sent_email = emails[0] self.assertEqual("html", sent_email.content_subtype) self.assertEqual(settings.EMAIL_HOST_USER, sent_email.from_email) self.assertEqual(['*****@*****.**'], sent_email.to) self.assertEqual([settings.HNI_SUPPORT_EMAIL_ID], sent_email.bcc) self.assertEqual( render_to_string( 'registration/activation_email_subject_in_en.txt'), sent_email.subject) ctx_dict = { 'activation_key': RegistrationProfile.objects.get( user=self.user1).activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': site, 'username': self.user1.first_name, 'invoice_total': PRO_SMS_MONTHLY_PRICING, 'period': '1 month' } self.assertEqual( render_to_string( 'registration/pro_sms_activation_email_in_en.html', ctx_dict), sent_email.body) payment_detail = PaymentDetails.objects.filter( organization=self.paid_organization) self.assertTrue(is_not_empty(payment_detail)) payment_detail.delete()
def register(self, request, **kwargs): """ Given a username, email address and password, register a new user account, which will initially be inactive. Along with the new ``User`` object, a new ``registration.models.RegistrationProfile`` will be created, tied to that ``User``, containing the activation key which will be used for this account. An email will be sent to the supplied email address; this email should contain an activation link. The email will be rendered using two templates. See the documentation for ``RegistrationProfile.send_activation_email()`` for information about these templates and the contexts provided to them. After the ``User`` and ``RegistrationProfile`` are created and the activation email is sent, the signal ``registration.signals.user_registered`` will be sent, with the new ``User`` as the keyword argument ``user`` and the class of this backend as the sender. """ if Site._meta.installed: site = Site.objects.get_current() else: site = RequestSite(request) organization = self.create_respective_organization(kwargs) organization.save() organization.organization_setting.save() new_user = self._create_user(site, kwargs) registration_processor = get_registration_processor(organization) registration_processor.process(new_user, site, request.LANGUAGE_CODE, kwargs) new_user.save() signals.user_registered.send(sender=self.__class__, user=new_user, request=request, title=kwargs.get("title"), organization_id=organization.org_id, organization=organization, mobile_phone=kwargs.get("mobile_phone"), reporter_id=kwargs.get('reporter_id')) return new_user