Esempio n. 1
0
 def test_titleless_salutation_is_stripped(self):
     a = UserAddress(last_name='Barrington',
                     line1="75 Smith Road",
                     postcode="N4 8TY",
                     country=self.country,
                     user=self.user)
     self.assertEquals("Barrington", a.salutation())
Esempio n. 2
0
 def test_hashing_with_utf8(self):
     a = UserAddress(first_name=u"\u0141ukasz Smith",
                     last_name=u'Smith',
                     line1=u"75 Smith Road",
                     postcode=u"n4 8ty",
                     country=self.country,
                     user=self.user)
     hash = a.active_address_fields()
Esempio n. 3
0
 def test_active_address_fields_skips_whitespace_only_fields(self):
     a = UserAddress(first_name="   ",
                     last_name='Barrington',
                     line1="  75 Smith Road  ",
                     postcode="  n4 8ty",
                     country=self.country,
                     user=self.user)
     active_fields = a.active_address_fields()
     self.assertEquals("Barrington", active_fields[0])
Esempio n. 4
0
 def test_hashing_with_utf8(self):
     a = UserAddress(
         first_name=u"\u0141ukasz Smith",
         last_name=u"Smith",
         line1=u"75 Smith Road",
         postcode=u"n4 8ty",
         country=self.country,
         user=self.user,
     )
     a.active_address_fields()
Esempio n. 5
0
 def test_populated_shipping_address_has_same_summary_user_address(self):
     a = UserAddress(first_name=" Terry  ",
                     last_name='Barrington',
                     line1="  75 Smith Road  ",
                     postcode="  n4 8ty",
                     country=self.country,
                     user=self.user)
     sa = ShippingAddress()
     a.populate_alternative_model(sa)
     self.assertEquals(sa.summary, a.summary)
Esempio n. 6
0
 def test_populate_shipping_address_doesnt_set_id(self):
     a = UserAddress(first_name=" Terry  ",
                     last_name='Barrington',
                     line1="  75 Smith Road  ",
                     postcode="  n4 8ty",
                     country=self.country,
                     user=self.user)
     sa = ShippingAddress()
     a.populate_alternative_model(sa)
     self.assertIsNone(sa.id)
Esempio n. 7
0
 def test_active_address_fields_skips_whitespace_only_fields(self):
     a = UserAddress(
         first_name="   ",
         last_name="Barrington",
         line1="  75 Smith Road  ",
         postcode="  n4 8ty",
         country=self.country,
         user=self.user,
     )
     active_fields = a.active_address_fields()
     self.assertEquals("Barrington", active_fields[0])
Esempio n. 8
0
 def test_populated_shipping_address_has_same_summary_user_address(self):
     a = UserAddress(
         first_name=" Terry  ",
         last_name="Barrington",
         line1="  75 Smith Road  ",
         postcode="  n4 8ty",
         country=self.country,
         user=self.user,
     )
     sa = ShippingAddress()
     a.populate_alternative_model(sa)
     self.assertEquals(sa.summary, a.summary)
Esempio n. 9
0
 def test_populate_shipping_address_doesnt_set_id(self):
     a = UserAddress(
         first_name=" Terry  ",
         last_name="Barrington",
         line1="  75 Smith Road  ",
         postcode="  n4 8ty",
         country=self.country,
         user=self.user,
     )
     sa = ShippingAddress()
     a.populate_alternative_model(sa)
     self.assertIsNone(sa.id)
Esempio n. 10
0
 def test_city_is_alias_of_line4(self):
     a = UserAddress(last_name='Barrington',
                     line1="75 Smith Road",
                     line4="London",
                     postcode="n4 8ty",
                     country=self.country,
                     user=self.user)
     self.assertEqual('London', a.city)
Esempio n. 11
0
 def test_addresses_with_same_fields_ignoring_whitespace_have_same_hash(self):
     a1 = UserAddress(
         first_name=" Terry  ",
         last_name="Barrington",
         line1="  75 Smith Road  ",
         postcode="  n4 8ty",
         country=self.country,
         user=self.user,
     )
     a2 = UserAddress(
         first_name=" Terry",
         last_name="   Barrington",
         line1="  75 Smith Road  ",
         postcode="N4 8ty",
         country=self.country,
         user=self.user,
     )
     self.assertEquals(a1.generate_hash(), a2.generate_hash())
Esempio n. 12
0
 def test_summary_is_property(self):
     a = UserAddress(first_name=" Terry  ",
                     last_name='Barrington',
                     line1="  75 Smith Road  ",
                     postcode="  n4 8ty",
                     country=self.country,
                     user=self.user)
     self.assertEquals(
         "Terry Barrington, 75 Smith Road, N4 8TY, UNITED KINGDOM",
         a.summary)
Esempio n. 13
0
 def test_addresses_with_same_fields_ignoring_whitespace_have_same_hash(
         self):
     a1 = UserAddress(first_name=" Terry  ",
                      last_name='Barrington',
                      line1="  75 Smith Road  ",
                      postcode="  n4 8ty",
                      country=self.country,
                      user=self.user)
     a2 = UserAddress(first_name=" Terry",
                      last_name='   Barrington',
                      line1="  75 Smith Road  ",
                      postcode="N4 8ty",
                      country=self.country,
                      user=self.user)
     self.assertEquals(a1.generate_hash(), a2.generate_hash())
