Beispiel #1
0
def upgrade(request, token=None):
    profile = request.user.get_profile()
    organization = get_organization(request)
    if request.method == 'GET':
        form = UpgradeForm()
        organization_form = OrganizationForm(instance=organization)
        profile_form = EditUserProfileForm(
            data=dict(title=profile.title,
                      first_name=profile.user.first_name,
                      last_name=profile.user.last_name,
                      username=profile.user.username,
                      mobile_phone=profile.mobile_phone))
        return render_to_response("registration/upgrade.html", {
            'organization': organization_form,
            'profile': profile_form,
            'form': form
        },
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = UpgradeForm(request.POST)
        organization = Organization.objects.get(org_id=request.POST["org_id"])
        organization_form = OrganizationForm(request.POST,
                                             instance=organization).update()
        profile_form = EditUserProfileForm(request.POST)
        if form.is_valid() and organization_form.is_valid(
        ) and profile_form.is_valid():
            organization.save()

            invoice_period = form.cleaned_data['invoice_period']
            preferred_payment = form.cleaned_data['preferred_payment']

            payment_details = PaymentDetails.objects.model(
                organization=organization,
                invoice_period=invoice_period,
                preferred_payment=preferred_payment)
            payment_details.save()
            message_tracker = MessageTracker(organization=organization,
                                             month=datetime.datetime.today())
            message_tracker.save()

            DataSenderOnTrialAccount.objects.filter(
                organization=organization).delete()
            _send_upgrade_email(request.user, request.LANGUAGE_CODE)
            _update_user_and_profile(request, profile_form)
            messages.success(request, _("upgrade success message"))
            if token:
                request.user.backend = 'django.contrib.auth.backends.ModelBackend'
                sign_in(request, request.user)
                Token.objects.get(pk=token).delete()
            return HttpResponseRedirect(django_settings.LOGIN_REDIRECT_URL)

        return render_to_response("registration/upgrade.html", {
            'organization': organization_form,
            'profile': profile_form,
            'form': form
        },
                                  context_instance=RequestContext(request))
    def test_has_exceeded_submission_limit(self):
        self.assertFalse(self.organization.has_exceeded_submission_limit())

        last_month = datetime.date.today() - datetime.timedelta(days=4)
        mt_current_month = MessageTracker(month=datetime.date(last_month.year, last_month.month, 12),
                                          incoming_web_count=909, incoming_sms_count=13, incoming_sp_count=5,
                                          sms_api_usage_count=3,
                                          sms_registration_count=2, sent_reminders_count=10, send_message_count=0,
                                          outgoing_sms_count=40,
                                          organization=self.organization
        )
        mt_current_month.save()
        print self.organization.get_total_submission_count()
        self.assertTrue(self.organization.has_exceeded_submission_limit())
Beispiel #3
0
    def setUpClass(cls):
        HeadlessRunnerTest.setUpClass()
        cls.message_tracker = MessageTracker()
        cls.message_tracker.organization_id = 'YDC120930'
        cls.message_tracker.sms_api_usage_count = 20
        cls.message_tracker.sms_registration_count = 10
        cls.message_tracker.outgoing_sms_count = 50
        cls.message_tracker.incoming_sms_count = 50
        cls.message_tracker.sent_reminders_count = 0
        cls.message_tracker.send_message_count = 0
        cls.message_tracker.incoming_sp_count = 160
        cls.message_tracker.incoming_web_count = 800
        cls.message_tracker.month = datetime.strftime(datetime.today(), "%Y-%m-01")
        cls.message_tracker.save()
        # doing successful login with valid credentials

        login(cls.driver, VALID_CREDENTIALS)
Beispiel #4
0
    def setUpClass(cls):
        cls.driver = setup_driver()
        cls.message_tracker = MessageTracker()
        cls.message_tracker.organization_id = 'YDC120930'
        cls.message_tracker.sms_api_usage_count = 20
        cls.message_tracker.sms_registration_count = 10
        cls.message_tracker.outgoing_sms_count = 50
        cls.message_tracker.incoming_sms_count = 50
        cls.message_tracker.sent_reminders_count = 0
        cls.message_tracker.send_message_count = 0
        cls.message_tracker.incoming_sp_count = 160
        cls.message_tracker.incoming_web_count = 800
        cls.message_tracker.month = datetime.strftime(datetime.today(), "%Y-%m-01")
        cls.message_tracker.save()
        # doing successful login with valid credentials

        cls.driver.go_to(DATA_WINNER_LOGIN_PAGE)
        login_page = LoginPage(cls.driver)
        cls.global_navigation = login_page.do_successful_login_with(VALID_CREDENTIALS)
 def setUpClass(cls):
     HeadlessRunnerTest.setUpClass()
     cls.message_tracker = MessageTracker()
     cls.message_tracker.organization_id = 'YDC120930'
     cls.message_tracker.sms_api_usage_count = 20
     cls.message_tracker.sms_registration_count = 10
     cls.message_tracker.outgoing_sms_count = 50
     cls.message_tracker.incoming_sms_count = 50
     cls.message_tracker.sent_reminders_count = 0
     cls.message_tracker.send_message_count = 0
     cls.message_tracker.incoming_sp_count = 160
     cls.message_tracker.incoming_web_count = 800
     cls.message_tracker.month = datetime.strftime(datetime.today(),
                                                   "%Y-%m-01")
     cls.message_tracker.save()
     # doing successful login with valid credentials
     from datawinners.accountmanagement.models import Organization
     org = Organization.objects.get(org_id="YDC120930")
     org.active_date = datetime.now()
     org.status_changed_datetime = datetime.now()
     org.save()
     login(cls.driver, VALID_CREDENTIALS)
Beispiel #6
0
 def setUp(self):
     self.message_tracker = MessageTracker()
     request = Mock()
     request.user = User.objects.get(pk=-12)
     self.request = request
    def _prepare_organization(self):
        trial_organization = Organization(name='test_org_for_trial_account',
                                          sector='PublicHealth', address='add',
                                          city='Pune', country='IN',
                                          zipcode='411006', account_type='Basic',
                                          org_id=OrganizationIdCreator().generateId(),
                                          status='Activated')
        trial_organization.save()

        today = datetime.datetime.today()
        mt_current_month = MessageTracker(month=datetime.date(today.year, today.month, 12),
                                          incoming_web_count=7, incoming_sms_count=13, incoming_sp_count=5,
                                          sms_api_usage_count=3,sms_api_usage_charged_count=3,
                                          sms_registration_count=2, sent_reminders_count=10,
                                          sent_reminders_charged_count=10, send_message_count=0,
                                          send_message_charged_count=0, outgoing_sms_count=40,
                                          outgoing_sms_charged_count=40,
                                          organization=trial_organization
        )
        mt_current_month.save()
        mt_current_month = MessageTracker(month=datetime.date(today.year, today.month, 1),
                                          incoming_web_count=3, incoming_sms_count=20, incoming_sp_count=10,
                                          sms_api_usage_count=3,
                                          sms_registration_count=4, outgoing_sms_count=40,
                                          organization=trial_organization
        )
        mt_current_month.save()
        year = today.year
        month = today.month
        if today.month == 1:
            year -= 1
            month = 12
        mt_last_month = MessageTracker(month=datetime.date(year, month, 1),
                                       incoming_web_count=10, incoming_sms_count=10, incoming_sp_count=7,
                                       sms_api_usage_count=3,
                                       sms_registration_count=4, outgoing_sms_count=40, organization=trial_organization
        )
        mt_last_month.save()
        return trial_organization