Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions remoteappmanager/webapi/admin/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Accounting(Resource):
__collection_name__ = "accounting"

def validate(self, representation):
def validate_representation(self, representation):
representation["user_name"] = _not_empty_str(
representation["user_name"])
representation["image_name"] = _not_empty_str(
Expand All @@ -23,6 +23,7 @@ def validate(self, representation):
representation["volume"] = _not_empty_str(
representation["volume"])
parse_volume_string(representation["volume"])
return representation

@gen.coroutine
@authenticated
Expand All @@ -44,11 +45,11 @@ def create(self, representation):

@gen.coroutine
@authenticated
def delete(self, id):
def delete(self, identifier):
db = self.application.db

try:
db.revoke_access_by_id(id)
db.revoke_access_by_id(identifier)
except db_exceptions.NotFound:
raise exceptions.NotFound()

Expand Down
17 changes: 10 additions & 7 deletions remoteappmanager/webapi/admin/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@


class Application(Resource):
def validate(self, representation):
def validate_representation(self, representation):
representation["image_name"] = str(representation["image_name"])
if len(representation["image_name"]) == 0:
raise ValueError("image_name cannot be empty")

return representation

def validate_identifier(self, identifier):
return int(identifier)

@gen.coroutine
@authenticated
def delete(self, identifier):
"""Removes the application."""
db = self.application.db
try:
id = int(identifier)
except ValueError:
raise exceptions.BadRequest("id")

try:
db.remove_application(id=id)
self.log.info("Removed application with id {}".format(id))
db.remove_application(id=identifier)
self.log.info("Removed application with id {}".format(identifier))
except db_exceptions.NotFound:
raise exceptions.NotFound()
except db_exceptions.UnsupportedOperation:
Expand Down
11 changes: 10 additions & 1 deletion remoteappmanager/webapi/admin/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_delete(self):
httpstatus.NOT_FOUND)

self.delete("/user/username/api/v1/applications/foo/",
httpstatus.BAD_REQUEST)
httpstatus.NOT_FOUND)

def test_unable_to_delete(self):
with mock.patch("remoteappmanager.tests.mocking."
Expand Down Expand Up @@ -53,6 +53,15 @@ def test_unable_to_create(self):
{"image_name": "foobar"},
httpstatus.INTERNAL_SERVER_ERROR)

def test_create_invalid_representation(self):
self.post("/user/username/api/v1/applications/",
{"image_name": ""},
httpstatus.BAD_REQUEST)

self.post("/user/username/api/v1/applications/",
{},
httpstatus.BAD_REQUEST)

def test_delete_failed_auth(self):
self._app.hub.verify_token.return_value = {}

Expand Down
2 changes: 1 addition & 1 deletion remoteappmanager/webapi/admin/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_delete(self):
httpstatus.NOT_FOUND)

self.delete("/user/username/api/v1/users/foo/",
httpstatus.BAD_REQUEST)
httpstatus.NOT_FOUND)

def test_unable_to_delete(self):
with mock.patch("remoteappmanager.tests.mocking."
Expand Down
15 changes: 7 additions & 8 deletions remoteappmanager/webapi/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@


class User(Resource):
def validate(self, representation):
def validate_representation(self, representation):
representation["name"] = str(representation["name"]).strip()
if len(representation["name"]) == 0:
raise ValueError("name cannot be empty")
return representation

def validate_identifier(self, identifier):
return int(identifier)

@gen.coroutine
@authenticated
def delete(self, identifier):
"""Removes the user."""
db = self.application.db
try:
id = int(identifier)
except ValueError:
raise exceptions.BadRequest("id")

try:
db.remove_user(id=id)
self.log.info("Removed user with id {}".format(id))
db.remove_user(id=identifier)
self.log.info("Removed user with id {}".format(identifier))
except db_exceptions.NotFound:
raise exceptions.NotFound()
except db_exceptions.UnsupportedOperation:
Expand Down
23 changes: 13 additions & 10 deletions remoteappmanager/webapi/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
from tornado import gen

from tornadowebapi import exceptions
from tornadowebapi.exceptions import NotFound
from tornadowebapi.resource import Resource

from remoteappmanager.netutils import wait_for_http_server_2xx
from remoteappmanager.webapi.decorators import authenticated


class Container(Resource):
def validate_representation(self, representation):
try:
representation["mapping_id"]
except KeyError:
raise exceptions.BadRepresentation(message="missing mapping_id")

return representation

@gen.coroutine
@authenticated
def create(self, representation):
"""Create the container.
The representation should accept the application mapping id we
want to start"""
if self.current_user is None:
raise NotFound()

try:
mapping_id = representation["mapping_id"]
except KeyError:
raise exceptions.BadRequest(message="missing mapping_id")
mapping_id = representation["mapping_id"]

webapp = self.application
account = self.current_user.account
Expand All @@ -38,19 +40,20 @@ def create(self, representation):
if not choice:
self.log.warning("Could not find resource "
"for mapping id {}".format(mapping_id))
raise exceptions.BadRequest(message="unrecognized mapping_id")
raise exceptions.BadRepresentation(
message="unrecognized mapping_id")

_, app, policy = choice[0]

image = yield container_manager.image(app.image)
if image is None:
raise exceptions.BadRequest(message="unrecognized image")
raise exceptions.BadRepresentation(message="unrecognized image")

try:
environment = self._environment_from_configurables(image,
representation)
except Exception:
raise exceptions.BadRequest(message="invalid configurables")
raise exceptions.BadRepresentation(message="invalid configurables")

# Everything is fine. Start and wait for the container to come online.
try:
Expand Down
4 changes: 2 additions & 2 deletions remoteappmanager/webapi/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_create_fails_for_missing_mapping_id(self):
)

self.assertEqual(data,
{"type": "BadRequest",
{"type": "BadRepresentation",
"message": "missing mapping_id"})

def test_create_fails_for_invalid_mapping_id(self):
Expand All @@ -217,7 +217,7 @@ def test_create_fails_for_invalid_mapping_id(self):
)

self.assertEqual(data,
{"type": "BadRequest",
{"type": "BadRepresentation",
"message": "unrecognized mapping_id"})

def test_retrieve(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ git+git://github.com/jupyterhub/jupyterhub.git@42a993fd084780ad23e475f27f67ade3a
jupyter_client==4.3.0
click==6.6
tabulate==0.7.5
git+git://github.com/simphony/tornado-webapi.git@v0.4.2#egg=tornadowebapi
git+git://github.com/simphony/tornado-webapi.git#egg=tornadowebapi
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jupyter_client>=4.3.0",
"click>=6.6",
"tabulate>=0.7.5",
"tornadowebapi>=0.4.2"
"tornadowebapi>=0.5.0.dev0"
]

# Unfortunately RTD cannot install jupyterhub because jupyterhub needs bower,
Expand Down