more coverage stuff
This commit is contained in:
@@ -512,7 +512,7 @@ class gatewayresult():
|
||||
self.transaction = vtransaction()
|
||||
self.payment_method = vpayment_method()
|
||||
self.subscription = vsubscription()
|
||||
self.customer = customer()
|
||||
self.customer = kwargs.pop('customer',customer())
|
||||
|
||||
def __unicode__():
|
||||
return "mockedgatewayresult"
|
||||
@@ -526,12 +526,18 @@ class paypal_account():
|
||||
def __init__(self, *args, **kwargs):
|
||||
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():
|
||||
def find(*arg, **kwargs):
|
||||
return self
|
||||
|
||||
def create(*args, **kwargs):
|
||||
return gatewayresult(is_success=True)
|
||||
return customercreateresult(is_success=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.credit_cards = [credit_card(),credit_card()]
|
||||
@@ -650,7 +656,6 @@ class MockBraintreeGateway:
|
||||
|
||||
|
||||
def mocked_gateway(*args, **kwargs):
|
||||
|
||||
return MockBraintreeGateway()
|
||||
|
||||
|
||||
@@ -912,6 +917,7 @@ def mocked_requests(*args, **kwargs):
|
||||
nktester = re.compile('.*?nkrowlink\.com')
|
||||
rp3tester = re.compile('.*?rp3rowing-app\.com')
|
||||
garmintester = re.compile('.*?garmin\.com')
|
||||
fakturoidtester = re.compile('.*?fakturoid\.cz')
|
||||
|
||||
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
||||
c2importtester = re.compile(c2importregex)
|
||||
@@ -1202,6 +1208,22 @@ def mocked_requests(*args, **kwargs):
|
||||
else:
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
@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:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
@@ -204,12 +204,22 @@ class UserPreferencesTest(TestCase):
|
||||
'tr':170,
|
||||
'at':160,
|
||||
'an':175,
|
||||
'rest':50
|
||||
'rest':50,
|
||||
'hrrestname':'rest',
|
||||
'hrut2name':'ut2',
|
||||
'hrut1name':'ut1',
|
||||
'hratname':'at',
|
||||
'hrtrname':'tr',
|
||||
'hranname':'an',
|
||||
'hrmaxname':'max',
|
||||
}
|
||||
|
||||
form = RowerForm(form_data)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
form = RowerHRZonesForm(form_data)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
url = '/rowers/me/preferences/'
|
||||
|
||||
response = self.c.get(url)
|
||||
|
||||
Reference in New Issue
Block a user