2025-08-10 13:44:29 +03:00
|
|
|
import os
|
2025-08-08 16:41:21 +03:00
|
|
|
import unittest
|
|
|
|
import requests
|
|
|
|
|
2025-08-08 17:08:43 +03:00
|
|
|
#test push
|
2025-08-10 15:05:47 +03:00
|
|
|
WEKAN_URL = os.getenv("WEKAN_URL", "http://localhost/users/login")
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
class TestUserLogin(unittest.TestCase):
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
def test_user_login_success(self):
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
payload = {
|
2025-08-10 15:05:47 +03:00
|
|
|
"username": "RabeeaFaraj",
|
|
|
|
"password": "30fnhk03"
|
|
|
|
}
|
|
|
|
payload2 = {
|
2025-08-08 16:41:21 +03:00
|
|
|
"username": "rabeeaFaraj",
|
|
|
|
"password": "30fnhk03"
|
|
|
|
}
|
2025-08-10 15:05:47 +03:00
|
|
|
if WEKAN_URL== "http://localhost/users/login":
|
|
|
|
payload = payload2
|
2025-08-10 13:44:29 +03:00
|
|
|
response = requests.post(WEKAN_URL, json=payload)
|
2025-08-09 21:22:54 +03:00
|
|
|
print("Status code:", response.status_code)
|
|
|
|
print("Response JSON:", response.json())
|
2025-08-08 16:41:21 +03:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertIn("token", response.json())
|
|
|
|
|
|
|
|
def test_user_login_wrong_password(self):
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
payload = {
|
|
|
|
"username": "rabeeaFaraj",
|
|
|
|
"password": "wrongpassword"
|
|
|
|
}
|
2025-08-10 13:44:29 +03:00
|
|
|
response = requests.post(WEKAN_URL, json=payload)
|
2025-08-08 16:41:21 +03:00
|
|
|
self.assertEqual(response.status_code, 400) # או 400 בהתאם למימוש
|
|
|
|
self.assertIn("error", response.json())
|
|
|
|
|
|
|
|
def test_user_login_missing_fields(self):
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
payload = {
|
|
|
|
"username": "rabeeaFaraj"
|
|
|
|
# חסר שדה סיסמה
|
|
|
|
}
|
2025-08-10 13:44:29 +03:00
|
|
|
response = requests.post(WEKAN_URL, json=payload)
|
2025-08-08 16:41:21 +03:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
self.assertIn("error", response.json())
|
|
|
|
|
|
|
|
def test_user_login_nonexistent_user(self):
|
2025-08-10 13:44:29 +03:00
|
|
|
|
2025-08-08 16:41:21 +03:00
|
|
|
payload = {
|
|
|
|
"username": "notexist",
|
|
|
|
"password": "any"
|
|
|
|
}
|
2025-08-10 13:44:29 +03:00
|
|
|
response = requests.post(WEKAN_URL, json=payload)
|
2025-08-08 16:41:21 +03:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400) # או 404 בהתאם למימוש
|
|
|
|
self.assertIn("error", response.json())
|
|
|
|
|
|
|
|
# ana btal
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|
|
|
|
|