update and fix some tests from rebase

This commit is contained in:
dandds 2018-07-27 15:15:44 -04:00
parent 84c228ec2e
commit 7f5f02985b
6 changed files with 35 additions and 15 deletions

View File

@ -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):

View File

@ -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

View File

@ -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),

View File

@ -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(

View File

@ -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"

View File

@ -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):