Esempio n. 14
0
def user_settings_view_new(request):

    profile_updated = False
    # if this is a POST request we need to process the form data
    if 'edit_profile' in request.POST:
        # create a form instance and populate it with data from the request:
        edit_profile_form = EditProfileForm(data=request.POST,
                                            user=request.user)
        # check whether it's valid:
        if edit_profile_form.is_valid():
            edit_profile_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            profile_updated = True
    # if a GET (or any other method) we'll create a blank form
    else:
        edit_profile_form = EditProfileForm(user=request.user)

    if 'edit_active_card' in request.POST:
        try:
            stripe_token = request.POST.get('stripe_token')
            customer, created = Customer.get_or_create(
                subscriber=subscriber_request_callback(request))
            update_active_card(customer, stripe_token)
        except stripe.StripeError as e:
            # add form error here
            return _ajax_response(
                request, JsonResponse({'error': e.args[0]}, status=500))

        messages.success(request,
                         'Your account card has been changed successfully.')
        profile_updated = True

    if 'change_email' in request.POST:
        change_email_form = ChangeEmailForm(data=request.POST,
                                            user=request.user)
        if change_email_form.is_valid():
            change_email_form.save(request)
            messages.success(
                request, 'Your email address has been changed successfully.')
            profile_updated = True
    else:
        change_email_form = ChangeEmailForm(user=request.user)

    if 'change_password' in request.POST:
        change_password_form = ChangePasswordForm(data=request.POST,
                                                  user=request.user)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(request,
                             'Your password has been changed successfully.')
            profile_updated = True
    else:
        change_password_form = ChangePasswordForm(user=request.user)

    # if this is a POST request we need to process the form data
    if 'artist_info' in request.POST:
        # create a form instance and populate it with data from the request:
        artist_info_form = ArtistInfoForm(data=request.POST,
                                          instance=request.user)
        # check whether it's valid:
        if artist_info_form.is_valid():
            artist_info_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            profile_updated = True
        else:
            assert False, artist_info_form.errors
    # if a GET (or any other method) we'll create a blank form
    else:
        artist_info_form = ArtistInfoForm(instance=request.user)

    if 'billing_info' in request.POST:
        billing_address_form = BillingAddressForm(None, request.user,
                                                  request.POST)
        if billing_address_form.is_valid():
            billing_address_form.save()
            profile_updated = True
        else:
            billing_address_form = BillingAddressForm(None, request.user, None)

    if profile_updated:
        return HttpResponseRedirect('/accounts/settings/')

    plan = None
    period_end = {}
    period_end['date'] = None

    customer_detail = None
    customer_charges = None
    user_archive_access_until = None
    monthly_pledge_in_dollars = None
    cancel_at = None
    billing_address = None

    show_email_confirmation = False

    try:
        customer = request.user.customer
    except:
        customer = None

    user_archive_access_until = None
    if request.user.has_archive_access:
        user_archive_access_until = request.user.get_archive_access_expiry_date(
        )

    if customer and customer.has_active_subscription():
        plan_id = request.user.customer.current_subscription.plan
        try:
            plan = stripe.Plan.retrieve(id=plan_id)
        except stripe.error.InvalidRequestError:
            plan = None

    customer_charges = request.user.get_donations().order_by('-date')
    charges_value = 0
    for charge in customer_charges:
        if charge.amount:
            charges_value = charges_value + charge.amount

        artist_info_form = ArtistInfoForm(instance=request.user)
    customer_detail = CustomerDetail.get(id=request.user.customer.stripe_id)

    if customer_detail and customer_detail.subscription:
        monthly_pledge_in_dollars = customer_detail.subscription.plan.amount / 100

    if customer_detail and customer_detail.subscription:
        period_end["date"] = datetime.fromtimestamp(
            customer_detail.subscription.current_period_end).strftime(
                "%d/%m/%y")
        period_end["due"] = datetime.fromtimestamp(
            customer_detail.subscription.current_period_end) <= datetime.now()

    if customer_detail and customer_detail.subscription and customer_detail.subscriptions.data:
        cancel_at = customer_detail.subscriptions.data[0][
            'cancel_at_period_end']
    else:
        cancel_at = False

    try:
        billing_address = request.user.addresses.get(
            is_default_for_billing=True)
    except UserAddress.DoesNotExist:
        try:
            billing_address = request.user.addresses.first()
        except UserAddress.DoesNotExist:
            billing_address = UserAddress()

    return render(
        request, 'account/user_settings_new.html', {
            'STRIPE_PUBLIC_KEY': settings.STRIPE_PUBLIC_KEY,
            'change_email_form': change_email_form,
            'change_profile_form': edit_profile_form,
            'change_password_form': change_password_form,
            'current_user': request.user,
            'artist_info_form': artist_info_form,
            'plan': plan,
            'donations': request.user.get_donations() or None,
            'customer_detail': customer_detail or '',
            'customer_charges': customer_charges or '',
            'charges_value': request.user.get_donation_amount or '0',
            'period_end': period_end,
            'user_archive_access_until': user_archive_access_until
            or 'unverified account',
            'monthly_pledge_in_dollars': monthly_pledge_in_dollars or 'no',
            'cancelled': cancel_at or '',
            'donate_url': reverse('donate'),
            'billing_address': billing_address or '',
            'show_email_confirmation_dialog': show_email_confirmation
        })
Esempio n. 15
0
 def test_titleless_salutation_is_stripped(self):
     a = UserAddress(last_name='Barrington', line1="75 Smith Road", postcode="N4 8TY", 
                                    country=self.country, user=self.user)
     self.assertEquals("Barrington", a.salutation())