Fix API to allow returning user list with the master user
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
36bf1a80bf
commit
1ac5f72433
|
@ -68,7 +68,7 @@ def create_app(test_config=None):
|
||||||
def spec():
|
def spec():
|
||||||
if app.config["ENABLE_SWAGGER"] == "1":
|
if app.config["ENABLE_SWAGGER"] == "1":
|
||||||
swag = swagger(app)
|
swag = swagger(app)
|
||||||
swag["info"]["version"] = "1.2.4"
|
swag["info"]["version"] = "1.2.5"
|
||||||
swag["info"]["title"] = "SelfPrivacy API"
|
swag["info"]["title"] = "SelfPrivacy API"
|
||||||
swag["info"]["description"] = "SelfPrivacy API"
|
swag["info"]["description"] = "SelfPrivacy API"
|
||||||
swag["securityDefinitions"] = {
|
swag["securityDefinitions"] = {
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Tokens(Resource):
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
token:
|
token_name:
|
||||||
type: string
|
type: string
|
||||||
description: Token name to delete
|
description: Token name to delete
|
||||||
required: true
|
required: true
|
||||||
|
|
|
@ -23,4 +23,4 @@ class ApiVersion(Resource):
|
||||||
401:
|
401:
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
"""
|
"""
|
||||||
return {"version": "1.2.4"}
|
return {"version": "1.2.5"}
|
||||||
|
|
|
@ -24,8 +24,15 @@ class Users(Resource):
|
||||||
401:
|
401:
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
"""
|
"""
|
||||||
|
parser = reqparse.RequestParser(bundle_errors=True)
|
||||||
|
parser.add_argument("withMainUser", type=bool, required=False)
|
||||||
|
args = parser.parse_args()
|
||||||
|
with_main_user = False if args["withMainUser"] is None else args["withMainUser"]
|
||||||
|
|
||||||
with ReadUserData() as data:
|
with ReadUserData() as data:
|
||||||
users = []
|
users = []
|
||||||
|
if with_main_user:
|
||||||
|
users.append(data["username"])
|
||||||
if "users" in data:
|
if "users" in data:
|
||||||
for user in data["users"]:
|
for user in data["users"]:
|
||||||
users.append(user["username"])
|
users.append(user["username"])
|
||||||
|
@ -96,7 +103,10 @@ class Users(Resource):
|
||||||
if "users" not in data:
|
if "users" not in data:
|
||||||
data["users"] = []
|
data["users"] = []
|
||||||
|
|
||||||
# Return 400 if user already exists
|
# Return 409 if user already exists
|
||||||
|
if data["username"] == args["username"]:
|
||||||
|
return {"error": "User already exists"}, 409
|
||||||
|
|
||||||
for user in data["users"]:
|
for user in data["users"]:
|
||||||
if user["username"] == args["username"]:
|
if user["username"] == args["username"]:
|
||||||
return {"error": "User already exists"}, 409
|
return {"error": "User already exists"}, 409
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="selfprivacy_api",
|
name="selfprivacy_api",
|
||||||
version="1.2.3",
|
version="1.2.5",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
scripts=[
|
scripts=[
|
||||||
"selfprivacy_api/app.py",
|
"selfprivacy_api/app.py",
|
||||||
|
|
|
@ -130,12 +130,24 @@ def test_get_one_user(authorized_client, one_user, mock_subprocess_popen):
|
||||||
assert response.json == ["user1"]
|
assert response.json == ["user1"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_one_user_with_main(authorized_client, one_user, mock_subprocess_popen):
|
||||||
|
response = authorized_client.get("/users?withMainUser=true")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json == ["tester", "user1"]
|
||||||
|
|
||||||
|
|
||||||
def test_get_no_users(authorized_client, no_users, mock_subprocess_popen):
|
def test_get_no_users(authorized_client, no_users, mock_subprocess_popen):
|
||||||
response = authorized_client.get("/users")
|
response = authorized_client.get("/users")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json == []
|
assert response.json == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_no_users_with_main(authorized_client, no_users, mock_subprocess_popen):
|
||||||
|
response = authorized_client.get("/users?withMainUser=true")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json == ["tester"]
|
||||||
|
|
||||||
|
|
||||||
def test_get_undefined_users(
|
def test_get_undefined_users(
|
||||||
authorized_client, undefined_settings, mock_subprocess_popen
|
authorized_client, undefined_settings, mock_subprocess_popen
|
||||||
):
|
):
|
||||||
|
@ -199,6 +211,13 @@ def test_post_existing_user(authorized_client, one_user, mock_subprocess_popen):
|
||||||
assert response.status_code == 409
|
assert response.status_code == 409
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_existing_main_user(authorized_client, one_user, mock_subprocess_popen):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/users", json={"username": "tester", "password": "password"}
|
||||||
|
)
|
||||||
|
assert response.status_code == 409
|
||||||
|
|
||||||
|
|
||||||
def test_post_user_to_undefined_users(
|
def test_post_user_to_undefined_users(
|
||||||
authorized_client, undefined_settings, mock_subprocess_popen
|
authorized_client, undefined_settings, mock_subprocess_popen
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in New Issue