Skip to content

Commit

Permalink
fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jul 9, 2018
1 parent 424b0a9 commit 7237391
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 6 additions & 6 deletions abilian/services/vocabularies/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import sqlalchemy as sa
import sqlalchemy.exc
from hyperlink import URL
from pytest import mark, raises

from abilian.testing.util import path_from_url
from abilian.web import url_for

from .models import BaseVocabulary, Vocabulary
Expand Down Expand Up @@ -137,22 +137,22 @@ def test_admin_panel_reorder(app, db, session, client, test_request_context):
data.update(base_data)
r = client.post(url, data=data)
assert r.status_code == 302
assert URL.from_text(r.headers["Location"]).path == "/admin/vocabularies"
assert path_from_url(r.headers["Location"]) == "/admin/vocabularies"
assert Voc.query.order_by(Voc.position).all() == [second, first, third]

data = {"up": first.id, "return_to": "group"}
data.update(base_data)
r = client.post(url, data=data)
assert r.status_code == 302
assert URL.from_text(r.headers["Location"]).path == "/admin/vocabularies/_/"
assert path_from_url(r.headers["Location"]) == "/admin/vocabularies/_/"
assert Voc.query.order_by(Voc.position).all() == [first, second, third]

data = {"up": first.id, "return_to": "model"}
data.update(base_data)
r = client.post(url, data=data)
assert r.status_code == 302
assert (
URL.from_text(r.headers["Location"]).path
path_from_url(r.headers["Location"])
== "/admin/vocabularies/_/defaultstates/"
)
assert Voc.query.order_by(Voc.position).all() == [first, second, third]
Expand All @@ -161,12 +161,12 @@ def test_admin_panel_reorder(app, db, session, client, test_request_context):
data.update(base_data)
r = client.post(url, data=data)
assert r.status_code == 302
assert URL.from_text(r.headers["Location"]).path == "/admin/vocabularies"
assert path_from_url(r.headers["Location"]) == "/admin/vocabularies"
assert Voc.query.order_by(Voc.position).all() == [first, second, third]

data = {"up": third.id}
data.update(base_data)
r = client.post(url, data=data)
assert r.status_code == 302
assert URL.from_text(r.headers["Location"]).path == "/admin/vocabularies"
assert path_from_url(r.headers["Location"]) == "/admin/vocabularies"
assert Voc.query.order_by(Voc.position).all() == [first, third, second]
5 changes: 5 additions & 0 deletions abilian/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask.testing import FlaskClient
from flask_login import login_user, logout_user
from hyperlink import URL
from sqlalchemy.exc import DatabaseError

from abilian.core.models.subjects import User
Expand All @@ -19,6 +20,10 @@
)


def path_from_url(url):
return "/" + "/".join(URL.from_text(url).path)


def client_login(client, user):
# type: (FlaskClient, User) -> LoginContext

Expand Down
7 changes: 6 additions & 1 deletion abilian/testing/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

SKIPPED_PATHS = [
# FIXME: later
"/admin/settings"
("admin", "settings"),
]


Expand All @@ -21,6 +21,7 @@ class ValidationError(AssertionError):


def validate_response(response):
# type: (Response) -> Response
assert_valid(response)
return response

Expand Down Expand Up @@ -53,11 +54,13 @@ def assert_valid(response):


def assert_html_valid(response):
# type: (Response) -> None
assert_html_valid_using_htmlhint(response)
assert_html_valid_using_external_service(response)


def assert_html_valid_using_htmlhint(response):
# type: (Response) -> None
with NamedTemporaryFile() as tmpfile:
tmpfile.write(response.data)
tmpfile.flush()
Expand All @@ -71,6 +74,7 @@ def assert_html_valid_using_htmlhint(response):


def assert_html_valid_using_external_service(response):
# type: (Response) -> None
config = current_app.config
validator_url = config.get("VALIDATOR_URL") or os.environ.get("VALIDATOR_URL")

Expand All @@ -95,6 +99,7 @@ def assert_html_valid_using_external_service(response):


def assert_json_valid(response):
# type: (Response) -> None
try:
json.loads(response.data)
except BaseException:
Expand Down

0 comments on commit 7237391

Please sign in to comment.