Skip to content

Commit

Permalink
Fix tests by rm
Browse files Browse the repository at this point in the history
  • Loading branch information
harminius committed Dec 20, 2024
1 parent c13f1b2 commit 6b1ac37
Showing 1 changed file with 0 additions and 58 deletions.
58 changes: 0 additions & 58 deletions server/mergin/tests/test_private_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,61 +418,3 @@ def test_admin_project_list(client):
p.delete()
resp = client.get("/app/admin/projects?page=1&per_page=15&like=mergin")
assert len(resp.json["items"]) == 14


def test_get_project_access(client):
workspace = create_workspace()
user = User.query.filter(User.username == "mergin").first()
project = create_project("test-project", workspace, user)
url = f"/app/project/{project.id}/access"
users = []
for i in range(5):
users.append(add_user(str(i), str(i)))
Configuration.GLOBAL_ADMIN = False
Configuration.GLOBAL_WRITE = False
Configuration.GLOBAL_READ = False
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 1
assert resp.json[0]["role"] == "owner"
project.set_role(users[0].id, ProjectRole.OWNER)
project.set_role(users[1].id, ProjectRole.WRITER)
project.set_role(users[2].id, ProjectRole.READER)
db.session.commit()
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 4
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 1
# user3 does not have access to the project
assert not any(users[3].email == access["email"] for access in resp.json)
assert any(users[2].email == access["email"] for access in resp.json)
Configuration.GLOBAL_READ = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 3
Configuration.GLOBAL_WRITE = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 4
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 0
Configuration.GLOBAL_ADMIN = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 6
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 0
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 0
# pretend a user was deleted to test that api can handle it
users[3].inactivate()
users[3].anonymize()
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 5
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 5

0 comments on commit 6b1ac37

Please sign in to comment.