From 9f20d46fa6f756ff9a3dc5a2000a9a1a761f6140 Mon Sep 17 00:00:00 2001 From: al8763be Date: Sun, 17 Mar 2024 22:57:19 +0100 Subject: [PATCH] Test for getWeeklyReport --- backend/internal/handlers/handlers_report_related.go | 6 ++++++ testing.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/backend/internal/handlers/handlers_report_related.go b/backend/internal/handlers/handlers_report_related.go index 8754afd..79da61a 100644 --- a/backend/internal/handlers/handlers_report_related.go +++ b/backend/internal/handlers/handlers_report_related.go @@ -37,13 +37,19 @@ func (gs *GState) SubmitWeeklyReport(c *fiber.Ctx) error { // Handler for retrieving weekly report func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error { // Extract the necessary parameters from the request + println("GetWeeklyReport") user := c.Locals("user").(*jwt.Token) + println(user) claims := user.Claims.(jwt.MapClaims) + println(claims) username := claims["name"].(string) + println(username) // Extract project name and week from query parameters projectName := c.Query("projectName") + println(projectName) week := c.Query("week") + println(week) // Convert week to integer weekInt, err := strconv.Atoi(week) diff --git a/testing.py b/testing.py index d2c64fe..d75d0f2 100644 --- a/testing.py +++ b/testing.py @@ -21,6 +21,7 @@ registerPath = base_url + "/api/register" loginPath = base_url + "/api/login" addProjectPath = base_url + "/api/project" submitReportPath = base_url + "/api/submitReport" +getWeeklyReportPath = base_url + "/api/getWeeklyReport" # Posts the username and password to the register endpoint @@ -89,9 +90,18 @@ def test_submit_report(): assert response.status_code == 200, "Submit report failed" print("Submit report successful") +def test_get_weekly_report(): + token = login(username, "always_same").json()["token"] + response = requests.get( + getWeeklyReportPath, + headers={"Authorization": "Bearer " + token}, + params={"username": username, "projectName": "report1", "week": 1} + ) + print(response.text) if __name__ == "__main__": test_create_user() test_login() test_add_project() test_submit_report() + test_get_weekly_report() \ No newline at end of file