remove fundz_client in favor of pe numbers repo

This commit is contained in:
dandds 2018-07-30 16:25:15 -04:00
parent fc535ea715
commit cb30ee99ca
6 changed files with 27 additions and 29 deletions

View File

@ -65,7 +65,6 @@ def make_app(config, deps, **kwargs):
{
"page": "requests_new",
"db_session": deps["db_session"],
"fundz_client": deps["fundz_client"],
},
name="request_new",
),
@ -75,7 +74,6 @@ def make_app(config, deps, **kwargs):
{
"page": "requests_new",
"db_session": deps["db_session"],
"fundz_client": deps["fundz_client"],
},
name="request_form_new",
),
@ -85,7 +83,6 @@ def make_app(config, deps, **kwargs):
{
"page": "requests_new",
"db_session": deps["db_session"],
"fundz_client": deps["fundz_client"],
},
name="request_form_update",
),
@ -108,7 +105,6 @@ def make_app(config, deps, **kwargs):
{
"page": "financial_verification",
"db_session": deps["db_session"],
"fundz_client": deps["fundz_client"],
},
name="financial_verification",
),
@ -172,9 +168,6 @@ def make_deps(config):
api_version="v1",
validate_cert=validate_cert,
),
"fundz_client": ApiClient(
config["default"]["FUNDZ_BASE_URL"], validate_cert=validate_cert
),
"sessions": RedisSessions(
redis_client, config["default"]["SESSION_TTL_SECONDS"]
),

View File

@ -6,6 +6,8 @@ from wtforms.fields import StringField, SelectField
from wtforms.form import Form
from wtforms.validators import Required, Email
from atst.domain.exceptions import NotFoundError
from .fields import NewlineListField
from .forms import ValidatedForm
@ -35,12 +37,10 @@ def suggest_pe_id(pe_id):
@tornado.gen.coroutine
def validate_pe_id(field, existing_request, fundz_client):
response = yield fundz_client.get(
"/pe-number/{}".format(field.data),
raise_error=False,
)
if not response.ok:
def validate_pe_id(field, existing_request, pe_numbers_repo):
try:
pe_number = pe_numbers_repo.get(field.data)
except NotFoundError:
suggestion = suggest_pe_id(field.data)
error_str = (
"We couldn't find that PE number. {}"
@ -56,10 +56,10 @@ def validate_pe_id(field, existing_request, fundz_client):
class FinancialForm(ValidatedForm):
@tornado.gen.coroutine
def perform_extra_validation(self, existing_request, fundz_client):
def perform_extra_validation(self, existing_request, pe_numbers_repo):
valid = True
if not existing_request or existing_request.get('pe_id') != self.pe_id.data:
valid = yield validate_pe_id(self.pe_id, existing_request, fundz_client)
valid = yield validate_pe_id(self.pe_id, existing_request, pe_numbers_repo)
raise Return(valid)
task_order_id = StringField(

View File

@ -3,13 +3,14 @@ import tornado
from atst.handler import BaseHandler
from atst.forms.financial import FinancialForm
from atst.domain.requests import Requests
from atst.domain.pe_numbers import PENumbers
class RequestFinancialVerification(BaseHandler):
def initialize(self, page, db_session, fundz_client):
def initialize(self, page, db_session):
self.page = page
self.requests_repo = Requests(db_session)
self.fundz_client = fundz_client
self.pe_numbers_repo = PENumbers(db_session)
def get_existing_request(self, request_id):
return self.requests_repo.get(request_id)
@ -48,7 +49,7 @@ class RequestFinancialVerification(BaseHandler):
yield self.update_request(request_id, form.data)
valid = yield form.perform_extra_validation(
existing_request.body.get('financial_verification'),
self.fundz_client
self.pe_numbers_repo
)
if valid:
self.redirect(

View File

@ -7,13 +7,14 @@ from atst.forms.org import OrgForm
from atst.forms.poc import POCForm
from atst.forms.review import ReviewForm
from atst.domain.requests import Requests
from atst.domain.pe_numbers import PENumbers
class RequestNew(BaseHandler):
def initialize(self, page, db_session, fundz_client):
def initialize(self, page, db_session):
self.page = page
self.requests_repo = Requests(db_session)
self.fundz_client = fundz_client
self.pe_numbers_repo = PENumbers(db_session)
def get_existing_request(self, request_id):
if request_id is None:
@ -31,7 +32,7 @@ class RequestNew(BaseHandler):
existing_request = self.get_existing_request(request_id)
jedi_flow = JEDIRequestFlow(
self.requests_repo,
self.fundz_client,
self.pe_numbers_repo,
screen,
post_data=post_data,
request_id=request_id,
@ -81,7 +82,7 @@ class RequestNew(BaseHandler):
request = self.requests_repo.get(request_id)
jedi_flow = JEDIRequestFlow(
self.requests_repo, self.fundz_client, screen, request, request_id=request_id
self.requests_repo, self.pe_numbers_repo, screen, request, request_id=request_id
)
self.render(
@ -101,7 +102,7 @@ class JEDIRequestFlow(object):
def __init__(
self,
requests_repo,
fundz_client,
pe_numbers_repo,
current_step,
request=None,
post_data=None,
@ -110,7 +111,7 @@ class JEDIRequestFlow(object):
existing_request=None,
):
self.requests_repo = requests_repo
self.fundz_client = fundz_client
self.pe_numbers_repo = pe_numbers_repo
self.current_step = current_step
self.request = request
@ -144,7 +145,7 @@ class JEDIRequestFlow(object):
valid = yield self.form.perform_extra_validation(
existing_request_data,
self.fundz_client,
self.pe_numbers_repo,
)
return valid

View File

@ -11,7 +11,6 @@ from atst.sessions import DictSessions
def app(db):
TEST_DEPS = {
"authnid_client": MockApiClient("authnid"),
"fundz_client": MockFundzClient("fundz"),
"sessions": DictSessions(),
"db_session": db
}

View File

@ -2,7 +2,8 @@ import re
import pytest
import tornado
import urllib
from tests.mocks import MOCK_REQUEST, MOCK_USER, MOCK_VALID_PE_ID
from tests.mocks import MOCK_REQUEST, MOCK_USER
from tests.factories import PENumberFactory
class TestPENumberInForm:
@ -73,11 +74,14 @@ class TestPENumberInForm:
assert response.headers.get("Location") == "/requests/financial_verification_submitted"
@pytest.mark.gen_test
def test_submit_request_form_with_new_valid_pe_id(self, monkeypatch, http_client, base_url):
def test_submit_request_form_with_new_valid_pe_id(self, db, monkeypatch, http_client, base_url):
self._set_monkeypatches(monkeypatch)
pe = PENumberFactory.create(number="8675309U", description="sample PE number")
db.add(pe)
db.commit()
data = dict(self.required_data)
data['pe_id'] = MOCK_VALID_PE_ID
data['pe_id'] = pe.number
response = yield self.submit_data(http_client, base_url, data)