Use black for formatting
This commit is contained in:
@@ -7,9 +7,9 @@ from tests.mocks import MockApiClient, MockRequestsClient
|
||||
@pytest.fixture
|
||||
def app():
|
||||
TEST_DEPS = {
|
||||
'authz_client': MockApiClient('authz'),
|
||||
'requests_client': MockRequestsClient('requests'),
|
||||
'authnid_client': MockApiClient('authnid'),
|
||||
"authz_client": MockApiClient("authz"),
|
||||
"requests_client": MockRequestsClient("requests"),
|
||||
"authnid_client": MockApiClient("authnid"),
|
||||
}
|
||||
|
||||
config = make_config()
|
||||
|
@@ -4,9 +4,11 @@ from atst.forms.request import RequestForm
|
||||
|
||||
form = RequestForm()
|
||||
|
||||
|
||||
def test_form_has_expected_fields():
|
||||
label = form.application_name.label
|
||||
assert label.text == 'Application name'
|
||||
assert label.text == "Application name"
|
||||
|
||||
|
||||
def test_form_can_validate_total_ram():
|
||||
form.application_name.data = 5
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import re
|
||||
import pytest
|
||||
|
||||
ERROR_CLASS = 'usa-input-error-message'
|
||||
ERROR_CLASS = "usa-input-error-message"
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_submit_invalid_request_form(monkeypatch, http_client, base_url):
|
||||
monkeypatch.setattr('atst.handlers.request_new.RequestNew.get_current_user', lambda s: True)
|
||||
monkeypatch.setattr('atst.handlers.request_new.RequestNew.check_xsrf_cookie', lambda s: True)
|
||||
monkeypatch.setattr(
|
||||
"atst.handlers.request_new.RequestNew.get_current_user", lambda s: True
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"atst.handlers.request_new.RequestNew.check_xsrf_cookie", lambda s: True
|
||||
)
|
||||
# this just needs to send a known invalid form value
|
||||
response = yield http_client.fetch(
|
||||
base_url + "/requests/new",
|
||||
@@ -15,15 +19,19 @@ def test_submit_invalid_request_form(monkeypatch, http_client, base_url):
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
||||
body="total_ram=5",
|
||||
)
|
||||
assert response.effective_url == base_url + '/requests/new'
|
||||
assert response.effective_url == base_url + "/requests/new"
|
||||
assert re.search(ERROR_CLASS, response.body.decode())
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_submit_valid_request_form(monkeypatch, http_client, base_url):
|
||||
monkeypatch.setattr('atst.handlers.request_new.RequestNew.get_current_user', lambda s: True)
|
||||
monkeypatch.setattr('atst.handlers.request_new.RequestNew.check_xsrf_cookie', lambda s: True)
|
||||
monkeypatch.setattr('atst.forms.request.RequestForm.validate', lambda s: True)
|
||||
monkeypatch.setattr(
|
||||
"atst.handlers.request_new.RequestNew.get_current_user", lambda s: True
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"atst.handlers.request_new.RequestNew.check_xsrf_cookie", lambda s: True
|
||||
)
|
||||
monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
|
||||
|
||||
# this just needs to send a known invalid form value
|
||||
response = yield http_client.fetch(
|
||||
@@ -32,4 +40,4 @@ def test_submit_valid_request_form(monkeypatch, http_client, base_url):
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
||||
body="meaning=42",
|
||||
)
|
||||
assert '/requests/new/2' in response.effective_url
|
||||
assert "/requests/new/2" in response.effective_url
|
||||
|
@@ -10,33 +10,34 @@ class MockApiClient(ApiClient):
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def get(self, path, **kwargs):
|
||||
return self._get_response('GET', path)
|
||||
return self._get_response("GET", path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def put(self, path, **kwargs):
|
||||
return self._get_response('PUT', path)
|
||||
return self._get_response("PUT", path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def patch(self, path, **kwargs):
|
||||
return self._get_response('PATCH', path)
|
||||
return self._get_response("PATCH", path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self, path, **kwargs):
|
||||
return self._get_response('POST', path)
|
||||
return self._get_response("POST", path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def delete(self, path, **kwargs):
|
||||
return self._get_response('DELETE', path)
|
||||
return self._get_response("DELETE", path)
|
||||
|
||||
def _get_response(self, verb, path, code=200, json=None):
|
||||
response = HTTPResponse(
|
||||
request=HTTPRequest(path, verb),
|
||||
code=code,
|
||||
headers={'Content-Type': 'application/json'})
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
setattr(response, 'ok', 200 <= code < 300)
|
||||
setattr(response, "ok", 200 <= code < 300)
|
||||
if json:
|
||||
setattr(response, 'json', json)
|
||||
setattr(response, "json", json)
|
||||
|
||||
return response
|
||||
|
||||
@@ -45,18 +46,17 @@ class MockRequestsClient(MockApiClient):
|
||||
@tornado.gen.coroutine
|
||||
def get(self, path, **kwargs):
|
||||
json = {
|
||||
'id': '66b8ef71-86d3-48ef-abc2-51bfa1732b6b',
|
||||
'creator': '49903ae7-da4a-49bf-a6dc-9dff5d004238',
|
||||
'body': {}
|
||||
"id": "66b8ef71-86d3-48ef-abc2-51bfa1732b6b",
|
||||
"creator": "49903ae7-da4a-49bf-a6dc-9dff5d004238",
|
||||
"body": {},
|
||||
}
|
||||
return self._get_response('GET', path, 200, json=json)
|
||||
return self._get_response("GET", path, 200, json=json)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self, path, **kwargs):
|
||||
json = {
|
||||
'id': '66b8ef71-86d3-48ef-abc2-51bfa1732b6b',
|
||||
'creator': '49903ae7-da4a-49bf-a6dc-9dff5d004238',
|
||||
'body': {}
|
||||
"id": "66b8ef71-86d3-48ef-abc2-51bfa1732b6b",
|
||||
"creator": "49903ae7-da4a-49bf-a6dc-9dff5d004238",
|
||||
"body": {},
|
||||
}
|
||||
return self._get_response('POST', path, 202, json=json)
|
||||
|
||||
return self._get_response("POST", path, 202, json=json)
|
||||
|
@@ -6,5 +6,5 @@ from atst.api_client import ApiClient
|
||||
@pytest.mark.gen_test
|
||||
def test_api_client(http_client, base_url):
|
||||
client = ApiClient(base_url)
|
||||
response = yield client.get('')
|
||||
response = yield client.get("")
|
||||
assert response.code == 200
|
||||
|
@@ -9,10 +9,10 @@ def test_redirects_when_not_logged_in(http_client, base_url):
|
||||
response = yield http_client.fetch(
|
||||
base_url + "/home", raise_error=False, follow_redirects=False
|
||||
)
|
||||
location = response.headers['Location']
|
||||
location = response.headers["Location"]
|
||||
assert response.code == 302
|
||||
assert response.error
|
||||
assert re.match('/\??', location)
|
||||
assert re.match("/\??", location)
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
@@ -22,16 +22,15 @@ def test_login_with_valid_bearer_token(app, monkeypatch, http_client, base_url):
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(
|
||||
"atst.handlers.login.Login._validate_login_token",
|
||||
_validate_login_token
|
||||
"atst.handlers.login.Login._validate_login_token", _validate_login_token
|
||||
)
|
||||
response = yield http_client.fetch(
|
||||
base_url + "/login?bearer-token=abc-123",
|
||||
follow_redirects=False,
|
||||
raise_error=False
|
||||
raise_error=False,
|
||||
)
|
||||
assert response.headers["Set-Cookie"].startswith("atst")
|
||||
assert response.headers['Location'] == '/home'
|
||||
assert response.headers["Location"] == "/home"
|
||||
assert response.code == 302
|
||||
|
||||
|
||||
|
@@ -4,15 +4,15 @@ import pytest
|
||||
@pytest.mark.gen_test
|
||||
def test_routes(http_client, base_url):
|
||||
for path in (
|
||||
'/',
|
||||
'/home',
|
||||
'/workspaces',
|
||||
'/requests',
|
||||
'/requests/new',
|
||||
'/requests/new/1',
|
||||
'/users',
|
||||
'/reports',
|
||||
'/calculator'
|
||||
):
|
||||
"/",
|
||||
"/home",
|
||||
"/workspaces",
|
||||
"/requests",
|
||||
"/requests/new",
|
||||
"/requests/new/1",
|
||||
"/users",
|
||||
"/reports",
|
||||
"/calculator",
|
||||
):
|
||||
response = yield http_client.fetch(base_url + path)
|
||||
assert response.code == 200
|
||||
|
Reference in New Issue
Block a user