2024-03-17 01:55:24 +01:00
|
|
|
import requests
|
|
|
|
import string
|
|
|
|
import random
|
|
|
|
|
2024-03-19 00:30:25 +01:00
|
|
|
debug_output = False
|
|
|
|
|
2024-03-19 01:12:14 +01:00
|
|
|
def gprint(*args, **kwargs):
|
|
|
|
print("\033[92m", *args, "\033[00m", **kwargs)
|
|
|
|
|
|
|
|
print("Running Tests...")
|
|
|
|
|
2024-03-19 00:30:25 +01:00
|
|
|
def dprint(*args, **kwargs):
|
|
|
|
if debug_output:
|
|
|
|
print(*args, **kwargs)
|
2024-03-17 03:39:31 +01:00
|
|
|
|
2024-03-17 01:55:24 +01:00
|
|
|
def randomString(len=10):
|
2024-03-17 03:39:31 +01:00
|
|
|
"""Generate a random string of fixed length"""
|
2024-03-17 01:55:24 +01:00
|
|
|
letters = string.ascii_lowercase
|
2024-03-17 03:39:31 +01:00
|
|
|
return "".join(random.choice(letters) for i in range(len))
|
|
|
|
|
2024-03-17 01:55:24 +01:00
|
|
|
|
|
|
|
# Defined once per test run
|
2024-03-20 21:51:36 +01:00
|
|
|
username = "user_" + randomString()
|
|
|
|
projectName = "project_" + randomString()
|
2024-03-17 01:55:24 +01:00
|
|
|
|
2024-03-17 03:39:31 +01:00
|
|
|
# The base URL of the API
|
2024-03-17 01:55:24 +01:00
|
|
|
base_url = "http://localhost:8080"
|
|
|
|
|
2024-03-17 03:39:31 +01:00
|
|
|
# Endpoint to test
|
2024-03-17 01:55:24 +01:00
|
|
|
registerPath = base_url + "/api/register"
|
|
|
|
loginPath = base_url + "/api/login"
|
2024-03-17 03:39:31 +01:00
|
|
|
addProjectPath = base_url + "/api/project"
|
2024-03-19 00:46:28 +01:00
|
|
|
submitReportPath = base_url + "/api/submitWeeklyReport"
|
2024-03-17 22:57:19 +01:00
|
|
|
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
2024-03-18 16:42:35 +01:00
|
|
|
getProjectPath = base_url + "/api/project"
|
2024-03-18 16:01:00 +01:00
|
|
|
signReportPath = base_url + "/api/signReport"
|
|
|
|
addUserToProjectPath = base_url + "/api/addUserToProject"
|
|
|
|
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
2024-03-18 21:08:33 +01:00
|
|
|
getUserProjectsPath = base_url + "/api/getUserProjects"
|
2024-03-19 19:04:45 +01:00
|
|
|
getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser"
|
2024-03-19 19:30:01 +01:00
|
|
|
checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager"
|
2024-03-19 23:08:14 +01:00
|
|
|
ProjectRoleChangePath = base_url + "/api/ProjectRoleChange"
|
2024-03-20 00:35:37 +01:00
|
|
|
getUsersProjectPath = base_url + "/api/getUsersProject"
|
2024-03-21 00:16:51 +01:00
|
|
|
getChangeUserNamePath = base_url + "/api/changeUserName"
|
2024-03-17 03:39:31 +01:00
|
|
|
|
2024-03-19 23:08:14 +01:00
|
|
|
#ta bort auth i handlern för att få testet att gå igenom
|
|
|
|
def test_ProjectRoleChange():
|
|
|
|
dprint("Testing ProjectRoleChange")
|
2024-03-20 21:51:36 +01:00
|
|
|
localUsername = randomString()
|
|
|
|
localProjectName = randomString()
|
|
|
|
register(localUsername, "username_password")
|
2024-03-19 23:08:14 +01:00
|
|
|
|
2024-03-20 21:51:36 +01:00
|
|
|
token = login(localUsername, "username_password").json()[
|
2024-03-19 23:08:14 +01:00
|
|
|
"token"
|
|
|
|
]
|
2024-03-20 21:51:36 +01:00
|
|
|
|
|
|
|
# Just checking since this test is built somewhat differently than the others
|
|
|
|
assert token != None, "Login failed"
|
|
|
|
|
2024-03-19 23:08:14 +01:00
|
|
|
response = requests.post(
|
|
|
|
addProjectPath,
|
2024-03-20 21:51:36 +01:00
|
|
|
json={"name": localProjectName, "description": "This is a project"},
|
2024-03-19 23:08:14 +01:00
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
2024-03-20 21:51:36 +01:00
|
|
|
|
|
|
|
if response.status_code != 200:
|
|
|
|
print("Add project failed")
|
|
|
|
|
2024-03-19 23:08:14 +01:00
|
|
|
response = requests.post(
|
|
|
|
ProjectRoleChangePath,
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
json={
|
2024-03-20 21:51:36 +01:00
|
|
|
"projectName": localProjectName,
|
|
|
|
"role": "project_manager",
|
2024-03-19 23:08:14 +01:00
|
|
|
},
|
|
|
|
)
|
2024-03-20 21:51:36 +01:00
|
|
|
|
|
|
|
assert response.status_code == 200, "ProjectRoleChange failed"
|
|
|
|
gprint("test_ProjectRoleChange successful")
|
2024-03-19 23:08:14 +01:00
|
|
|
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 23:34:03 +01:00
|
|
|
def test_get_user_projects():
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Testing get user projects")
|
2024-03-18 23:34:03 +01:00
|
|
|
loginResponse = login("user2", "123")
|
|
|
|
# Check if the user is added to the project
|
|
|
|
response = requests.get(
|
|
|
|
getUserProjectsPath,
|
|
|
|
json={"username": "user2"},
|
|
|
|
headers={"Authorization": "Bearer " + loginResponse.json()["token"]},
|
2024-03-18 23:43:14 +01:00
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
|
|
|
dprint(response.json())
|
2024-03-18 23:34:03 +01:00
|
|
|
assert response.status_code == 200, "Get user projects failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_get_user_projects successful")
|
2024-03-18 23:34:03 +01:00
|
|
|
|
2024-03-17 01:55:24 +01:00
|
|
|
|
2024-03-17 03:46:16 +01:00
|
|
|
# Posts the username and password to the register endpoint
|
2024-03-17 03:39:31 +01:00
|
|
|
def register(username: string, password: string):
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Registering with username: ", username, " and password: ", password)
|
2024-03-17 03:39:31 +01:00
|
|
|
response = requests.post(
|
|
|
|
registerPath, json={"username": username, "password": password}
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-17 01:55:24 +01:00
|
|
|
return response
|
|
|
|
|
2024-03-17 03:39:31 +01:00
|
|
|
|
2024-03-17 03:46:16 +01:00
|
|
|
# Posts the username and password to the login endpoint
|
2024-03-17 03:39:31 +01:00
|
|
|
def login(username: string, password: string):
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Logging in with username: ", username, " and password: ", password)
|
2024-03-17 03:39:31 +01:00
|
|
|
response = requests.post(
|
|
|
|
loginPath, json={"username": username, "password": password}
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-17 01:55:24 +01:00
|
|
|
return response
|
|
|
|
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to login
|
2024-03-17 01:55:24 +01:00
|
|
|
def test_login():
|
|
|
|
response = login(username, "always_same")
|
|
|
|
assert response.status_code == 200, "Login failed"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Login successful")
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_login successful")
|
2024-03-17 03:39:31 +01:00
|
|
|
return response.json()["token"]
|
|
|
|
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to create a new user
|
2024-03-17 01:55:24 +01:00
|
|
|
def test_create_user():
|
2024-03-17 03:39:31 +01:00
|
|
|
response = register(username, "always_same")
|
2024-03-17 01:55:24 +01:00
|
|
|
assert response.status_code == 200, "Registration failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_create_user successful")
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to add a project
|
2024-03-17 03:39:31 +01:00
|
|
|
def test_add_project():
|
|
|
|
loginResponse = login(username, "always_same")
|
|
|
|
token = loginResponse.json()["token"]
|
|
|
|
response = requests.post(
|
|
|
|
addProjectPath,
|
|
|
|
json={"name": projectName, "description": "This is a project"},
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-17 03:39:31 +01:00
|
|
|
assert response.status_code == 200, "Add project failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_add_project successful")
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to submit a report
|
2024-03-17 04:16:54 +01:00
|
|
|
def test_submit_report():
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
response = requests.post(
|
|
|
|
submitReportPath,
|
|
|
|
json={
|
2024-03-17 23:17:06 +01:00
|
|
|
"projectName": projectName,
|
2024-03-17 04:16:54 +01:00
|
|
|
"week": 1,
|
|
|
|
"developmentTime": 10,
|
|
|
|
"meetingTime": 5,
|
|
|
|
"adminTime": 5,
|
|
|
|
"ownWorkTime": 10,
|
|
|
|
"studyTime": 10,
|
|
|
|
"testingTime": 10,
|
|
|
|
},
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-17 04:16:54 +01:00
|
|
|
assert response.status_code == 200, "Submit report failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_submit_report successful")
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to get a weekly report
|
2024-03-17 22:57:19 +01:00
|
|
|
def test_get_weekly_report():
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
response = requests.get(
|
|
|
|
getWeeklyReportPath,
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
2024-03-18 23:43:14 +01:00
|
|
|
params={"username": username, "projectName": projectName, "week": 1},
|
2024-03-17 22:57:19 +01:00
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:42:35 +01:00
|
|
|
assert response.status_code == 200, "Get weekly report failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_get_weekly_report successful")
|
2024-03-18 16:42:35 +01:00
|
|
|
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:42:35 +01:00
|
|
|
# Tests getting a project by id
|
|
|
|
def test_get_project():
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
response = requests.get(
|
2024-03-18 23:43:14 +01:00
|
|
|
getProjectPath + "/1", # Assumes that the project with id 1 exists
|
2024-03-18 16:42:35 +01:00
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:42:35 +01:00
|
|
|
assert response.status_code == 200, "Get project failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_get_project successful")
|
2024-03-17 04:16:54 +01:00
|
|
|
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to add a user to a project
|
|
|
|
def test_add_user_to_project():
|
|
|
|
# Log in as a site admin
|
|
|
|
admin_username = randomString()
|
|
|
|
admin_password = "admin_password"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(
|
2024-03-18 23:43:14 +01:00
|
|
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
|
|
)
|
2024-03-18 16:01:00 +01:00
|
|
|
response = requests.post(
|
|
|
|
registerPath, json={"username": admin_username, "password": admin_password}
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
admin_token = login(admin_username, admin_password).json()["token"]
|
2024-03-18 23:43:14 +01:00
|
|
|
response = requests.post(
|
|
|
|
promoteToAdminPath,
|
|
|
|
json={"username": admin_username},
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:01:00 +01:00
|
|
|
assert response.status_code == 200, "Promote to site admin failed"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Admin promoted to site admin successfully")
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
# Create a new user to add to the project
|
|
|
|
new_user = randomString()
|
|
|
|
register(new_user, "new_user_password")
|
|
|
|
|
|
|
|
# Add the new user to the project as a member
|
|
|
|
response = requests.put(
|
|
|
|
addUserToProjectPath,
|
|
|
|
json={"projectName": projectName, "username": new_user, "role": "member"},
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
|
|
|
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:01:00 +01:00
|
|
|
assert response.status_code == 200, "Add user to project failed"
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_add_user_to_project successful")
|
2024-03-18 21:08:33 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Test function to sign a report
|
|
|
|
def test_sign_report():
|
|
|
|
# Create a project manager user
|
|
|
|
project_manager = randomString()
|
|
|
|
register(project_manager, "project_manager_password")
|
|
|
|
|
|
|
|
# Register an admin
|
|
|
|
admin_username = randomString()
|
|
|
|
admin_password = "admin_password2"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(
|
2024-03-18 23:43:14 +01:00
|
|
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
|
|
)
|
2024-03-18 16:01:00 +01:00
|
|
|
response = requests.post(
|
|
|
|
registerPath, json={"username": admin_username, "password": admin_password}
|
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
# Log in as the admin
|
|
|
|
admin_token = login(admin_username, admin_password).json()["token"]
|
2024-03-18 23:43:14 +01:00
|
|
|
response = requests.post(
|
|
|
|
promoteToAdminPath,
|
|
|
|
json={"username": admin_username},
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
response = requests.put(
|
|
|
|
addUserToProjectPath,
|
2024-03-18 23:43:14 +01:00
|
|
|
json={
|
|
|
|
"projectName": projectName,
|
|
|
|
"username": project_manager,
|
|
|
|
"role": "project_manager",
|
|
|
|
},
|
2024-03-18 16:01:00 +01:00
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
2024-03-18 23:43:14 +01:00
|
|
|
)
|
2024-03-18 16:01:00 +01:00
|
|
|
assert response.status_code == 200, "Add project manager to project failed"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Project manager added to project successfully")
|
2024-03-18 23:43:14 +01:00
|
|
|
|
2024-03-18 16:01:00 +01:00
|
|
|
# Log in as the project manager
|
2024-03-18 23:43:14 +01:00
|
|
|
project_manager_token = login(project_manager, "project_manager_password").json()[
|
|
|
|
"token"
|
|
|
|
]
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
# Submit a report for the project
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
response = requests.post(
|
|
|
|
submitReportPath,
|
|
|
|
json={
|
|
|
|
"projectName": projectName,
|
2024-03-20 23:18:51 +01:00
|
|
|
"week": 2,
|
2024-03-18 16:01:00 +01:00
|
|
|
"developmentTime": 10,
|
|
|
|
"meetingTime": 5,
|
|
|
|
"adminTime": 5,
|
|
|
|
"ownWorkTime": 10,
|
|
|
|
"studyTime": 10,
|
|
|
|
"testingTime": 10,
|
|
|
|
},
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
|
|
|
assert response.status_code == 200, "Submit report failed"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Submit report successful")
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
# Retrieve the report ID
|
|
|
|
response = requests.get(
|
|
|
|
getWeeklyReportPath,
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
2024-03-18 23:43:14 +01:00
|
|
|
params={"username": username, "projectName": projectName, "week": 1},
|
2024-03-18 16:01:00 +01:00
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-18 16:01:00 +01:00
|
|
|
report_id = response.json()["reportId"]
|
|
|
|
|
|
|
|
# Sign the report as the project manager
|
|
|
|
response = requests.post(
|
|
|
|
signReportPath,
|
|
|
|
json={"reportId": report_id},
|
|
|
|
headers={"Authorization": "Bearer " + project_manager_token},
|
|
|
|
)
|
|
|
|
assert response.status_code == 200, "Sign report failed"
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint("Sign report successful")
|
2024-03-18 16:01:00 +01:00
|
|
|
|
|
|
|
# Retrieve the report ID again for confirmation
|
|
|
|
response = requests.get(
|
|
|
|
getWeeklyReportPath,
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
2024-03-18 23:43:14 +01:00
|
|
|
params={"username": username, "projectName": projectName, "week": 1},
|
2024-03-18 16:01:00 +01:00
|
|
|
)
|
2024-03-19 00:30:25 +01:00
|
|
|
dprint(response.text)
|
2024-03-19 01:12:14 +01:00
|
|
|
gprint("test_sign_report successful")
|
2024-03-18 16:01:00 +01:00
|
|
|
|
2024-03-19 19:04:45 +01:00
|
|
|
# Test function to get weekly reports for a user in a project
|
|
|
|
def test_get_weekly_reports_user():
|
|
|
|
# Log in as the user
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
|
|
|
|
# Get weekly reports for the user in the project
|
|
|
|
response = requests.get(
|
2024-03-20 17:14:57 +01:00
|
|
|
getWeeklyReportsUserPath + "/" + projectName,
|
2024-03-19 19:04:45 +01:00
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
|
|
|
|
|
|
|
dprint(response.text)
|
|
|
|
assert response.status_code == 200, "Get weekly reports for user failed"
|
|
|
|
gprint("test_get_weekly_reports_user successful")
|
|
|
|
|
2024-03-19 19:30:01 +01:00
|
|
|
# Test function to check if a user is a project manager
|
|
|
|
def test_check_if_project_manager():
|
|
|
|
# Log in as the user
|
|
|
|
token = login(username, "always_same").json()["token"]
|
|
|
|
|
|
|
|
# Check if the user is a project manager for the project
|
|
|
|
response = requests.get(
|
2024-03-20 17:50:51 +01:00
|
|
|
checkIfProjectManagerPath + "/" + projectName,
|
2024-03-19 19:30:01 +01:00
|
|
|
headers={"Authorization": "Bearer " + token},
|
|
|
|
)
|
|
|
|
|
|
|
|
dprint(response.text)
|
|
|
|
assert response.status_code == 200, "Check if project manager failed"
|
|
|
|
gprint("test_check_if_project_manager successful")
|
|
|
|
|
2024-03-20 21:51:36 +01:00
|
|
|
def test_ensure_manager_of_created_project():
|
|
|
|
# Create a new user to add to the project
|
|
|
|
newUser = "karen_" + randomString()
|
|
|
|
newProject = "HR_" + randomString()
|
|
|
|
register(newUser, "new_user_password")
|
|
|
|
token = login(newUser, "new_user_password").json()["token"]
|
2024-03-20 00:35:37 +01:00
|
|
|
|
2024-03-20 21:51:36 +01:00
|
|
|
# Create a new project
|
2024-03-20 00:35:37 +01:00
|
|
|
response = requests.post(
|
2024-03-20 21:51:36 +01:00
|
|
|
addProjectPath,
|
|
|
|
json={"name": newProject, "description": "This is a project"},
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
2024-03-20 00:35:37 +01:00
|
|
|
)
|
2024-03-20 21:51:36 +01:00
|
|
|
assert response.status_code == 200, "Add project failed"
|
2024-03-19 19:30:01 +01:00
|
|
|
|
2024-03-20 00:35:37 +01:00
|
|
|
response = requests.get(
|
2024-03-20 21:51:36 +01:00
|
|
|
checkIfProjectManagerPath + "/" + newProject,
|
|
|
|
headers={"Authorization": "Bearer " + token},
|
2024-03-20 00:35:37 +01:00
|
|
|
)
|
2024-03-20 21:51:36 +01:00
|
|
|
assert response.status_code == 200, "Check if project manager failed"
|
|
|
|
assert response.json()["isProjectManager"] == True, "User is not project manager"
|
|
|
|
gprint("test_ensure_admin_of_created_project successful")
|
2024-03-19 19:30:01 +01:00
|
|
|
|
2024-03-21 00:16:51 +01:00
|
|
|
def test_change_user_name():
|
|
|
|
# Register a new user
|
|
|
|
new_user = randomString()
|
|
|
|
register(new_user, "password")
|
|
|
|
|
|
|
|
# Log in as the new user
|
|
|
|
token = login(new_user, "password").json()["token"]
|
|
|
|
|
|
|
|
# Register a new admin
|
|
|
|
admin_username = randomString()
|
|
|
|
admin_password = "admin_password"
|
|
|
|
dprint(
|
|
|
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
|
|
)
|
|
|
|
response = requests.post(
|
|
|
|
registerPath, json={"username": admin_username, "password": admin_password}
|
|
|
|
)
|
|
|
|
admin_token = login(admin_username, admin_password).json()["token"]
|
|
|
|
|
|
|
|
# Promote to admin
|
|
|
|
response = requests.post(
|
|
|
|
promoteToAdminPath,
|
|
|
|
json={"username": admin_username},
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Change the user's name
|
|
|
|
response = requests.put(
|
|
|
|
getChangeUserNamePath,
|
2024-03-21 00:41:40 +01:00
|
|
|
json={"prevName": new_user, "newName": randomString()},
|
2024-03-21 00:16:51 +01:00
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Check if the change was successful
|
|
|
|
assert response.status_code == 200, "Change user name failed"
|
|
|
|
gprint("test_change_user_name successful")
|
2024-03-18 16:01:00 +01:00
|
|
|
|
2024-03-21 00:41:40 +01:00
|
|
|
def test_list_all_users_project():
|
|
|
|
# Log in as a user who is a member of the project
|
|
|
|
admin_username = randomString()
|
|
|
|
admin_password = "admin_password2"
|
|
|
|
dprint(
|
|
|
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
|
|
)
|
|
|
|
response = requests.post(
|
|
|
|
registerPath, json={"username": admin_username, "password": admin_password}
|
|
|
|
)
|
|
|
|
dprint(response.text)
|
|
|
|
|
|
|
|
# Log in as the admin
|
|
|
|
admin_token = login(admin_username, admin_password).json()["token"]
|
|
|
|
response = requests.post(
|
|
|
|
promoteToAdminPath,
|
|
|
|
json={"username": admin_username},
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Make a request to list all users associated with the project
|
|
|
|
response = requests.get(
|
|
|
|
getUsersProjectPath + "/" + projectName,
|
|
|
|
headers={"Authorization": "Bearer " + admin_token},
|
|
|
|
)
|
|
|
|
assert response.status_code == 200, "List all users project failed"
|
|
|
|
gprint("test_list_all_users_project sucessful")
|
|
|
|
|
2024-03-17 01:55:24 +01:00
|
|
|
if __name__ == "__main__":
|
2024-03-18 23:34:03 +01:00
|
|
|
test_get_user_projects()
|
2024-03-17 01:55:24 +01:00
|
|
|
test_create_user()
|
|
|
|
test_login()
|
2024-03-17 03:39:31 +01:00
|
|
|
test_add_project()
|
2024-03-17 04:16:54 +01:00
|
|
|
test_submit_report()
|
2024-03-18 16:42:35 +01:00
|
|
|
test_get_weekly_report()
|
2024-03-18 17:30:50 +01:00
|
|
|
test_get_project()
|
2024-03-18 16:01:00 +01:00
|
|
|
test_sign_report()
|
2024-03-18 17:30:50 +01:00
|
|
|
test_add_user_to_project()
|
2024-03-19 19:04:45 +01:00
|
|
|
test_get_weekly_reports_user()
|
2024-03-19 19:30:01 +01:00
|
|
|
test_check_if_project_manager()
|
2024-03-19 23:08:14 +01:00
|
|
|
test_ProjectRoleChange()
|
2024-03-20 21:51:36 +01:00
|
|
|
test_ensure_manager_of_created_project()
|
2024-03-21 00:41:40 +01:00
|
|
|
test_list_all_users_project()
|
2024-03-21 00:16:51 +01:00
|
|
|
test_change_user_name()
|