Skip to content

Commit

Permalink
Removed tests for deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Sep 4, 2020
1 parent cac9add commit cd85859
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 442 deletions.
2 changes: 1 addition & 1 deletion src/labthings/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def description_from_view(view_class):
summary = get_summary(view_class)

methods = []
for method_key in http_method_funcs:
for method_key in ("get", "post", "put"):
if hasattr(view_class, method_key):
methods.append(method_key.upper())

Expand Down
23 changes: 22 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from labthings import LabThing
from labthings.actions import Pool
from labthings.json import encode_json
from labthings.views import View
from labthings.views import View, ActionView, PropertyView


class Helpers:
Expand Down Expand Up @@ -190,6 +190,27 @@ def delete(self):
return ViewClass


@pytest.fixture
def action_view_cls():
class ActionViewClass(ActionView):
def post(self):
return "POST"

return ActionViewClass


@pytest.fixture
def property_view_cls():
class PropertyViewClass(PropertyView):
def get(self):
return "GET"

def put(self):
return "PUT"

return PropertyViewClass


@pytest.fixture
def spec():
return APISpec(
Expand Down
46 changes: 0 additions & 46 deletions tests/test_apispec_apispec.py

This file was deleted.

20 changes: 0 additions & 20 deletions tests/test_apispec_converter.py

This file was deleted.

143 changes: 0 additions & 143 deletions tests/test_apispec_utilities.py

This file was deleted.

57 changes: 0 additions & 57 deletions tests/test_default_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,60 +91,3 @@ def task_func():
def test_action_kill_missing(thing_client):
with thing_client as c:
assert c.delete("/actions/missing_id").status_code == 404


### DEPRECATED: LEGACY TASK VIEW


def test_tasks_list(thing_client):
def task_func():
pass

task_obj = current_labthing().actions.spawn(task_func)

with thing_client as c:
response = c.get("/tasks").json
ids = [task.get("id") for task in response]
assert str(task_obj.id) in ids


def test_task_representation(thing_client):
def task_func():
pass

task_obj = current_labthing().actions.spawn(task_func)
task_id = str(task_obj.id)

with thing_client as c:
response = c.get(f"/tasks/{task_id}").json
assert response


def test_task_representation_missing(thing_client):
with thing_client as c:
assert c.get("/tasks/missing_id").status_code == 404


def test_task_kill(thing_client):
def task_func():
while not current_action().stopping:
time.sleep(0)

task_obj = current_labthing().actions.spawn(task_func)
task_id = str(task_obj.id)

# Wait for task to start
task_obj.started.wait()
assert task_id in current_labthing().actions.to_dict()

# Send a DELETE request to terminate the task
with thing_client as c:
response = c.delete(f"/tasks/{task_id}")
assert response.status_code == 200
# Test task was stopped
assert task_obj._status == "stopped"


def test_task_kill_missing(thing_client):
with thing_client as c:
assert c.delete("/tasks/missing_id").status_code == 404
43 changes: 8 additions & 35 deletions tests/test_labthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ def test_init_types():
assert thing.types == types


def test_init_types_invalid():
types = ["org;labthings;test"]
with pytest.raises(ValueError):
LabThing(types=types)


def test_init_app(app):
thing = LabThing()
thing.init_app(app)
Expand Down Expand Up @@ -59,16 +53,16 @@ def get(self):
assert c.get("/index").data == b'"GET"\n'


def test_add_view_action(thing, view_cls, client):
view_cls.tags = ["actions"]
thing.add_view(view_cls, "/index", endpoint="index")
assert view_cls in thing._action_views.values()
def test_add_view_action(thing, action_view_cls, client):
action_view_cls.tags = ["actions"]
thing.add_view(action_view_cls, "/index", endpoint="index")
assert action_view_cls in thing._action_views.values()


def test_add_view_property(thing, view_cls, client):
view_cls.tags = ["properties"]
thing.add_view(view_cls, "/index", endpoint="index")
assert view_cls in thing._property_views.values()
def test_add_view_property(thing, property_view_cls, client):
property_view_cls.tags = ["properties"]
thing.add_view(property_view_cls, "/index", endpoint="index")
assert property_view_cls in thing._property_views.values()


def test_init_app_early_views(app, view_cls, client):
Expand Down Expand Up @@ -239,24 +233,3 @@ def test_version(thing):
thing.version = "x.x.x"
assert thing.version == "x.x.x"
assert thing.spec.version == "x.x.x"


def test_build_property(thing):
obj = type("obj", (object,), {"property_name": "propertyValue"})

thing.build_property(obj, "property_name")
# -1 index for last view added
# 1 index for URL tuple
assert "/properties/type/property_name" in thing.views[-1][1]


def test_build_action(thing):
def f():
return "response"

obj = type("obj", (object,), {"f": f})

thing.build_action(obj, "f")
# -1 index for last view added
# 1 index for URL tuple
assert "/actions/type/f" in thing.views[-1][1]
Loading

0 comments on commit cd85859

Please sign in to comment.