Skip to content

Commit

Permalink
Whitespace/isort fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwb27 committed Jul 24, 2021
1 parent 1a7a93b commit 89c1ddf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/labthings/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def preprocess(self, data, **_):

class ActionSchema(Schema):
"""Represents a running or completed Action
Actions can run in the background, started by one request
and subsequently polled for updates. This schema represents
one Action."""
Expand Down
2 changes: 1 addition & 1 deletion src/labthings/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from flask import request
from flask.views import MethodView
from typing_extensions import Protocol
from werkzeug.wrappers import Response as ResponseBase
from werkzeug.exceptions import HTTPException
from werkzeug.wrappers import Response as ResponseBase

from ..actions.pool import Pool
from ..deque import Deque
Expand Down
10 changes: 7 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,30 @@ def post(self, args):
pass

thing.add_view(TestFieldProperty, "/TestFieldProperty")

class FailAction(ActionView):
wait_for = 1.0

def post(self):
raise Exception("This action is meant to fail with an Exception")

thing.add_view(FailAction, "/FailAction")

class AbortAction(ActionView):
wait_for = 1.0

def post(self):
abort(418, "I'm a teapot! This action should abort with an HTTP code 418")

thing.add_view(AbortAction, "/AbortAction")

class ActionWithValidation(ActionView):
wait_for = 1.0
args = {"test_arg": fields.String(validate=validate.OneOf(["one", "two"]))}

def post(self):
return True

thing.add_view(ActionWithValidation, "/ActionWithValidation")

return thing
Expand Down
30 changes: 16 additions & 14 deletions tests/test_action_api.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
import pytest
import time
import json
import time

import pytest

from labthings import LabThing
from labthings.views import ActionView


@pytest.mark.filterwarnings("ignore:Exception in thread")
def test_action_exception_handling(thing_with_some_views, client):
"""Check errors in an Action are handled correctly
`/FieldProperty` has a validation constraint - it
should return a "bad response" error if invoked with
anything other than
anything other than
"""
# `/FailAction` raises an `Exception`.
# This ought to return a 201 code representing the
# action that was successfully started - but should
# `/FailAction` raises an `Exception`.
# This ought to return a 201 code representing the
# action that was successfully started - but should
# show that it failed through the "status" field.

# This is correct for the current (24/7/2021) behaviour
# but may want to change for the next version, e.g.
# but may want to change for the next version, e.g.
# returning a 500 code. For further discussion...
r = client.post("/FailAction")
assert r.status_code == 201
action = r.get_json()
assert action["status"] == "error"


def test_action_abort_and_validation(thing_with_some_views, client):
"""Check HTTPExceptions result in error codes.
Subclasses of HTTPError should result in a non-200 return code, not
just failures. This covers Marshmallow validation (400) and
use of `abort()`.
"""
# `/AbortAction` should return a 418 error code
r = client.post("/AbortAction")
assert r.status_code == 418



def test_action_validate(thing_with_some_views, client):
# `/ActionWithValidation` should fail with a 400 error
# if `test_arg` is not either `one` or `two`
r = client.post("/ActionWithValidation", data=json.dumps({"test_arg":"one"}))
r = client.post("/ActionWithValidation", data=json.dumps({"test_arg": "one"}))
assert r.status_code in [200, 201]
r = client.post("/ActionWithValidation", data=json.dumps({"test_arg":"three"}))
r = client.post("/ActionWithValidation", data=json.dumps({"test_arg": "three"}))
assert r.status_code in [422]


2 changes: 1 addition & 1 deletion tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from labthings.apispec import utilities
from labthings.extensions import BaseExtension
from labthings.schema import LogRecordSchema, Schema
from labthings.views import ActionView, EventView, PropertyView
from labthings.utilities import get_by_path
from labthings.views import ActionView, EventView, PropertyView


def test_openapi(thing_with_some_views):
Expand Down

0 comments on commit 89c1ddf

Please sign in to comment.