From 7f5f02985b2ba3f35f0bd613155c667934eefa8a Mon Sep 17 00:00:00 2001 From: dandds Date: Fri, 27 Jul 2018 15:15:44 -0400 Subject: [PATCH] update and fix some tests from rebase --- atst/handlers/request_new.py | 1 + script/update | 7 +++-- tests/handlers/test_financial_verification.py | 2 +- tests/handlers/test_request_new.py | 1 - tests/handlers/test_request_submit.py | 30 ++++++++++++------- tests/mocks.py | 9 ++++++ 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/atst/handlers/request_new.py b/atst/handlers/request_new.py index 49454874..e43e6ab3 100644 --- a/atst/handlers/request_new.py +++ b/atst/handlers/request_new.py @@ -6,6 +6,7 @@ from atst.forms.request import RequestForm from atst.forms.org import OrgForm from atst.forms.poc import POCForm from atst.forms.review import ReviewForm +from atst.domain.requests import Requests class RequestNew(BaseHandler): diff --git a/script/update b/script/update index 8cb772c1..1baef9a8 100755 --- a/script/update +++ b/script/update @@ -4,5 +4,8 @@ source "$(dirname "${0}")"/../script/include/global_header.inc.sh -# Run the bootstrap script -source ./script/bootstrap +# Enable DB migration +MIGRATE_DB="true" + +# Run the shared update script +source ./script/include/run_update diff --git a/tests/handlers/test_financial_verification.py b/tests/handlers/test_financial_verification.py index 6e60bb4e..234c8d57 100644 --- a/tests/handlers/test_financial_verification.py +++ b/tests/handlers/test_financial_verification.py @@ -40,7 +40,7 @@ class TestPENumberInForm: @tornado.gen.coroutine def submit_data(self, http_client, base_url, data): response = yield http_client.fetch( - base_url + "/requests/verify/{}".format(MOCK_REQUEST["id"]), + base_url + "/requests/verify/{}".format(MOCK_REQUEST.id), method="POST", headers={"Content-Type": "application/x-www-form-urlencoded"}, body=urllib.parse.urlencode(data), diff --git a/tests/handlers/test_request_new.py b/tests/handlers/test_request_new.py index 8409fc13..3373c867 100644 --- a/tests/handlers/test_request_new.py +++ b/tests/handlers/test_request_new.py @@ -3,7 +3,6 @@ import pytest import tornado import urllib from tests.mocks import MOCK_USER -from tests.factories import RequestFactory ERROR_CLASS = "alert--error" MOCK_REQUEST = RequestFactory.create( diff --git a/tests/handlers/test_request_submit.py b/tests/handlers/test_request_submit.py index 0f60c1a1..635ff157 100644 --- a/tests/handlers/test_request_submit.py +++ b/tests/handlers/test_request_submit.py @@ -1,19 +1,26 @@ import pytest +import tornado from tests.mocks import MOCK_USER +from tests.factories import RequestFactory + + +@tornado.gen.coroutine +def _mock_func(*args, **kwargs): + return RequestFactory.create() -ERROR_CLASS = "usa-input-error-message" -APPROVED_MOCK_REQUEST = { - "status": "approved" -} @pytest.mark.gen_test def test_submit_reviewed_request(monkeypatch, http_client, base_url): monkeypatch.setattr( - "atst.handlers.request_submit.RequestsSubmit.get_current_user", lambda s: MOCK_USER + "atst.handlers.request_submit.RequestsSubmit.get_current_user", + lambda s: MOCK_USER, ) monkeypatch.setattr( "atst.handlers.request_submit.RequestsSubmit.check_xsrf_cookie", lambda s: True ) + monkeypatch.setattr("atst.domain.requests.Requests.get", _mock_func) + monkeypatch.setattr("atst.domain.requests.Requests.submit", _mock_func) + monkeypatch.setattr("atst.models.request.Request.status", "pending") # this just needs to send a known invalid form value response = yield http_client.fetch( base_url + "/requests/submit/1", @@ -21,7 +28,7 @@ def test_submit_reviewed_request(monkeypatch, http_client, base_url): headers={"Content-Type": "application/x-www-form-urlencoded"}, body="", raise_error=False, - follow_redirects=False + follow_redirects=False, ) assert response.headers["Location"] == "/requests" @@ -29,14 +36,15 @@ def test_submit_reviewed_request(monkeypatch, http_client, base_url): @pytest.mark.gen_test def test_submit_autoapproved_reviewed_request(monkeypatch, http_client, base_url): monkeypatch.setattr( - "atst.handlers.request_submit.RequestsSubmit.get_current_user", lambda s: MOCK_USER + "atst.handlers.request_submit.RequestsSubmit.get_current_user", + lambda s: MOCK_USER, ) monkeypatch.setattr( "atst.handlers.request_submit.RequestsSubmit.check_xsrf_cookie", lambda s: True ) - monkeypatch.setattr( - "tests.mocks.MOCK_REQUEST", APPROVED_MOCK_REQUEST - ) + monkeypatch.setattr("atst.domain.requests.Requests.get", _mock_func) + monkeypatch.setattr("atst.domain.requests.Requests.submit", _mock_func) + monkeypatch.setattr("atst.models.request.Request.status", "approved") # this just needs to send a known invalid form value response = yield http_client.fetch( base_url + "/requests/submit/1", @@ -44,6 +52,6 @@ def test_submit_autoapproved_reviewed_request(monkeypatch, http_client, base_url headers={"Content-Type": "application/x-www-form-urlencoded"}, body="", raise_error=False, - follow_redirects=False + follow_redirects=False, ) assert response.headers["Location"] == "/requests?modal=True" diff --git a/tests/mocks.py b/tests/mocks.py index 105824f7..96c22e4a 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -2,6 +2,7 @@ import tornado.gen from tornado.httpclient import HTTPRequest, HTTPResponse from atst.api_client import ApiClient +from tests.factories import RequestFactory MOCK_USER = { @@ -10,6 +11,14 @@ MOCK_USER = { "first_name": "Fake", "last_name": "User", } +MOCK_REQUEST = RequestFactory.create( + creator=MOCK_USER["id"], + body={ + "financial_verification": { + "pe_id": "0203752A", + }, + } +) class MockApiClient(ApiClient):