aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lb_app/api.py11
-rw-r--r--src/lb_app/app_db/user.py15
-rw-r--r--src/tests/test_user.py6
3 files changed, 32 insertions, 0 deletions
diff --git a/src/lb_app/api.py b/src/lb_app/api.py
index 6dfe2e8..9827828 100644
--- a/src/lb_app/api.py
+++ b/src/lb_app/api.py
@@ -41,3 +41,14 @@ class Register(Resource):
if status is None:
return loads('{"msg": "done"}'), 201
return loads('{"msg": "'+status+'"}'), 200
+
+@api.route('/users/<username>')
+@api.doc(params={'username': 'Jean'})
+class Remove(Resource):
+ def delete(self, username):
+ """ Remove a user """
+ status = user.remove(username)
+
+ if status is None:
+ return loads('{"msg": "done"}'), 201
+ return loads('{"msg": "'+status+'"}'), 200
diff --git a/src/lb_app/app_db/user.py b/src/lb_app/app_db/user.py
index 1af957c..7aeab7c 100644
--- a/src/lb_app/app_db/user.py
+++ b/src/lb_app/app_db/user.py
@@ -25,3 +25,18 @@ class User(object):
mongo.db.users.insert({"username": username})
return None
return error
+
+ def remove(self, username):
+ db = MongoDB(self.app)
+ mongo = db.connection()
+ error = None
+
+ if not username:
+ error = 'Username is required.'
+ elif len(list(mongo.db.users.find({"username": username}))) == 0:
+ error = "User {} not exist. So it's good.".format(username)
+
+ if error is None:
+ mongo.db.users.remove({"username": username})
+ return None
+ return error
diff --git a/src/tests/test_user.py b/src/tests/test_user.py
index 3d7ab50..f39279e 100644
--- a/src/tests/test_user.py
+++ b/src/tests/test_user.py
@@ -13,3 +13,9 @@ def test_register_user(app):
with app.app_context():
user = User(app)
assert user.register("neodarz") is None
+
+def test_register_and_remove_user(app):
+ with app.app_context():
+ user = User(app)
+ assert user.register("neodarz") is None
+ assert user.remove("neodarz") is None