Skip to content

Commit

Permalink
Simplify / generalize the client API for updating model state. See #105.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead2 committed Dec 16, 2013
1 parent b0af069 commit 34fe903
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
18 changes: 3 additions & 15 deletions packages/slycat/web/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,9 @@ def create_model(self, pid, type, name, marking="", description=""):
def store_bookmark(self, pid, bookmark):
return self.post_project_bookmarks(pid, bookmark)

def set_model_state(self, mid, state):
"""Sets the current model state."""
self.put_model(mid, {"state": require_string(state)})

def set_model_result(self, mid, result):
"""Sets the current model result."""
self.put_model(mid, {"result": require_string(result)})

def set_model_progress(self, mid, progress):
"""Sets the current model progress."""
self.put_model(mid, {"progress": require_float(progress)})

def set_model_message(self, mid, message):
"""Sets the current model message."""
self.put_model(mid, {"message": require_string(message)})
def update_model(self, mid, **kwargs):
"""Updates the model state/result/progress/message."""
self.put_model(mid, kwargs)

def store_parameter(self, mid, name, value, input=True):
"""Sets a model parameter value."""
Expand Down
26 changes: 13 additions & 13 deletions web-server/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,23 @@ def test_model_state():
nose.tools.assert_equal(model["state"], "waiting")

with nose.tools.assert_raises(requests.HTTPError):
connection.set_model_state(mid, "bull")
connection.update_model(mid, state="bull")

with nose.tools.assert_raises(requests.HTTPError):
connection.set_model_state(mid, "finished")
connection.update_model(mid, state="finished")

connection.set_model_state(mid, "running")
connection.update_model(mid, state="running")
model = connection.get_model(mid)
nose.tools.assert_equal(model["state"], "running")

with nose.tools.assert_raises(requests.HTTPError):
connection.set_model_state(mid, "closed")
connection.update_model(mid, state="closed")

connection.set_model_state(mid, "finished")
connection.update_model(mid, state="finished")
model = connection.get_model(mid)
nose.tools.assert_equal(model["state"], "finished")

connection.set_model_state(mid, "closed")
connection.update_model(mid, state="closed")
model = connection.get_model(mid)
nose.tools.assert_equal(model["state"], "closed")

Expand All @@ -184,14 +184,14 @@ def test_model_result():
nose.tools.assert_equal(model.get("result"), None)

with nose.tools.assert_raises(requests.HTTPError):
connection.set_model_result(mid, "bull")
connection.update_model(mid, result="bull")

connection.set_model_result(mid, "succeeded")
connection.update_model(mid, result="succeeded")
model = connection.get_model(mid)
nose.tools.assert_equal(model["result"], "succeeded")

with nose.tools.assert_raises(requests.HTTPError):
connection.set_model_result(mid, "failed")
connection.update_model(mid, result="failed")

connection.delete_model(mid)
connection.delete_project(pid)
Expand All @@ -203,11 +203,11 @@ def test_model_progress():
model = connection.get_model(mid)
nose.tools.assert_equal(model.get("progress", None), None)

connection.set_model_progress(mid, 0.0)
connection.update_model(mid, progress=0.0)
model = connection.get_model(mid)
nose.tools.assert_equal(model["progress"], 0.0)

connection.set_model_progress(mid, 1.0)
connection.update_model(mid, progress=1.0)
model = connection.get_model(mid)
nose.tools.assert_equal(model["progress"], 1.0)

Expand All @@ -221,11 +221,11 @@ def test_model_message():
model = connection.get_model(mid)
nose.tools.assert_equal(model.get("message", None), None)

connection.set_model_message(mid, "test 1")
connection.update_model(mid, message="test 1")
model = connection.get_model(mid)
nose.tools.assert_equal(model["message"], "test 1")

connection.set_model_message(mid, "test 2")
connection.update_model(mid, message="test 2")
model = connection.get_model(mid)
nose.tools.assert_equal(model["message"], "test 2")

Expand Down

0 comments on commit 34fe903

Please sign in to comment.