From c9ae1feddf1c8d3c6766cb04a3a53625a44e2539 Mon Sep 17 00:00:00 2001 From: rabeeafaraj Date: Fri, 8 Aug 2025 16:41:21 +0300 Subject: [PATCH] test_login solution --- pytest.ini | 4 ++++ tests_r/test_endpoint.py | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 pytest.ini create mode 100644 tests_r/test_endpoint.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..36004bc9a --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +testpasths=test +addopts= -s + diff --git a/tests_r/test_endpoint.py b/tests_r/test_endpoint.py new file mode 100644 index 000000000..adbf95adc --- /dev/null +++ b/tests_r/test_endpoint.py @@ -0,0 +1,49 @@ +import unittest +import requests + +class TestUserLogin(unittest.TestCase): + def test_user_login_success(self): + url = "http://localhost:80/users/login" + payload = { + "username": "rabeeaFaraj", + "password": "30fnhk03" + } + response = requests.post(url, json=payload) + self.assertEqual(response.status_code, 200) + self.assertIn("token", response.json()) + + def test_user_login_wrong_password(self): + url = "http://localhost:80/users/login" + payload = { + "username": "rabeeaFaraj", + "password": "wrongpassword" + } + response = requests.post(url, json=payload) + self.assertEqual(response.status_code, 400) # או 400 בהתאם למימוש + self.assertIn("error", response.json()) + + def test_user_login_missing_fields(self): + url = "http://localhost:80/users/login" + payload = { + "username": "rabeeaFaraj" + # חסר שדה סיסמה + } + response = requests.post(url, json=payload) + self.assertEqual(response.status_code, 400) + self.assertIn("error", response.json()) + + def test_user_login_nonexistent_user(self): + url = "http://localhost:80/users/login" + payload = { + "username": "notexist", + "password": "any" + } + response = requests.post(url, json=payload) + + self.assertEqual(response.status_code, 400) # או 404 בהתאם למימוש + self.assertIn("error", response.json()) + +# ana btal +if __name__ == "__main__": + unittest.main() +