passing tests
This commit is contained in:
@@ -17,7 +17,7 @@ from rowers.tasks import (
|
|||||||
# handle_send_email_transaction_notification,
|
# handle_send_email_transaction_notification,
|
||||||
)
|
)
|
||||||
from rowers.utils import myqueue
|
from rowers.utils import myqueue
|
||||||
import rowers.fakturoid as fakturoid
|
import rowers.idoklad as idoklad
|
||||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||||
from braintree.exceptions.not_found_error import NotFoundError
|
from braintree.exceptions.not_found_error import NotFoundError
|
||||||
import time
|
import time
|
||||||
@@ -114,18 +114,18 @@ def send_invoice(subscription):
|
|||||||
else:
|
else:
|
||||||
r = rs[0]
|
r = rs[0]
|
||||||
dologging('braintreewebhooks.log','Rower '+str(r)+'\n')
|
dologging('braintreewebhooks.log','Rower '+str(r)+'\n')
|
||||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
idoklad_contact_id = idoklad.get_contacts(r)
|
||||||
dologging('braintreewebhooks.log','Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
dologging('braintreewebhooks.log','Idoklad Contact ID '+str(idoklad_contact_id)+'\n')
|
||||||
if not fakturoid_contact_id: # pragma: no cover
|
if not idoklad_contact_id: # pragma: no cover
|
||||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
idoklad_contact_id = idoklad.create_contact(r)
|
||||||
dologging('braintreewebhooks.log','Created Fakturoid Contact ID ' +
|
dologging('braintreewebhooks.log','Created Idoklad Contact ID ' +
|
||||||
str(fakturoid_contact_id)+'\n')
|
str(idoklad_contact_id)+'\n')
|
||||||
transactions = subscription.transactions
|
transactions = subscription.transactions
|
||||||
if transactions:
|
if transactions:
|
||||||
amount = transactions[0].amount
|
amount = transactions[0].amount
|
||||||
dologging('braintreewebhooks.log','Transaction amount '+str(amount)+'\n')
|
dologging('braintreewebhooks.log','Transaction amount '+str(amount)+'\n')
|
||||||
id = fakturoid.create_invoice(r, amount, subscription_id, dosend=True,
|
id = idoklad.create_invoice(r, amount, subscription_id, dosend=True,
|
||||||
contact_id=fakturoid_contact_id)
|
contact_id=idoklad_contact_id)
|
||||||
return id
|
return id
|
||||||
|
|
||||||
return 0 # pragma: no cover
|
return 0 # pragma: no cover
|
||||||
@@ -212,11 +212,13 @@ def make_payment(rower, data):
|
|||||||
l=rower.user.last_name,
|
l=rower.user.last_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
fakturoid_contact_id = fakturoid.get_contacts(rower)
|
idoklad_contact_id = idoklad.get_contacts(rower)
|
||||||
if not fakturoid_contact_id:
|
if not idoklad_contact_id:
|
||||||
fakturoid_contact_id = fakturoid.create_contact(rower)
|
idoklad_contact_id = idoklad.create_contact(rower)
|
||||||
_ = fakturoid.create_invoice(rower, amount, transaction.id, dosend=True, contact_id=fakturoid_contact_id,
|
|
||||||
name=additional_text)
|
_ = idoklad.create_invoice(rower, amount, transaction.id, dosend=True,
|
||||||
|
contact_id=idoklad_contact_id,
|
||||||
|
name=additional_text)
|
||||||
|
|
||||||
_ = myqueue(queuehigh, handle_send_email_transaction,
|
_ = myqueue(queuehigh, handle_send_email_transaction,
|
||||||
name, rower.user.email, amount)
|
name, rower.user.email, amount)
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ def get_contacts(rower):
|
|||||||
if res.status_code != 200: # pragma: no cover
|
if res.status_code != 200: # pragma: no cover
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
data = res.json()['Data']['Items']
|
data = res.json()['Data']['Items']
|
||||||
|
|
||||||
if len(data) >= 1:
|
if len(data) >= 1:
|
||||||
@@ -141,7 +140,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True, contact_id=None, nam
|
|||||||
|
|
||||||
token = idoklad_token()
|
token = idoklad_token()
|
||||||
if token is None:
|
if token is None:
|
||||||
return None
|
return 0
|
||||||
|
|
||||||
dologging('idoklad.log','Creating idoklad invoice for '+str(rower.user.email)+'\n')
|
dologging('idoklad.log','Creating idoklad invoice for '+str(rower.user.email)+'\n')
|
||||||
|
|
||||||
@@ -177,26 +176,29 @@ def create_invoice(rower, amount, braintreeid, dosend=True, contact_id=None, nam
|
|||||||
id = res.json()['Data']['Id']
|
id = res.json()['Data']['Id']
|
||||||
|
|
||||||
if dosend:
|
if dosend:
|
||||||
url = invoice_url+'/'+str(id)+'/Send'
|
|
||||||
print(url)
|
|
||||||
data = {
|
data = {
|
||||||
'AttachmentIds': [id],
|
'AttachmentIds': [],
|
||||||
'DocumentId': braintreeid,
|
'DocumentId': id,
|
||||||
'EmailBody': 'Dear customer, we are sending you the invoice for your subscription. Please do not hesitate to contact us if you have any questions. Best regards, Rowsandall Team',
|
'EmailBody': 'Dear customer, we are sending you the invoice for your subscription. Please do not hesitate to contact us if you have any questions. Best regards, Rowsandall Team',
|
||||||
'EmailSubject': 'Rowsandall Subscription Invoice',
|
'EmailSubject': 'Rowsandall Subscription Invoice',
|
||||||
'Method': 1,
|
'Method': 1,
|
||||||
'ReportLanguage': 3,
|
'ReportLanguage': 3,
|
||||||
'SendToSelf': True,
|
'SendToSelf': True,
|
||||||
|
'SendToPartner': True,
|
||||||
|
'SendToAccountant': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
print(data)
|
headers = {
|
||||||
print(email_url)
|
'Authorization': 'Bearer {access_token}'.format(access_token=token.access_token),
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
res = requests.post(email_url, json=data, headers=headers)
|
res = requests.post(email_url, json=data, headers=headers)
|
||||||
|
|
||||||
dologging('idoklad.log','Invoice Sent - status code '+str(res.status_code)+'\n')
|
dologging('idoklad.log','Invoice Sent - status code '+str(res.status_code)+'\n')
|
||||||
if res.status_code not in [200, 201]:
|
if res.status_code not in [200, 201]:
|
||||||
dologging('idoklad.log','Invoice Sent - reason '+str(res.reason)+'\n')
|
dologging('idoklad.log','Invoice Sent - reason '+str(res.text)+'\n')
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ from rowers.dataprep import delete_strokedata
|
|||||||
from redis import StrictRedis
|
from redis import StrictRedis
|
||||||
redis_connection = StrictRedis()
|
redis_connection = StrictRedis()
|
||||||
|
|
||||||
|
def mocked_idoklad_token(*args, **kwargs): # pragma: no cover
|
||||||
|
class MockToken:
|
||||||
|
def __init__(self, *args,**kwargs):
|
||||||
|
self.access_token = "aap"
|
||||||
|
|
||||||
|
return MockToken()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def mocked_grpc(*args, **kwargs): # pragma: no cover
|
def mocked_grpc(*args, **kwargs): # pragma: no cover
|
||||||
class insecure_channel:
|
class insecure_channel:
|
||||||
@@ -773,6 +781,9 @@ def mocked_requests(*args, **kwargs):
|
|||||||
with open('rowers/tests/testdata/rp3_list.json','r') as infile:
|
with open('rowers/tests/testdata/rp3_list.json','r') as infile:
|
||||||
rp3workoutlist = json.load(infile)
|
rp3workoutlist = json.load(infile)
|
||||||
|
|
||||||
|
with open('rowers/tests/testdata/idoklad_default.json','r') as infile:
|
||||||
|
idokladdefault = json.load(infile)
|
||||||
|
|
||||||
rp3linkready = {'data': {'download': {'id': 591621, 'status': 'ready', 'link': 'https://rp3rowing-app.com/api/workouts/591621/download?type=csv'}}}
|
rp3linkready = {'data': {'download': {'id': 591621, 'status': 'ready', 'link': 'https://rp3rowing-app.com/api/workouts/591621/download?type=csv'}}}
|
||||||
|
|
||||||
with open('rowers/tests/testdata/example-session-strokes-with-impeller-data.json','r') as infile:
|
with open('rowers/tests/testdata/example-session-strokes-with-impeller-data.json','r') as infile:
|
||||||
@@ -1117,6 +1128,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
rp3tester = re.compile(r'.*?rp3rowing-app\.com')
|
rp3tester = re.compile(r'.*?rp3rowing-app\.com')
|
||||||
garmintester = re.compile(r'.*?garmin\.com')
|
garmintester = re.compile(r'.*?garmin\.com')
|
||||||
fakturoidtester = re.compile(r'.*?fakturoid\.cz')
|
fakturoidtester = re.compile(r'.*?fakturoid\.cz')
|
||||||
|
idokladtester = re.compile(r'.*?idoklad\.cz')
|
||||||
|
|
||||||
polarlistregex = r'.*?polaraccesslink\.com\/.*\/(\d+)$'
|
polarlistregex = r'.*?polaraccesslink\.com\/.*\/(\d+)$'
|
||||||
polarlisttester = re.compile(polarlistregex)
|
polarlisttester = re.compile(polarlistregex)
|
||||||
@@ -1487,6 +1499,43 @@ def mocked_requests(*args, **kwargs):
|
|||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
return MockResponse(c2workoutdata,200)
|
return MockResponse(c2workoutdata,200)
|
||||||
|
|
||||||
|
|
||||||
|
if idokladtester.match(args[0]):
|
||||||
|
if 'Invoices' in args[0]:
|
||||||
|
if 'Default' in args[0]:
|
||||||
|
response_data = idokladdefault
|
||||||
|
|
||||||
|
return MockResponse(response_data,200)
|
||||||
|
|
||||||
|
response = {
|
||||||
|
'Data': {
|
||||||
|
'Id': 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MockResponse(response,200)
|
||||||
|
|
||||||
|
if 'Contacts' in args[0]:
|
||||||
|
response = {
|
||||||
|
'Data': {
|
||||||
|
'Items': [
|
||||||
|
{
|
||||||
|
'Id': 1,
|
||||||
|
'url':'aap',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MockResponse(response,200)
|
||||||
|
|
||||||
|
response = [
|
||||||
|
{
|
||||||
|
'Id':1,
|
||||||
|
'url':'aap',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return MockResponse(response, 200)
|
||||||
|
|
||||||
if fakturoidtester.match(args[0]):
|
if fakturoidtester.match(args[0]):
|
||||||
if 'invoices' in args[0]:
|
if 'invoices' in args[0]:
|
||||||
response = {
|
response = {
|
||||||
|
|||||||
@@ -74,11 +74,12 @@ class BraintreeUnits(TestCase):
|
|||||||
self.p2 = PaidPlan.objects.create(price=25,paymentprocessor='braintree')
|
self.p2 = PaidPlan.objects.create(price=25,paymentprocessor='braintree')
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.fakturoid.requests.get',side_effect=mocked_requests)
|
@patch('rowers.idoklad.idoklad_token', side_effect=mocked_idoklad_token)
|
||||||
@patch('rowers.fakturoid.requests.post',side_effect=mocked_requests)
|
@patch('rowers.idoklad.requests.get',side_effect=mocked_requests)
|
||||||
|
@patch('rowers.idoklad.requests.post',side_effect=mocked_requests)
|
||||||
@patch('rowers.braintreestuff.gateway', side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway', side_effect=MockBraintreeGateway)
|
||||||
@patch('rowers.braintreestuff.myqueue')
|
@patch('rowers.braintreestuff.myqueue')
|
||||||
def test_process_webhook(self,mock_get,mockpost,mocked_gateway,mocked_myqueue):
|
def test_process_webhook(self,mock_token, mock_get,mockpost,mocked_gateway,mocked_myqueue):
|
||||||
n = notification()
|
n = notification()
|
||||||
res = process_webhook(n)
|
res = process_webhook(n)
|
||||||
self.assertEqual(res,1)
|
self.assertEqual(res,1)
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ description: ""
|
|||||||
|
|
||||||
|
|
||||||
@patch('rowers.views.braintreestuff.gateway', side_effect=MockBraintreeGateway)
|
@patch('rowers.views.braintreestuff.gateway', side_effect=MockBraintreeGateway)
|
||||||
@patch('rowers.fakturoid.create_invoice',side_effect=mocked_invoiceid)
|
@patch('rowers.idoklad.create_invoice',side_effect=mocked_invoiceid)
|
||||||
@patch('rowers.utils.myqueue')
|
@patch('rowers.utils.myqueue')
|
||||||
def test_purchase_trainingplan_view(self, mocked_gateway,mocked_invoiceid, mocked_myqueue):
|
def test_purchase_trainingplan_view(self, mocked_gateway,mocked_invoiceid, mocked_myqueue):
|
||||||
u = UserFactory()
|
u = UserFactory()
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user