update financial verification to use requests repo
This commit is contained in:
parent
7f5f02985b
commit
78c55099bc
@ -107,7 +107,7 @@ def make_app(config, deps, **kwargs):
|
|||||||
RequestFinancialVerification,
|
RequestFinancialVerification,
|
||||||
{
|
{
|
||||||
"page": "financial_verification",
|
"page": "financial_verification",
|
||||||
"requests_client": deps["requests_client"],
|
"db_session": deps["db_session"],
|
||||||
"fundz_client": deps["fundz_client"],
|
"fundz_client": deps["fundz_client"],
|
||||||
},
|
},
|
||||||
name="financial_verification",
|
name="financial_verification",
|
||||||
|
@ -2,26 +2,23 @@ import tornado
|
|||||||
|
|
||||||
from atst.handler import BaseHandler
|
from atst.handler import BaseHandler
|
||||||
from atst.forms.financial import FinancialForm
|
from atst.forms.financial import FinancialForm
|
||||||
|
from atst.domain.requests import Requests
|
||||||
|
|
||||||
|
|
||||||
class RequestFinancialVerification(BaseHandler):
|
class RequestFinancialVerification(BaseHandler):
|
||||||
def initialize(self, page, requests_client, fundz_client):
|
def initialize(self, page, db_session, fundz_client):
|
||||||
self.page = page
|
self.page = page
|
||||||
self.requests_client = requests_client
|
self.requests_repo = Requests(db_session)
|
||||||
self.fundz_client = fundz_client
|
self.fundz_client = fundz_client
|
||||||
|
|
||||||
@tornado.gen.coroutine
|
|
||||||
def get_existing_request(self, request_id):
|
def get_existing_request(self, request_id):
|
||||||
if request_id is None:
|
return self.requests_repo.get(request_id)
|
||||||
return {}
|
|
||||||
request = yield self.requests_client.get("/requests/{}".format(request_id))
|
|
||||||
return request.json
|
|
||||||
|
|
||||||
@tornado.web.authenticated
|
@tornado.web.authenticated
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
def get(self, request_id=None):
|
def get(self, request_id=None):
|
||||||
existing_request = yield self.get_existing_request(request_id)
|
existing_request = self.get_existing_request(request_id)
|
||||||
form = FinancialForm(data=existing_request['body'].get('financial_verification'))
|
form = FinancialForm(data=existing_request.body.get('financial_verification'))
|
||||||
self.render(
|
self.render(
|
||||||
"requests/financial_verification.html.to",
|
"requests/financial_verification.html.to",
|
||||||
page=self.page,
|
page=self.page,
|
||||||
@ -35,39 +32,33 @@ class RequestFinancialVerification(BaseHandler):
|
|||||||
"creator_id": self.current_user["id"],
|
"creator_id": self.current_user["id"],
|
||||||
"request": {"financial_verification": form_data},
|
"request": {"financial_verification": form_data},
|
||||||
}
|
}
|
||||||
response = yield self.requests_client.patch(
|
return self.requests_repo.update(request_id, request_data)
|
||||||
"/requests/{}".format(request_id), json=request_data
|
|
||||||
)
|
|
||||||
return response
|
|
||||||
|
|
||||||
@tornado.web.authenticated
|
@tornado.web.authenticated
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
def post(self, request_id=None):
|
def post(self, request_id=None):
|
||||||
self.check_xsrf_cookie()
|
self.check_xsrf_cookie()
|
||||||
post_data = self.request.arguments
|
post_data = self.request.arguments
|
||||||
existing_request = yield self.get_existing_request(request_id)
|
existing_request = self.get_existing_request(request_id)
|
||||||
form = FinancialForm(post_data)
|
form = FinancialForm(post_data)
|
||||||
|
|
||||||
rerender_args = dict(request_id=request_id, f=form)
|
rerender_args = dict(request_id=request_id, f=form)
|
||||||
|
|
||||||
if form.validate():
|
if form.validate():
|
||||||
response = yield self.update_request(request_id, form.data)
|
yield self.update_request(request_id, form.data)
|
||||||
if response.ok:
|
valid = yield form.perform_extra_validation(
|
||||||
valid = yield form.perform_extra_validation(
|
existing_request.body.get('financial_verification'),
|
||||||
existing_request.get('body', {}).get('financial_verification'),
|
self.fundz_client
|
||||||
self.fundz_client
|
)
|
||||||
|
if valid:
|
||||||
|
self.redirect(
|
||||||
|
self.application.default_router.reverse_url("financial_verification_submitted")
|
||||||
)
|
)
|
||||||
if valid:
|
|
||||||
self.redirect(
|
|
||||||
self.application.default_router.reverse_url("financial_verification_submitted")
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.render(
|
|
||||||
"requests/financial_verification.html.to",
|
|
||||||
**rerender_args
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.set_status(response.code)
|
self.render(
|
||||||
|
"requests/financial_verification.html.to",
|
||||||
|
**rerender_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.render(
|
self.render(
|
||||||
"requests/financial_verification.html.to",
|
"requests/financial_verification.html.to",
|
||||||
|
@ -36,6 +36,7 @@ class TestPENumberInForm:
|
|||||||
"atst.handlers.request_financial_verification.RequestFinancialVerification.check_xsrf_cookie", lambda s: True
|
"atst.handlers.request_financial_verification.RequestFinancialVerification.check_xsrf_cookie", lambda s: True
|
||||||
)
|
)
|
||||||
monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
|
monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
|
||||||
|
monkeypatch.setattr("atst.domain.requests.Requests.get", lambda s, i: MOCK_REQUEST)
|
||||||
|
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
def submit_data(self, http_client, base_url, data):
|
def submit_data(self, http_client, base_url, data):
|
||||||
@ -64,7 +65,7 @@ class TestPENumberInForm:
|
|||||||
self._set_monkeypatches(monkeypatch)
|
self._set_monkeypatches(monkeypatch)
|
||||||
|
|
||||||
data = dict(self.required_data)
|
data = dict(self.required_data)
|
||||||
data['pe_id'] = MOCK_REQUEST['body']['financial_verification']['pe_id']
|
data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id']
|
||||||
|
|
||||||
response = yield self.submit_data(http_client, base_url, data)
|
response = yield self.submit_data(http_client, base_url, data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user