more coverage stuff
This commit is contained in:
@@ -34,7 +34,7 @@ from rowsandall_app.settings import (
|
|||||||
BRAINTREE_SANDBOX_PRIVATE_KEY, BRAINTREE_MERCHANT_ACCOUNT_ID
|
BRAINTREE_SANDBOX_PRIVATE_KEY, BRAINTREE_MERCHANT_ACCOUNT_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
if settings.DEBUG or 'dev' in settings.SITE_URL:
|
if settings.DEBUG or 'dev' in settings.SITE_URL: # pragma: no cover
|
||||||
gateway = braintree.BraintreeGateway(
|
gateway = braintree.BraintreeGateway(
|
||||||
braintree.Configuration(
|
braintree.Configuration(
|
||||||
braintree.Environment.Sandbox,
|
braintree.Environment.Sandbox,
|
||||||
@@ -68,7 +68,7 @@ def process_webhook(notification):
|
|||||||
if notification.kind == 'subscription_canceled':
|
if notification.kind == 'subscription_canceled':
|
||||||
subscription = notification.subscription
|
subscription = notification.subscription
|
||||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||||
if rs.count() == 0:
|
if rs.count() == 0: # pragma: no cover
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
f.write('Could not find rowers with subscription ID '+subscription.id+'\n')
|
f.write('Could not find rowers with subscription ID '+subscription.id+'\n')
|
||||||
return 0
|
return 0
|
||||||
@@ -76,10 +76,10 @@ def process_webhook(notification):
|
|||||||
result,mesg,errormsg = cancel_subscription(r,subscription.id)
|
result,mesg,errormsg = cancel_subscription(r,subscription.id)
|
||||||
if result:
|
if result:
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
f.write('Subscription canceled: '+subscription.id+'\n')
|
f.write('Subscription canceled: '+str(subscription.id)+'\n')
|
||||||
return subscription.id
|
return subscription.id
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f: # pragma: no cover
|
||||||
f.write('Could not cancel Subscription: '+subscription.id+'\n')
|
f.write('Could not cancel Subscription: '+str(subscription.id)+'\n')
|
||||||
return 0
|
return 0
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -87,10 +87,10 @@ def send_invoice(subscription):
|
|||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
t = time.localtime()
|
t = time.localtime()
|
||||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||||
f.write('Subscription ID '+subscription.id+'\n')
|
f.write('Subscription ID '+str(subscription.id)+'\n')
|
||||||
subscription_id = subscription.id
|
subscription_id = subscription.id
|
||||||
rs = Rower.objects.filter(subscription_id=subscription_id)
|
rs = Rower.objects.filter(subscription_id=subscription_id)
|
||||||
if rs.count() == 0:
|
if rs.count() == 0: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
r = rs[0]
|
r = rs[0]
|
||||||
@@ -99,7 +99,7 @@ def send_invoice(subscription):
|
|||||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
fakturoid_contact_id = fakturoid.get_contacts(r)
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
f.write('Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
f.write('Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
||||||
if not fakturoid_contact_id:
|
if not fakturoid_contact_id: # pragma: no cover
|
||||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
fakturoid_contact_id = fakturoid.create_contact(r)
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
f.write('Created Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
f.write('Created Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
||||||
@@ -112,7 +112,7 @@ def send_invoice(subscription):
|
|||||||
contact_id=fakturoid_contact_id)
|
contact_id=fakturoid_contact_id)
|
||||||
return id
|
return id
|
||||||
|
|
||||||
return 0
|
return 0 # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
def webhook(request):
|
def webhook(request):
|
||||||
@@ -120,7 +120,7 @@ def webhook(request):
|
|||||||
webhook_notification = gateway.webhook_notification.parse(
|
webhook_notification = gateway.webhook_notification.parse(
|
||||||
str(request.POST['bt_signature']),
|
str(request.POST['bt_signature']),
|
||||||
request.POST['bt_payload'])
|
request.POST['bt_payload'])
|
||||||
except InvalidSignatureError:
|
except InvalidSignatureError: # pragma: no cover
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
result = process_webhook(webhook_notification)
|
result = process_webhook(webhook_notification)
|
||||||
@@ -136,14 +136,14 @@ def create_customer(rower,force=False):
|
|||||||
'last_name':rower.user.last_name,
|
'last_name':rower.user.last_name,
|
||||||
'email':rower.user.email,
|
'email':rower.user.email,
|
||||||
})
|
})
|
||||||
if not result.is_success:
|
if not result.is_success: # pragma: no cover
|
||||||
raise ProcessorCustomerError
|
raise ProcessorCustomerError
|
||||||
else:
|
else:
|
||||||
rower.customer_id = result.customer.id
|
rower.customer_id = result.customer.id
|
||||||
rower.paymentprocessor = 'braintree'
|
rower.paymentprocessor = 'braintree'
|
||||||
rower.save()
|
rower.save()
|
||||||
return rower.customer_id
|
return rower.customer_id
|
||||||
else:
|
else: # pragma: no cover
|
||||||
return rower.customer_id
|
return rower.customer_id
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ def get_client_token(rower):
|
|||||||
client_token = gateway.client_token.generate({
|
client_token = gateway.client_token.generate({
|
||||||
"customer_id":rower.customer_id,
|
"customer_id":rower.customer_id,
|
||||||
})
|
})
|
||||||
except ValueError:
|
except ValueError: # pragma: no cover
|
||||||
customer_id = create_customer(rower,force=True)
|
customer_id = create_customer(rower,force=True)
|
||||||
|
|
||||||
client_token = gateway.client_token.generate({
|
client_token = gateway.client_token.generate({
|
||||||
@@ -162,7 +162,7 @@ def get_client_token(rower):
|
|||||||
|
|
||||||
return client_token
|
return client_token
|
||||||
|
|
||||||
def get_plans_costs():
|
def get_plans_costs(): # pragma: no cover
|
||||||
plans = gateway.plan.all()
|
plans = gateway.plan.all()
|
||||||
|
|
||||||
localplans = PaidPlan.object.filter(paymentprocessor='braintree')
|
localplans = PaidPlan.object.filter(paymentprocessor='braintree')
|
||||||
@@ -179,7 +179,7 @@ def make_payment(rower,data):
|
|||||||
nonce_from_the_client = data['payment_method_nonce']
|
nonce_from_the_client = data['payment_method_nonce']
|
||||||
nonce = gateway.payment_method_nonce.find(nonce_from_the_client)
|
nonce = gateway.payment_method_nonce.find(nonce_from_the_client)
|
||||||
info = nonce.three_d_secure_info
|
info = nonce.three_d_secure_info
|
||||||
if nonce.type.lower() == 'creditcard':
|
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
||||||
if info is None or not info.liability_shifted:
|
if info is None or not info.liability_shifted:
|
||||||
return False,0
|
return False,0
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ def make_payment(rower,data):
|
|||||||
name, rower.user.email, amount)
|
name, rower.user.email, amount)
|
||||||
|
|
||||||
return amount,True
|
return amount,True
|
||||||
else:
|
else: # pragma: no cover
|
||||||
return 0,False
|
return 0,False
|
||||||
|
|
||||||
def update_subscription(rower,data,method='up'):
|
def update_subscription(rower,data,method='up'):
|
||||||
@@ -397,7 +397,7 @@ def cancel_subscription(rower,id):
|
|||||||
try:
|
try:
|
||||||
result = gateway.subscription.cancel(id)
|
result = gateway.subscription.cancel(id)
|
||||||
themessages.append("Subscription canceled")
|
themessages.append("Subscription canceled")
|
||||||
except:
|
except: # pragma: no cover
|
||||||
errormessages.append("We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.")
|
errormessages.append("We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.")
|
||||||
|
|
||||||
|
|
||||||
@@ -426,29 +426,29 @@ def cancel_subscription(rower,id):
|
|||||||
def find_subscriptions(rower):
|
def find_subscriptions(rower):
|
||||||
try:
|
try:
|
||||||
result = gateway.customer.find(rower.customer_id)
|
result = gateway.customer.find(rower.customer_id)
|
||||||
except:
|
except: # pragma: no cover
|
||||||
raise ProcessorCustomerError("We could not find the customer in the database")
|
raise ProcessorCustomerError("We could not find the customer in the database")
|
||||||
|
|
||||||
active_subscriptions = []
|
active_subscriptions = []
|
||||||
|
|
||||||
cards = result.credit_cards
|
cards = result.credit_cards
|
||||||
for card in cards:
|
for card in cards: # pragma: no cover
|
||||||
for subscription in card.subscriptions:
|
for subscription in card.subscriptions:
|
||||||
if subscription.status == 'Active':
|
if subscription.status == 'Active':
|
||||||
active_subscriptions.append(subscription)
|
active_subscriptions.append(subscription)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
paypal_accounts = result.paypal_accounts
|
paypal_accounts = result.paypal_accounts
|
||||||
for account in paypal_accounts:
|
for account in paypal_accounts: # pragma: no cover
|
||||||
for subscription in account.subscriptions:
|
for subscription in account.subscriptions:
|
||||||
if subscription.status == 'Active':
|
if subscription.status == 'Active':
|
||||||
active_subscriptions.append(subscription)
|
active_subscriptions.append(subscription)
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
pass
|
pass
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
for subscription in active_subscriptions:
|
for subscription in active_subscriptions: # pragma: no cover
|
||||||
|
|
||||||
plan = PaidPlan.objects.filter(paymentprocessor="braintree",
|
plan = PaidPlan.objects.filter(paymentprocessor="braintree",
|
||||||
external_id=subscription.plan_id)[0]
|
external_id=subscription.plan_id)[0]
|
||||||
@@ -466,7 +466,7 @@ def find_subscriptions(rower):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_transactions(start_date,end_date):
|
def get_transactions(start_date,end_date): # pragma: no cover
|
||||||
results = gateway.transaction.search(
|
results = gateway.transaction.search(
|
||||||
braintree.TransactionSearch.created_at.between(
|
braintree.TransactionSearch.created_at.between(
|
||||||
start_date,
|
start_date,
|
||||||
@@ -553,5 +553,5 @@ def get_transactions(start_date,end_date):
|
|||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
def mocktest(rower):
|
def mocktest(rower): # pragma: no cover
|
||||||
return '5'
|
return '5'
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ def get_contacts(rower):
|
|||||||
|
|
||||||
|
|
||||||
res = requests.get(url, auth=auth, headers=headers)
|
res = requests.get(url, auth=auth, headers=headers)
|
||||||
|
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
f.write('Searching Contact Status code '+str(res.status_code)+'\n')
|
f.write('Searching Contact Status code '+str(res.status_code)+'\n')
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ def user_is_not_basic(user):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
if user.rower.protrialexpires >= datetime.date.today():
|
if user.rower.protrialexpires >= datetime.date.today():
|
||||||
return True
|
return True # pragma: no cover
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ def user_is_basic(user):
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_start_trial(user):
|
def can_start_trial(user):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -97,13 +97,13 @@ def can_start_trial(user):
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_start_plantrial(user):
|
def can_start_plantrial(user):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return user.rower.plantrialexpires == datetime.date(1970,1,1)
|
return user.rower.plantrialexpires == datetime.date(1970,1,1)
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_staff(user):
|
def is_staff(user): # pragma: no cover
|
||||||
return user.is_staff
|
return user.is_staff
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
@@ -117,7 +117,7 @@ def is_paid_coach(user):
|
|||||||
def is_planmember(user):
|
def is_planmember(user):
|
||||||
try:
|
try:
|
||||||
r = user.rower
|
r = user.rower
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return r.rowerplan in ['coach','plan'] # freecoach?
|
return r.rowerplan in ['coach','plan'] # freecoach?
|
||||||
@@ -144,7 +144,7 @@ def is_protrial(user):
|
|||||||
if r.mycoachgroup is not None:
|
if r.mycoachgroup is not None:
|
||||||
return len(r.mycoachgroup)>=4
|
return len(r.mycoachgroup)>=4
|
||||||
|
|
||||||
return False
|
return False # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ def can_add_plan(user):
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_add_workout(user):
|
def can_add_workout(user):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return user.rower.rowerplan != 'freecoach'
|
return user.rower.rowerplan != 'freecoach'
|
||||||
@@ -180,7 +180,7 @@ def can_add_workout(user):
|
|||||||
def is_plantrial(user):
|
def is_plantrial(user):
|
||||||
try:
|
try:
|
||||||
r = user.rower
|
r = user.rower
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if r.rowerplan in ['basic','pro']:
|
if r.rowerplan in ['basic','pro']:
|
||||||
@@ -189,7 +189,7 @@ def is_plantrial(user):
|
|||||||
if r.mycoachgroup is not None:
|
if r.mycoachgroup is not None:
|
||||||
return len(r.mycoachgroup)>=4
|
return len(r.mycoachgroup)>=4
|
||||||
|
|
||||||
return False
|
return False # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
isplanmember = is_planmember | is_plantrial
|
isplanmember = is_planmember | is_plantrial
|
||||||
@@ -202,13 +202,13 @@ def can_add_session(user):
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_plan(user):
|
def can_plan(user):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
if user.rower.rowerplan in ['plan','coach']:
|
if user.rower.rowerplan in ['plan','coach']:
|
||||||
return True
|
return True
|
||||||
if user.rower.rowerplan in ['basic','pro']:
|
if user.rower.rowerplan in ['basic','pro']:
|
||||||
return user.rower.plantrialexpires >= datetime.date.today()
|
return user.rower.plantrialexpires >= datetime.date.today()
|
||||||
if user.rower.rowerplan == 'freecoach':
|
if user.rower.rowerplan == 'freecoach': # pragma: no cover
|
||||||
if user.rower.mycoachgroup is not None:
|
if user.rower.mycoachgroup is not None:
|
||||||
return len(user.rower.mycoachgroup)>=4
|
return len(user.rower.mycoachgroup)>=4
|
||||||
|
|
||||||
@@ -238,8 +238,7 @@ def is_coach_user(usercoach,userrower):
|
|||||||
|
|
||||||
# checks if rower is coach of user (or is user himself)
|
# checks if rower is coach of user (or is user himself)
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_anonymous_or_coach(usercoach,userrower):
|
def is_anonymous_or_coach(usercoach,userrower): # pragma: no cover
|
||||||
print(usercoach,userrower)
|
|
||||||
if usercoach == userrower:
|
if usercoach == userrower:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -267,7 +266,7 @@ def is_anonymous_or_coach(usercoach,userrower):
|
|||||||
# check if rower and user are members of the same team
|
# check if rower and user are members of the same team
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_rower_team_member(user,rower):
|
def is_rower_team_member(user,rower):
|
||||||
if user.rower == rower:
|
if user.rower == rower: # pragma: no cover
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if is_coach_user(user,rower.user):
|
if is_coach_user(user,rower.user):
|
||||||
@@ -286,11 +285,11 @@ def is_rower_team_member(user,rower):
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_add_workout_member(user,rower):
|
def can_add_workout_member(user,rower):
|
||||||
if not user:
|
if not user: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
if user == rower.user:
|
if user == rower.user: # pragma: no cover
|
||||||
return True
|
return True
|
||||||
# only below tested - need test user == rower.user
|
# only below tested - need test user == rower.user
|
||||||
return is_coach(user) and user.rower in rower.get_coaches()
|
return is_coach(user) and user.rower in rower.get_coaches()
|
||||||
@@ -310,7 +309,7 @@ def can_plan_user(user,rower):
|
|||||||
# free coach, plan etc cannot plan for basic
|
# free coach, plan etc cannot plan for basic
|
||||||
if not is_paid_coach(user) and user_is_not_basic(user):
|
if not is_paid_coach(user) and user_is_not_basic(user):
|
||||||
for t in teams:
|
for t in teams:
|
||||||
if rower in t.rower.all():
|
if rower in t.rower.all(): # pragma: no cover
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# paying coach can plan for all kinds of rowers
|
# paying coach can plan for all kinds of rowers
|
||||||
@@ -362,7 +361,7 @@ def is_workout_user(user,workout):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
r = user.rower
|
r = user.rower
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if workout.user == r:
|
if workout.user == r:
|
||||||
@@ -373,12 +372,12 @@ def is_workout_user(user,workout):
|
|||||||
# check if user is in same team as owner of workout
|
# check if user is in same team as owner of workout
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_workout_team(user,workout):
|
def is_workout_team(user,workout):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = user.rower
|
r = user.rower
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if workout.user == r:
|
if workout.user == r:
|
||||||
@@ -391,7 +390,7 @@ def is_workout_team(user,workout):
|
|||||||
def can_view_workout(user,workout):
|
def can_view_workout(user,workout):
|
||||||
if workout.privacy != 'private':
|
if workout.privacy != 'private':
|
||||||
return True
|
return True
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
return user == workout.user.user
|
return user == workout.user.user
|
||||||
|
|
||||||
@@ -444,7 +443,7 @@ rules.add_perm('workout.view_workout',can_view_workout) # replaces checkworkoutu
|
|||||||
|
|
||||||
# untested can_view_target to can_delete_target
|
# untested can_view_target to can_delete_target
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_view_target(user,target):
|
def can_view_target(user,target): # pragma: no cover
|
||||||
if user.is_anonymous:
|
if user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
if user == target.manager.user:
|
if user == target.manager.user:
|
||||||
@@ -459,14 +458,14 @@ def can_view_target(user,target):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_target(user,target):
|
def can_change_target(user,target): # pragma: no cover
|
||||||
if user.is_anonymous:
|
if user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
return user == target.manager.user
|
return user == target.manager.user
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_delete_target(user,target):
|
def can_delete_target(user,target):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
return user == target.manager.user
|
return user == target.manager.user
|
||||||
|
|
||||||
@@ -476,23 +475,23 @@ rules.add_perm('target.delete_target',can_delete_target)
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_view_plan(user,plan):
|
def can_view_plan(user,plan):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
if user == plan.manager.user:
|
if user == plan.manager.user:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# a plan's coach can view as well
|
# a plan's coach can view as well
|
||||||
# below untested
|
# below untested
|
||||||
if is_coach_user(user,plan.manager.user):
|
if is_coach_user(user,plan.manager.user): # pragma: no cover
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# the object can view as well
|
# the object can view as well
|
||||||
if user.rower in plan.rowers.all():
|
if user.rower in plan.rowers.all(): # pragma: no cover
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_plan(user,plan):
|
def can_change_plan(user,plan):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
return user == plan.manager.user
|
return user == plan.manager.user
|
||||||
|
|
||||||
@@ -512,7 +511,7 @@ rules.add_perm('plan.can_add_plan',can_add_plan)
|
|||||||
|
|
||||||
# untested
|
# untested
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_view_cycle(user,cycle):
|
def can_view_cycle(user,cycle): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
return can_view_cycle(user,cycle.plan)
|
return can_view_cycle(user,cycle.plan)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -521,7 +520,7 @@ def can_view_cycle(user,cycle):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_cycle(user,cycle):
|
def can_change_cycle(user,cycle): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
return can_change_cycle(user,cycle.plan)
|
return can_change_cycle(user,cycle.plan)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -530,7 +529,7 @@ def can_change_cycle(user,cycle):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_delete_cycle(user,cycle):
|
def can_delete_cycle(user,cycle): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
return can_delete_cycle(user,cycle.plan)
|
return can_delete_cycle(user,cycle.plan)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -547,43 +546,43 @@ rules.add_perm('cycle.delete_cycle',can_delete_cycle)
|
|||||||
# check if user has view access to session
|
# check if user has view access to session
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_view_session(user,session):
|
def can_view_session(user,session):
|
||||||
if session.sessiontype in ['race','indoorrace']:
|
if session.sessiontype in ['race','indoorrace']: # pragma: no cover
|
||||||
return True
|
return True
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
# session manager can view session
|
# session manager can view session
|
||||||
if user == session.manager:
|
if user == session.manager:
|
||||||
return True
|
return True
|
||||||
# if you're a rower in the session you can view it
|
# if you're a rower in the session you can view it
|
||||||
# below untested
|
# below untested
|
||||||
if user.rower in session.rower.all():
|
if user.rower in session.rower.all(): # pragma: no cover
|
||||||
return True
|
return True
|
||||||
# coach users can view sessions created by their team members
|
# coach users can view sessions created by their team members
|
||||||
# below untested
|
# below untested
|
||||||
if is_coach(user):
|
if is_coach(user): # pragma: no cover
|
||||||
teams = user.rower.get_managed_teams()
|
teams = user.rower.get_managed_teams()
|
||||||
for t in teams:
|
for t in teams:
|
||||||
teamusers = [member.u for member in t.rower.all()]
|
teamusers = [member.u for member in t.rower.all()]
|
||||||
if session.manager in teamusers:
|
if session.manager in teamusers:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False # pragma: no cover
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_session(user,session):
|
def can_change_session(user,session):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
# session part of a race should not be changed through the session interface
|
# session part of a race should not be changed through the session interface
|
||||||
if session.sessiontype in ['race','indoorrace']:
|
if session.sessiontype in ['race','indoorrace']: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
if user == session.manager:
|
if user == session.manager:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_delete_session(user,session):
|
def can_delete_session(user,session): # pragma: no cover
|
||||||
if user.is_anonymous:
|
if user.is_anonymous:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -636,7 +635,7 @@ def is_team_manager(user,team):
|
|||||||
|
|
||||||
# check is user is member of team - untested
|
# check is user is member of team - untested
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_team_member(user,team):
|
def is_team_member(user,team): # pragma: no cover
|
||||||
members = team.rower.all()
|
members = team.rower.all()
|
||||||
return user in [member.user for member in members]
|
return user in [member.user for member in members]
|
||||||
|
|
||||||
@@ -644,13 +643,13 @@ def is_team_member(user,team):
|
|||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_view_team(user,team):
|
def can_view_team(user,team):
|
||||||
# user based - below untested
|
# user based - below untested
|
||||||
if user.rower.rowerplan == 'basic' and team.manager.rower.rowerplan != 'coach':
|
if user.rower.rowerplan == 'basic' and team.manager.rower.rowerplan != 'coach': # pragma: no cover
|
||||||
return is_plantrial(user) or is_protrial(user)
|
return is_plantrial(user) or is_protrial(user)
|
||||||
# team is public
|
# team is public
|
||||||
if team.private == 'open':
|
if team.private == 'open':
|
||||||
return True
|
return True
|
||||||
# team is private - below untested
|
# team is private - below untested
|
||||||
return is_team_member(user,team) | is_team_manager(user,team)
|
return is_team_member(user,team) | is_team_manager(user,team) # pragma: no cover
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_team(user,team):
|
def can_change_team(user,team):
|
||||||
@@ -682,7 +681,7 @@ rules.add_perm('teams.delete_team',can_delete_team)
|
|||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_course(user,course):
|
def can_change_course(user,course):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return course.manager == user.rower
|
return course.manager == user.rower
|
||||||
@@ -690,21 +689,21 @@ def can_change_course(user,course):
|
|||||||
# untested
|
# untested
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_delete_course(user,course):
|
def can_delete_course(user,course):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return course.manager == user.rower
|
return course.manager == user.rower
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_delete_logo(user,logo):
|
def can_delete_logo(user,logo):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return logo.user == user
|
return logo.user == user
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def can_change_race(user,race):
|
def can_change_race(user,race):
|
||||||
if user.is_anonymous:
|
if user.is_anonymous: # pragma: no cover
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return race.manager == user
|
return race.manager == user
|
||||||
|
|||||||
@@ -512,7 +512,7 @@ class gatewayresult():
|
|||||||
self.transaction = vtransaction()
|
self.transaction = vtransaction()
|
||||||
self.payment_method = vpayment_method()
|
self.payment_method = vpayment_method()
|
||||||
self.subscription = vsubscription()
|
self.subscription = vsubscription()
|
||||||
self.customer = customer()
|
self.customer = kwargs.pop('customer',customer())
|
||||||
|
|
||||||
def __unicode__():
|
def __unicode__():
|
||||||
return "mockedgatewayresult"
|
return "mockedgatewayresult"
|
||||||
@@ -526,12 +526,18 @@ class paypal_account():
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.subscriptions = [vsubscription(),vsubscription()]
|
self.subscriptions = [vsubscription(),vsubscription()]
|
||||||
|
|
||||||
|
class customercreateresult:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.customer = kwargs.pop('customer',customer())
|
||||||
|
self.is_success = kwargs.pop('is_success',True)
|
||||||
|
self.customer_id = 1
|
||||||
|
|
||||||
class customer():
|
class customer():
|
||||||
def find(*arg, **kwargs):
|
def find(*arg, **kwargs):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def create(*args, **kwargs):
|
def create(*args, **kwargs):
|
||||||
return gatewayresult(is_success=True)
|
return customercreateresult(is_success=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.credit_cards = [credit_card(),credit_card()]
|
self.credit_cards = [credit_card(),credit_card()]
|
||||||
@@ -650,7 +656,6 @@ class MockBraintreeGateway:
|
|||||||
|
|
||||||
|
|
||||||
def mocked_gateway(*args, **kwargs):
|
def mocked_gateway(*args, **kwargs):
|
||||||
|
|
||||||
return MockBraintreeGateway()
|
return MockBraintreeGateway()
|
||||||
|
|
||||||
|
|
||||||
@@ -912,6 +917,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
nktester = re.compile('.*?nkrowlink\.com')
|
nktester = re.compile('.*?nkrowlink\.com')
|
||||||
rp3tester = re.compile('.*?rp3rowing-app\.com')
|
rp3tester = re.compile('.*?rp3rowing-app\.com')
|
||||||
garmintester = re.compile('.*?garmin\.com')
|
garmintester = re.compile('.*?garmin\.com')
|
||||||
|
fakturoidtester = re.compile('.*?fakturoid\.cz')
|
||||||
|
|
||||||
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
||||||
c2importtester = re.compile(c2importregex)
|
c2importtester = re.compile(c2importregex)
|
||||||
@@ -1202,6 +1208,22 @@ def mocked_requests(*args, **kwargs):
|
|||||||
else:
|
else:
|
||||||
return MockResponse(c2workoutdata,200)
|
return MockResponse(c2workoutdata,200)
|
||||||
|
|
||||||
|
if fakturoidtester.match(args[0]):
|
||||||
|
if 'invoices' in args[0]:
|
||||||
|
response = {
|
||||||
|
'url':'aap',
|
||||||
|
'id':1,
|
||||||
|
}
|
||||||
|
return MockResponse(response,200)
|
||||||
|
|
||||||
|
response = [
|
||||||
|
{
|
||||||
|
'id':1,
|
||||||
|
'url':'aap',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return MockResponse(response,200)
|
||||||
|
|
||||||
return MockResponse(None,404)
|
return MockResponse(None,404)
|
||||||
|
|
||||||
class MockEmailMessage:
|
class MockEmailMessage:
|
||||||
|
|||||||
127
rowers/tests/test_braintree.py
Normal file
127
rowers/tests/test_braintree.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
#from __future__ import print_function
|
||||||
|
from .statements import *
|
||||||
|
nu = datetime.datetime.now()
|
||||||
|
|
||||||
|
|
||||||
|
import rowers
|
||||||
|
from rowers import dataprep
|
||||||
|
from rowers import tasks
|
||||||
|
from rowers import c2stuff
|
||||||
|
from rowers import stravastuff
|
||||||
|
import urllib
|
||||||
|
import json
|
||||||
|
|
||||||
|
from rowers.braintreestuff import *
|
||||||
|
|
||||||
|
class transaction:
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.amount = kwargs.get('amount',25)
|
||||||
|
|
||||||
|
class subscription:
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.id = kwargs.get('id',1)
|
||||||
|
self.transactions = [transaction(amount=25)]
|
||||||
|
self.billing_period_end_date = datetime.datetime.now()+datetime.timedelta(days=365)
|
||||||
|
|
||||||
|
class notification:
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.kind = kwargs.get('kind','subscription_charged_successfully')
|
||||||
|
self.subscription = subscription(id=1)
|
||||||
|
|
||||||
|
class mycustomer:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.id = kwargs.get('id',1)
|
||||||
|
|
||||||
|
class mycreatecustomer:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.customer = mycustomer(id=1)
|
||||||
|
self.is_success = True
|
||||||
|
self.customer_id = 1
|
||||||
|
|
||||||
|
class myupgraderesult:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.subscription = subscription()
|
||||||
|
self.is_success = True
|
||||||
|
|
||||||
|
class paymentmethod:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.token = 'aa'
|
||||||
|
|
||||||
|
class mypaymentmethod:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.is_success = True
|
||||||
|
self.payment_method = paymentmethod()
|
||||||
|
|
||||||
|
class BraintreeUnits(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.u = UserFactory()
|
||||||
|
|
||||||
|
self.r = Rower.objects.create(user=self.u,
|
||||||
|
birthdate=faker.profile()['birthdate'],
|
||||||
|
gdproptin=True,surveydone=True,
|
||||||
|
gdproptindate=timezone.now(),
|
||||||
|
rowerplan='coach',subscription_id=1)
|
||||||
|
|
||||||
|
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||||
|
workoutsbox.save()
|
||||||
|
failbox = Mailbox.objects.create(name='Failed')
|
||||||
|
failbox.save()
|
||||||
|
|
||||||
|
self.pp = PaidPlan.objects.create(price=0,paymentprocessor='braintree')
|
||||||
|
self.p2 = PaidPlan.objects.create(price=25,paymentprocessor='braintree')
|
||||||
|
|
||||||
|
|
||||||
|
@patch('rowers.fakturoid.requests.get',side_effect=mocked_requests)
|
||||||
|
@patch('rowers.fakturoid.requests.post',side_effect=mocked_requests)
|
||||||
|
@patch('rowers.braintreestuff.gateway', side_effect=MockBraintreeGateway)
|
||||||
|
def test_process_webhook(self,mock_get,mockpost,mocked_gateway):
|
||||||
|
n = notification()
|
||||||
|
res = process_webhook(n)
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
|
n = notification(kind='subscription_canceled')
|
||||||
|
res = process_webhook(n)
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
|
def test_create_customer(self):
|
||||||
|
with patch('rowers.braintreestuff.gateway') as mocked_gateway:
|
||||||
|
mocked_gateway.customer.create.return_value = mycreatecustomer()
|
||||||
|
self.r.customer_id = 0
|
||||||
|
self.r.save()
|
||||||
|
|
||||||
|
res = create_customer(self.r)
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
|
def test_update_subscription(self):
|
||||||
|
data = {
|
||||||
|
'plan':self.pp.id,
|
||||||
|
'payment_method_nonce':'aap',
|
||||||
|
'amount':24,
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch('rowers.braintreestuff.gateway') as mocked_gateway:
|
||||||
|
mocked_gateway.subscription.update.return_value = myupgraderesult()
|
||||||
|
success,amount = update_subscription(self.r,data)
|
||||||
|
self.assertTrue(success)
|
||||||
|
self.assertEqual(amount,25)
|
||||||
|
|
||||||
|
def test_create_subscription(self):
|
||||||
|
data = {
|
||||||
|
'plan':self.p2.id,
|
||||||
|
'payment_method_nonce':'aap',
|
||||||
|
'amount':24,
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch('rowers.braintreestuff.gateway') as mocked_gateway:
|
||||||
|
mocked_gateway.subscription.create.return_value = myupgraderesult()
|
||||||
|
mocked_gateway.payment_method.create.return_value = mypaymentmethod()
|
||||||
|
success,amount = create_subscription(self.r,data)
|
||||||
|
self.assertTrue(success)
|
||||||
|
self.assertEqual(amount,25)
|
||||||
@@ -450,7 +450,8 @@ class NKObjects(DjangoTestCase):
|
|||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
@patch('rowers.tasks.requests.get', side_effect=mocked_requests)
|
@patch('rowers.tasks.requests.get', side_effect=mocked_requests)
|
||||||
def test_handle_nk_get_workouts(self, mock_get):
|
@patch('rowers.tasks.requests.post', side_effect=mocked_requests)
|
||||||
|
def test_handle_nk_get_workouts(self, mock_get,mockpost):
|
||||||
with open('rowers/tests/testdata/nk_list.json','r') as f:
|
with open('rowers/tests/testdata/nk_list.json','r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
|||||||
@@ -204,12 +204,22 @@ class UserPreferencesTest(TestCase):
|
|||||||
'tr':170,
|
'tr':170,
|
||||||
'at':160,
|
'at':160,
|
||||||
'an':175,
|
'an':175,
|
||||||
'rest':50
|
'rest':50,
|
||||||
|
'hrrestname':'rest',
|
||||||
|
'hrut2name':'ut2',
|
||||||
|
'hrut1name':'ut1',
|
||||||
|
'hratname':'at',
|
||||||
|
'hrtrname':'tr',
|
||||||
|
'hranname':'an',
|
||||||
|
'hrmaxname':'max',
|
||||||
}
|
}
|
||||||
|
|
||||||
form = RowerForm(form_data)
|
form = RowerForm(form_data)
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
form = RowerHRZonesForm(form_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
url = '/rowers/me/preferences/'
|
url = '/rowers/me/preferences/'
|
||||||
|
|
||||||
response = self.c.get(url)
|
response = self.c.get(url)
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ def paidplans_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def billing_view(request):
|
def billing_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
if payments.is_existing_customer(r): # pragma: no cover
|
if payments.is_existing_customer(r): # pragma: no cover
|
||||||
@@ -89,7 +89,7 @@ def billing_view(request):
|
|||||||
message="This functionality requires a Coach or Self-Coach plan",
|
message="This functionality requires a Coach or Self-Coach plan",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def buy_trainingplan_view(request,id=0):
|
def buy_trainingplan_view(request,id=0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -97,10 +97,10 @@ def buy_trainingplan_view(request,id=0):
|
|||||||
|
|
||||||
plan = get_object_or_404(InstantPlan,pk=id)
|
plan = get_object_or_404(InstantPlan,pk=id)
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree':
|
if r.paymentprocessor != 'braintree': # pragma: no cover
|
||||||
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
||||||
|
|
||||||
if id == 0 or id is None:
|
if id == 0 or id is None: # pragma: no cover
|
||||||
messages.error(request,"There was an error accessing this plan")
|
messages.error(request,"There was an error accessing this plan")
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
@@ -111,7 +111,7 @@ def buy_trainingplan_view(request,id=0):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
billingaddressform = RowerBillingAddressForm(instance=r)
|
billingaddressform = RowerBillingAddressForm(instance=r)
|
||||||
form = InstantPlanSelectForm(request.POST)
|
form = InstantPlanSelectForm(request.POST)
|
||||||
if billingaddressform.is_valid():
|
if billingaddressform.is_valid(): # pragma: no cover
|
||||||
cd = billingaddressform.cleaned_data
|
cd = billingaddressform.cleaned_data
|
||||||
for attr, value in cd.items():
|
for attr, value in cd.items():
|
||||||
setattr(r, attr, value)
|
setattr(r, attr, value)
|
||||||
@@ -134,16 +134,16 @@ def buy_trainingplan_view(request,id=0):
|
|||||||
try:
|
try:
|
||||||
targetid = request.POST['target']
|
targetid = request.POST['target']
|
||||||
|
|
||||||
if targetid != '':
|
if targetid != '': # pragma: no cover
|
||||||
target = TrainingTarget.objects.get(id=int(targetid))
|
target = TrainingTarget.objects.get(id=int(targetid))
|
||||||
else:
|
else: # pragma: no cover
|
||||||
target = None
|
target = None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
target = None
|
target = None
|
||||||
|
|
||||||
if target and datechoice == 'target':
|
if target and datechoice == 'target': # pragma: no cover
|
||||||
enddate = target.date
|
enddate = target.date
|
||||||
elif datechoice == 'startdate':
|
elif datechoice == 'startdate': # pragma: no cover
|
||||||
enddate = startdate+datetime.timedelta(days=plan.duration)
|
enddate = startdate+datetime.timedelta(days=plan.duration)
|
||||||
else:
|
else:
|
||||||
startdate = enddate-datetime.timedelta(days=plan.duration)
|
startdate = enddate-datetime.timedelta(days=plan.duration)
|
||||||
@@ -177,13 +177,13 @@ def buy_trainingplan_view(request,id=0):
|
|||||||
message="This functionality requires a Coach or Self-Coach plan",
|
message="This functionality requires a Coach or Self-Coach plan",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def purchase_checkouts_view(request):
|
def purchase_checkouts_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST': # pragma: no cover
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
})
|
})
|
||||||
@@ -199,7 +199,7 @@ def purchase_checkouts_view(request):
|
|||||||
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+str(plan.uuid)
|
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+str(plan.uuid)
|
||||||
headers = {'Authorization':authorizationstring}
|
headers = {'Authorization':authorizationstring}
|
||||||
response = requests.get(url=url,headers=headers)
|
response = requests.get(url=url,headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200: # pragma: no cover
|
||||||
messages.error(request,"Could not connect to the training plan server")
|
messages.error(request,"Could not connect to the training plan server")
|
||||||
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
||||||
|
|
||||||
@@ -233,13 +233,13 @@ def purchase_checkouts_view(request):
|
|||||||
url = url+'?when='+timeperiod
|
url = url+'?when='+timeperiod
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was a problem with your payment")
|
messages.error(request,"There was a problem with your payment")
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
})
|
})
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
elif 'tac' not in request.POST:
|
elif 'tac' not in request.POST: # pragma: no cover
|
||||||
try:
|
try:
|
||||||
planid=int(request.POST['plan'])
|
planid=int(request.POST['plan'])
|
||||||
enddate = request.POST['enddate']
|
enddate = request.POST['enddate']
|
||||||
@@ -250,19 +250,19 @@ def purchase_checkouts_view(request):
|
|||||||
url = reverse("purchase_checkouts_view")
|
url = reverse("purchase_checkouts_view")
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
url = reverse('rower_select_instantplan')
|
url = reverse('rower_select_instantplan') # pragma: no cover
|
||||||
if 'plan' in request.POST:
|
if 'plan' in request.POST: # pragma: no cover
|
||||||
plan = plan = InstantPlan.objects.get(id=request.POST['plan'])
|
plan = plan = InstantPlan.objects.get(id=request.POST['plan'])
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
})
|
})
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url) # pragma: no cover
|
||||||
|
|
||||||
@user_passes_test(can_plan,login_url="/rowers/paidplans",
|
@user_passes_test(can_plan,login_url="/rowers/paidplans",
|
||||||
message="This functionality requires a Coach or Self-Coach plan",
|
message="This functionality requires a Coach or Self-Coach plan",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def confirm_trainingplan_purchase_view(request,id = 0):
|
def confirm_trainingplan_purchase_view(request,id = 0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -270,10 +270,10 @@ def confirm_trainingplan_purchase_view(request,id = 0):
|
|||||||
|
|
||||||
plan = get_object_or_404(InstantPlan,pk=id)
|
plan = get_object_or_404(InstantPlan,pk=id)
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree':
|
if r.paymentprocessor != 'braintree': # pragma: no cover
|
||||||
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
||||||
|
|
||||||
if id == 0 or id is None:
|
if id == 0 or id is None: # pragma: no cover
|
||||||
messages.error(request,"There was an error accessing this plan")
|
messages.error(request,"There was an error accessing this plan")
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
@@ -287,7 +287,7 @@ def confirm_trainingplan_purchase_view(request,id = 0):
|
|||||||
name = request.GET.get('name','')
|
name = request.GET.get('name','')
|
||||||
status = request.GET.get('status',True)
|
status = request.GET.get('status',True)
|
||||||
notes = request.GET.get('notes','')
|
notes = request.GET.get('notes','')
|
||||||
if enddate is None:
|
if enddate is None: # pragma: no cover
|
||||||
messages.error(request,"There was an error accessing this plan")
|
messages.error(request,"There was an error accessing this plan")
|
||||||
url = reverse('rower_view_instantplan',kwargs={
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
'id':plan.uuid,
|
'id':plan.uuid,
|
||||||
@@ -307,16 +307,16 @@ def confirm_trainingplan_purchase_view(request,id = 0):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def upgrade_view(request):
|
def upgrade_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
if r.subscription_id is None or r.subscription_id == '':
|
if r.subscription_id is None or r.subscription_id == '': # pragma: no cover
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -352,16 +352,16 @@ def upgrade_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def downgrade_view(request):
|
def downgrade_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
if r.subscription_id is None or r.subscription_id == '':
|
if r.subscription_id is None or r.subscription_id == '': # pragma: no cover
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -378,9 +378,9 @@ def downgrade_view(request):
|
|||||||
if planselectform.is_valid():
|
if planselectform.is_valid():
|
||||||
plan = planselectform.cleaned_data['plan']
|
plan = planselectform.cleaned_data['plan']
|
||||||
|
|
||||||
if plan.price > r.paidplan.price:
|
if plan.price > r.paidplan.price: # pragma: no cover
|
||||||
nextview = upgrade_confirm_view
|
nextview = upgrade_confirm_view
|
||||||
elif plan.price == r.paidplan.price:
|
elif plan.price == r.paidplan.price: # pragma: no cover
|
||||||
messages.info(request,'You did not select a new plan')
|
messages.info(request,'You did not select a new plan')
|
||||||
url = reverse(downgrade_view)
|
url = reverse(downgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
@@ -409,7 +409,7 @@ def downgrade_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def plan_stop_view(request):
|
def plan_stop_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -417,13 +417,13 @@ def plan_stop_view(request):
|
|||||||
|
|
||||||
subscriptions = []
|
subscriptions = []
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
if r.paidplan is not None and r.paidplan.paymentprocessor == 'braintree':
|
if r.paidplan is not None and r.paidplan.paymentprocessor == 'braintree':
|
||||||
try:
|
try:
|
||||||
subscriptions = braintreestuff.find_subscriptions(r)
|
subscriptions = braintreestuff.find_subscriptions(r)
|
||||||
except ProcessorCustomerError:
|
except ProcessorCustomerError: # pragma: no cover
|
||||||
r.paymentprocessor = None
|
r.paymentprocessor = None
|
||||||
r.save()
|
r.save()
|
||||||
|
|
||||||
@@ -437,13 +437,13 @@ def plan_stop_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def plan_tobasic_view(request,id=0):
|
def plan_tobasic_view(request,id=0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paidplan.paymentprocessor == 'braintree':
|
if r.paidplan.paymentprocessor == 'braintree': # pragma: no cover
|
||||||
success, themessages,errormessages = braintreestuff.cancel_subscription(r,id)
|
success, themessages,errormessages = braintreestuff.cancel_subscription(r,id)
|
||||||
for message in themessages:
|
for message in themessages:
|
||||||
messages.info(request,message)
|
messages.info(request,message)
|
||||||
@@ -459,20 +459,20 @@ def plan_tobasic_view(request,id=0):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def upgrade_confirm_view(request,planid = 0):
|
def upgrade_confirm_view(request,planid = 0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
plan = PaidPlan.objects.get(id=planid)
|
plan = PaidPlan.objects.get(id=planid)
|
||||||
except PaidPlan.DoesNotExist:
|
except PaidPlan.DoesNotExist: # pragma: no cover
|
||||||
messages.error(request,"Something went wrong. Please try again.")
|
messages.error(request,"Something went wrong. Please try again.")
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
client_token = braintreestuff.get_client_token(r)
|
client_token = braintreestuff.get_client_token(r)
|
||||||
@@ -487,13 +487,13 @@ def upgrade_confirm_view(request,planid = 0):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def downgrade_confirm_view(request,planid = 0):
|
def downgrade_confirm_view(request,planid = 0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
plan = PaidPlan.objects.get(id=planid)
|
plan = PaidPlan.objects.get(id=planid)
|
||||||
except PaidPlan.DoesNotExist:
|
except PaidPlan.DoesNotExist: # pragma: no cover
|
||||||
messages.error(request,"Something went wrong. Please try again.")
|
messages.error(request,"Something went wrong. Please try again.")
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
@@ -513,20 +513,20 @@ def downgrade_confirm_view(request,planid = 0):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def payment_confirm_view(request,planid = 0):
|
def payment_confirm_view(request,planid = 0):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
plan = PaidPlan.objects.get(id=planid)
|
plan = PaidPlan.objects.get(id=planid)
|
||||||
except PaidPlan.DoesNotExist:
|
except PaidPlan.DoesNotExist: # pragma: no cover
|
||||||
messages.error(request,"Something went wrong. Please try again.")
|
messages.error(request,"Something went wrong. Please try again.")
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
client_token = braintreestuff.get_client_token(r)
|
client_token = braintreestuff.get_client_token(r)
|
||||||
@@ -542,17 +542,17 @@ def payment_confirm_view(request,planid = 0):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def checkouts_view(request):
|
def checkouts_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
|
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
|
||||||
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST': # pragma: no cover
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -566,11 +566,11 @@ def checkouts_view(request):
|
|||||||
baseurl = reverse(payment_completed_view),
|
baseurl = reverse(payment_completed_view),
|
||||||
amount = amount)
|
amount = amount)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was a problem with your payment")
|
messages.error(request,"There was a problem with your payment")
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
elif 'tac' not in request.POST:
|
elif 'tac' not in request.POST: # pragma: no cover
|
||||||
try:
|
try:
|
||||||
planid = int(request.POST['plan'])
|
planid = int(request.POST['plan'])
|
||||||
url = reverse('payment_confirm_view',kwargs={'planid':planid})
|
url = reverse('payment_confirm_view',kwargs={'planid':planid})
|
||||||
@@ -580,24 +580,24 @@ def checkouts_view(request):
|
|||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse('billing_view')
|
url = reverse('billing_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse(billing_view)
|
url = reverse(billing_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view) # pragma: no cover
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url) # pragma: no cover
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def upgrade_checkouts_view(request):
|
def upgrade_checkouts_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST': # pragma: no cover
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -611,12 +611,12 @@ def upgrade_checkouts_view(request):
|
|||||||
baseurl = reverse(payment_completed_view),
|
baseurl = reverse(payment_completed_view),
|
||||||
amount = amount)
|
amount = amount)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was a problem with your payment")
|
messages.error(request,"There was a problem with your payment")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
elif 'tac' not in request.POST:
|
elif 'tac' not in request.POST: # pragma: no cover
|
||||||
try:
|
try:
|
||||||
planid = int(request.POST['plan'])
|
planid = int(request.POST['plan'])
|
||||||
url = reverse('upgrade_confirm_view',kwargs={'planid':planid})
|
url = reverse('upgrade_confirm_view',kwargs={'planid':planid})
|
||||||
@@ -626,24 +626,24 @@ def upgrade_checkouts_view(request):
|
|||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse('billing_view')
|
url = reverse('billing_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view) # pragma: no cover
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url) # pragma: no cover
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def downgrade_checkouts_view(request):
|
def downgrade_checkouts_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
r = request.user.rower
|
r = request.user.rower
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST': # pragma: no cover
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -655,11 +655,11 @@ def downgrade_checkouts_view(request):
|
|||||||
messages.info(request,"Your plan has been updated")
|
messages.info(request,"Your plan has been updated")
|
||||||
url = reverse(downgrade_completed_view)
|
url = reverse(downgrade_completed_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was a problem with your transaction")
|
messages.error(request,"There was a problem with your transaction")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
elif 'tac' not in request.POST:
|
elif 'tac' not in request.POST: # pragma: no cover
|
||||||
try:
|
try:
|
||||||
planid = int(request.POST['plan'])
|
planid = int(request.POST['plan'])
|
||||||
url = reverse('downgrade_confirm_view',kwargs={'planid':planid})
|
url = reverse('downgrade_confirm_view',kwargs={'planid':planid})
|
||||||
@@ -670,18 +670,18 @@ def downgrade_checkouts_view(request):
|
|||||||
url = reverse('billing_view')
|
url = reverse('billing_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
else:
|
else: # pragma: no cover
|
||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
url = reverse(paidplans_view)
|
url = reverse(paidplans_view) # pragma: no cover
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url) # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def payment_completed_view(request):
|
def payment_completed_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -699,7 +699,7 @@ def payment_completed_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def downgrade_completed_view(request):
|
def downgrade_completed_view(request):
|
||||||
if not PAYMENT_PROCESSING_ON:
|
if not PAYMENT_PROCESSING_ON: # pragma: no cover
|
||||||
url = reverse('promembership')
|
url = reverse('promembership')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -716,7 +716,7 @@ from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
|||||||
from django.contrib.sites.shortcuts import get_current_site
|
from django.contrib.sites.shortcuts import get_current_site
|
||||||
from rowers.tokens import account_activation_token
|
from rowers.tokens import account_activation_token
|
||||||
# Email activation
|
# Email activation
|
||||||
def useractivate(request, uidb64, token):
|
def useractivate(request, uidb64, token): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
uid = force_text(urlsafe_base64_decode(uidb64))
|
uid = force_text(urlsafe_base64_decode(uidb64))
|
||||||
user = User.objects.get(id=uid)
|
user = User.objects.get(id=uid)
|
||||||
@@ -768,7 +768,7 @@ def useractivate(request, uidb64, token):
|
|||||||
def rower_register_view(request):
|
def rower_register_view(request):
|
||||||
|
|
||||||
nextpage = request.GET.get('next','/rowers/list-workouts/')
|
nextpage = request.GET.get('next','/rowers/list-workouts/')
|
||||||
if nextpage == '':
|
if nextpage == '': # pragma: no cover
|
||||||
nextpage = '/rowers/list-workouts/'
|
nextpage = '/rowers/list-workouts/'
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -848,7 +848,7 @@ def rower_register_view(request):
|
|||||||
return HttpResponseRedirect(nextpage)
|
return HttpResponseRedirect(nextpage)
|
||||||
# '/rowers/register/thankyou/')
|
# '/rowers/register/thankyou/')
|
||||||
|
|
||||||
else:
|
else: # pragma: no cover
|
||||||
return render(request,
|
return render(request,
|
||||||
"registration_form.html",
|
"registration_form.html",
|
||||||
{'form':form,
|
{'form':form,
|
||||||
@@ -861,10 +861,10 @@ def rower_register_view(request):
|
|||||||
'next':nextpage,})
|
'next':nextpage,})
|
||||||
|
|
||||||
# User registration
|
# User registration
|
||||||
def freecoach_register_view(request):
|
def freecoach_register_view(request): # pragma: no cover
|
||||||
|
|
||||||
nextpage = request.GET.get('next','/rowers/me/teams/')
|
nextpage = request.GET.get('next','/rowers/me/teams/')
|
||||||
if nextpage == '':
|
if nextpage == '': # pragma: no cover
|
||||||
nextpage = '/rowers/me/teams/'
|
nextpage = '/rowers/me/teams/'
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -924,7 +924,7 @@ def freecoach_register_view(request):
|
|||||||
|
|
||||||
return HttpResponseRedirect(nextpage)
|
return HttpResponseRedirect(nextpage)
|
||||||
|
|
||||||
else:
|
else: # pragma: no cover
|
||||||
return render(request,
|
return render(request,
|
||||||
"freecoach_registration_form.html",
|
"freecoach_registration_form.html",
|
||||||
{'form':form,
|
{'form':form,
|
||||||
@@ -941,7 +941,7 @@ def freecoach_register_view(request):
|
|||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
@permission_required('rower.is_staff',fn=get_user_by_userid,raise_exception=True)
|
@permission_required('rower.is_staff',fn=get_user_by_userid,raise_exception=True)
|
||||||
def transactions_view(request):
|
def transactions_view(request): # pragma: no cover
|
||||||
if not request.user.is_staff:
|
if not request.user.is_staff:
|
||||||
raise PermissionDenied("Not Allowed")
|
raise PermissionDenied("Not Allowed")
|
||||||
|
|
||||||
|
|||||||
@@ -1821,7 +1821,7 @@ def plannedsession_teamclone_view(request,id=0):
|
|||||||
startdate__lte = startdate,
|
startdate__lte = startdate,
|
||||||
rowers = r,
|
rowers = r,
|
||||||
enddate__gte = enddate)[0]
|
enddate__gte = enddate)[0]
|
||||||
except IndexError:
|
except IndexError: # pragma: no cover
|
||||||
trainingplan = None
|
trainingplan = None
|
||||||
|
|
||||||
ps = get_object_or_404(PlannedSession,pk=id)
|
ps = get_object_or_404(PlannedSession,pk=id)
|
||||||
|
|||||||
Reference in New Issue
Block a user