Polishing tests
This commit is contained in:
parent
7c973009ac
commit
903132e56d
2 changed files with 95 additions and 87 deletions
|
@ -1,6 +1,7 @@
|
|||
import requests
|
||||
import string
|
||||
import random
|
||||
import json
|
||||
|
||||
# Helper function for the TTime API testing suite
|
||||
|
||||
|
@ -34,7 +35,7 @@ getUpdateWeeklyReportPath = base_url + "/api/updateWeeklyReport"
|
|||
removeProjectPath = base_url + "/api/removeProject"
|
||||
promoteToPmPath = base_url + "/api/promoteToPm"
|
||||
|
||||
debug_output = False
|
||||
debug_output = True
|
||||
|
||||
|
||||
def gprint(*args, **kwargs):
|
||||
|
@ -82,7 +83,9 @@ def register_and_login(username: string, password: string) -> string:
|
|||
return response.json()["token"]
|
||||
|
||||
|
||||
def create_project(token: string, project_name: string, description: string = "Test description"):
|
||||
def create_project(
|
||||
token: string, project_name: string, description: string = "Test description"
|
||||
):
|
||||
dprint("Creating project with name: ", project_name)
|
||||
response = requests.post(
|
||||
addProjectPath,
|
||||
|
@ -119,3 +122,30 @@ def promoteToManager(token: string, username: string, project_name: string):
|
|||
)
|
||||
dprint(response.text)
|
||||
return response
|
||||
|
||||
|
||||
def submitReport(token: string, report):
|
||||
dprint("Submitting report: ", report)
|
||||
response = requests.post(
|
||||
submitReportPath,
|
||||
json=report,
|
||||
headers={"Authorization": "Bearer " + token},
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def getReport(token: string, username: string, projectName: string):
|
||||
# Retrieve the report ID
|
||||
response = requests.get(
|
||||
getWeeklyReportPath,
|
||||
headers={"Authorization": "Bearer " + token},
|
||||
params={"username": username, "projectName": projectName, "week": 1},
|
||||
)
|
||||
return response.json()
|
||||
|
||||
|
||||
def signReport(project_manager_token: string, report_id: int):
|
||||
return requests.put(
|
||||
signReportPath + "/" + str(report_id),
|
||||
headers={"Authorization": "Bearer " + project_manager_token},
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import requests
|
||||
import string
|
||||
|
||||
# This modules contains helper functions for the tests
|
||||
from helpers import *
|
||||
|
@ -10,6 +9,7 @@ print("Running Tests...")
|
|||
username = "user_" + randomString()
|
||||
projectName = "project_" + randomString()
|
||||
|
||||
|
||||
# ta bort auth i handlern för att få testet att gå igenom
|
||||
def test_ProjectRoleChange():
|
||||
dprint("Testing ProjectRoleChange")
|
||||
|
@ -17,9 +17,7 @@ def test_ProjectRoleChange():
|
|||
localProjectName = randomString()
|
||||
register(localUsername, "username_password")
|
||||
|
||||
token = login(localUsername, "username_password").json()[
|
||||
"token"
|
||||
]
|
||||
token = login(localUsername, "username_password").json()["token"]
|
||||
|
||||
# Just checking since this test is built somewhat differently than the others
|
||||
assert token != None, "Login failed"
|
||||
|
@ -78,6 +76,7 @@ def test_create_user():
|
|||
assert response.status_code == 200, "Registration failed"
|
||||
gprint("test_create_user successful")
|
||||
|
||||
|
||||
# Test function to add a project
|
||||
def test_add_project():
|
||||
loginResponse = login(username, "always_same")
|
||||
|
@ -91,6 +90,7 @@ def test_add_project():
|
|||
assert response.status_code == 200, "Add project failed"
|
||||
gprint("test_add_project successful")
|
||||
|
||||
|
||||
# Test function to submit a report
|
||||
def test_submit_report():
|
||||
token = login(username, "always_same").json()["token"]
|
||||
|
@ -112,6 +112,7 @@ def test_submit_report():
|
|||
assert response.status_code == 200, "Submit report failed"
|
||||
gprint("test_submit_report successful")
|
||||
|
||||
|
||||
# Test function to get a weekly report
|
||||
def test_get_weekly_report():
|
||||
token = login(username, "always_same").json()["token"]
|
||||
|
@ -160,51 +161,37 @@ def test_add_user_to_project():
|
|||
response = addToProject(pm_token, member_user, project_name)
|
||||
assert response.status_code == 200, "Add user to project failed"
|
||||
|
||||
|
||||
# Test function to sign a report
|
||||
def test_sign_report():
|
||||
# Create a project manager user
|
||||
project_manager = randomString()
|
||||
register(project_manager, "project_manager_password")
|
||||
# Pm user
|
||||
pm_username = "pm" + randomString()
|
||||
pm_password = "admin_password2"
|
||||
|
||||
# Register an admin
|
||||
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)
|
||||
# User to add
|
||||
member_user = "member" + randomString()
|
||||
member_passwd = "password"
|
||||
|
||||
# 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},
|
||||
)
|
||||
# Name of the project to be created
|
||||
project_name = "project" + randomString()
|
||||
|
||||
response = requests.put(
|
||||
addUserToProjectPath + "/" + projectName,
|
||||
headers={"Authorization": "Bearer " + admin_token},
|
||||
params={"userName": project_manager}
|
||||
)
|
||||
assert response.status_code == 200, "Add project manager to project failed"
|
||||
dprint("Project manager added to project successfully")
|
||||
# Register and get the tokens for both users
|
||||
pm_token = register_and_login(pm_username, pm_password)
|
||||
member_token = register_and_login(member_user, member_passwd)
|
||||
|
||||
# Log in as the project manager
|
||||
project_manager_token = login(project_manager, "project_manager_password").json()[
|
||||
"token"
|
||||
]
|
||||
# Create the project
|
||||
response = create_project(pm_token, project_name)
|
||||
assert response.status_code == 200, "Create project failed"
|
||||
|
||||
# Add the user to the project
|
||||
response = addToProject(pm_token, member_user, project_name)
|
||||
|
||||
# Submit a report for the project
|
||||
token = login(username, "always_same").json()["token"]
|
||||
response = requests.post(
|
||||
submitReportPath,
|
||||
json={
|
||||
"projectName": projectName,
|
||||
"week": 2,
|
||||
response = submitReport(
|
||||
member_token,
|
||||
{
|
||||
"projectName": project_name,
|
||||
"week": 1,
|
||||
"developmentTime": 10,
|
||||
"meetingTime": 5,
|
||||
"adminTime": 5,
|
||||
|
@ -212,37 +199,23 @@ def test_sign_report():
|
|||
"studyTime": 10,
|
||||
"testingTime": 10,
|
||||
},
|
||||
headers={"Authorization": "Bearer " + token},
|
||||
)
|
||||
assert response.status_code == 200, "Submit report failed"
|
||||
dprint("Submit report successful")
|
||||
|
||||
# Retrieve the report ID
|
||||
response = requests.get(
|
||||
getWeeklyReportPath,
|
||||
headers={"Authorization": "Bearer " + token},
|
||||
params={"username": username, "projectName": projectName, "week": 1},
|
||||
)
|
||||
dprint(response.text)
|
||||
report_id = response.json()["reportId"]
|
||||
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||
|
||||
# Sign the report as the project manager
|
||||
response = requests.put(
|
||||
signReportPath + "/" + str(report_id),
|
||||
headers={"Authorization": "Bearer " + project_manager_token},
|
||||
)
|
||||
response = signReport(pm_token, report_id)
|
||||
assert response.status_code == 200, "Sign report failed"
|
||||
dprint("Sign report successful")
|
||||
|
||||
# Retrieve the report ID again for confirmation
|
||||
response = requests.get(
|
||||
getWeeklyReportPath,
|
||||
headers={"Authorization": "Bearer " + token},
|
||||
params={"username": username, "projectName": projectName, "week": 1},
|
||||
)
|
||||
dprint(response.text)
|
||||
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||
assert report_id != None, "Get report failed"
|
||||
gprint("test_sign_report successful")
|
||||
|
||||
|
||||
# Test function to get weekly reports for a user in a project
|
||||
def test_get_weekly_reports_user():
|
||||
# Log in as the user
|
||||
|
@ -259,7 +232,6 @@ def test_get_weekly_reports_user():
|
|||
gprint("test_get_weekly_reports_user successful")
|
||||
|
||||
|
||||
|
||||
# Test function to check if a user is a project manager
|
||||
def test_check_if_project_manager():
|
||||
# Log in as the user
|
||||
|
@ -275,6 +247,7 @@ def test_check_if_project_manager():
|
|||
assert response.status_code == 200, "Check if project manager failed"
|
||||
gprint("test_check_if_project_manager successful")
|
||||
|
||||
|
||||
def test_ensure_manager_of_created_project():
|
||||
# Create a new user to add to the project
|
||||
newUser = "karen_" + randomString()
|
||||
|
@ -298,6 +271,7 @@ def test_ensure_manager_of_created_project():
|
|||
assert response.json()["isProjectManager"] == True, "User is not project manager"
|
||||
gprint("test_ensure_admin_of_created_project successful")
|
||||
|
||||
|
||||
def test_change_user_name():
|
||||
# Register a new user
|
||||
new_user = randomString()
|
||||
|
@ -335,6 +309,7 @@ def test_change_user_name():
|
|||
assert response.status_code == 200, "Change user name failed"
|
||||
gprint("test_change_user_name successful")
|
||||
|
||||
|
||||
def test_list_all_users_project():
|
||||
# Log in as a user who is a member of the project
|
||||
admin_username = randomString()
|
||||
|
@ -363,6 +338,7 @@ def test_list_all_users_project():
|
|||
assert response.status_code == 200, "List all users project failed"
|
||||
gprint("test_list_all_users_project sucessful")
|
||||
|
||||
|
||||
def test_update_weekly_report():
|
||||
# Log in as the user
|
||||
token = login(username, "always_same").json()["token"]
|
||||
|
@ -428,6 +404,7 @@ def test_remove_project():
|
|||
assert response.status_code == 200, "Remove project failed"
|
||||
gprint("test_remove_project successful")
|
||||
|
||||
|
||||
def test_get_unsigned_reports():
|
||||
# Log in as the user
|
||||
token = login("user2", "123").json()["token"]
|
||||
|
@ -440,6 +417,7 @@ def test_get_unsigned_reports():
|
|||
assert response.status_code == 200, "Get unsigned reports failed"
|
||||
gprint("test_get_unsigned_reports successful")
|
||||
|
||||
|
||||
def test_get_other_users_report_as_pm():
|
||||
# Create user
|
||||
user = randomString()
|
||||
|
@ -493,6 +471,7 @@ def test_get_other_users_report_as_pm():
|
|||
)
|
||||
assert response.status_code == 200, "Get weekly report failed"
|
||||
|
||||
|
||||
def test_promote_to_manager():
|
||||
# User to create
|
||||
pm_user = "user" + randomString()
|
||||
|
@ -526,7 +505,7 @@ if __name__ == "__main__":
|
|||
test_submit_report()
|
||||
test_get_weekly_report()
|
||||
test_get_project()
|
||||
#test_sign_report()
|
||||
test_sign_report()
|
||||
test_add_user_to_project()
|
||||
test_get_weekly_reports_user()
|
||||
test_check_if_project_manager()
|
||||
|
@ -537,4 +516,3 @@ if __name__ == "__main__":
|
|||
test_change_user_name()
|
||||
test_update_weekly_report()
|
||||
test_get_other_users_report_as_pm()
|
||||
|
Loading…
Reference in a new issue