mongo updated
This commit is contained in:
@@ -8,28 +8,32 @@ LOGIN_ENDPOINT = f"{BASE_URL}/authentication/login"
|
||||
|
||||
# Load test data
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(os.path.join(current_dir, 'test_data.json'), 'r') as f:
|
||||
with open(os.path.join(current_dir, "test_data.json"), "r") as f:
|
||||
TEST_DATA = json.load(f)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_credentials():
|
||||
return TEST_DATA['test_credentials']
|
||||
return TEST_DATA["test_credentials"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def headers():
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
return {"Content-Type": "application/json", "Accept": "application/json"}
|
||||
|
||||
|
||||
class TestLogin:
|
||||
def test_successful_login(self, test_credentials, headers):
|
||||
"""Test successful login with provided credentials"""
|
||||
response = requests.post(LOGIN_ENDPOINT, json=test_credentials, headers=headers)
|
||||
assert response.status_code == 200, f"Login failed with status {response.status_code}. Response: {response.text}"
|
||||
assert (
|
||||
response.status_code == 200
|
||||
), f"Login failed with status {response.status_code}. Response: {response.text}"
|
||||
data = response.json()
|
||||
assert "token" in data, f"Token not found in response. Response: {data}"
|
||||
assert data.get("status") == "success", f"Status is not success. Response: {data}"
|
||||
assert (
|
||||
data.get("status") == "success"
|
||||
), f"Status is not success. Response: {data}"
|
||||
|
||||
def test_invalid_credentials(self, headers):
|
||||
"""Test login with invalid credentials"""
|
||||
@@ -37,20 +41,29 @@ class TestLogin:
|
||||
"domain": "evyos.com.tr",
|
||||
"access_key": "invalid@evyos.com.tr",
|
||||
"password": "wrongpassword",
|
||||
"remember_me": False
|
||||
"remember_me": False,
|
||||
}
|
||||
response = requests.post(LOGIN_ENDPOINT, json=invalid_credentials, headers=headers)
|
||||
assert response.status_code in [401, 403], f"Expected 401 or 403, got {response.status_code}. Response: {response.text}"
|
||||
response = requests.post(
|
||||
LOGIN_ENDPOINT, json=invalid_credentials, headers=headers
|
||||
)
|
||||
assert response.status_code in [
|
||||
401,
|
||||
403,
|
||||
], f"Expected 401 or 403, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
def test_missing_fields(self, headers):
|
||||
"""Test login with missing required fields"""
|
||||
incomplete_credentials = {
|
||||
"domain": "evyos.com.tr",
|
||||
"access_key": "test@evyos.com.tr"
|
||||
"access_key": "test@evyos.com.tr",
|
||||
# missing password
|
||||
}
|
||||
response = requests.post(LOGIN_ENDPOINT, json=incomplete_credentials, headers=headers)
|
||||
assert response.status_code == 422, f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
response = requests.post(
|
||||
LOGIN_ENDPOINT, json=incomplete_credentials, headers=headers
|
||||
)
|
||||
assert (
|
||||
response.status_code == 422
|
||||
), f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
def test_invalid_domain(self, headers):
|
||||
"""Test login with invalid domain"""
|
||||
@@ -58,17 +71,26 @@ class TestLogin:
|
||||
"domain": "invalid-domain.com",
|
||||
"access_key": "test@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": False
|
||||
"remember_me": False,
|
||||
}
|
||||
response = requests.post(LOGIN_ENDPOINT, json=invalid_domain_credentials, headers=headers)
|
||||
assert response.status_code in [400, 401], f"Expected 400 or 401, got {response.status_code}. Response: {response.text}"
|
||||
response = requests.post(
|
||||
LOGIN_ENDPOINT, json=invalid_domain_credentials, headers=headers
|
||||
)
|
||||
assert response.status_code in [
|
||||
400,
|
||||
401,
|
||||
], f"Expected 400 or 401, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
def test_malformed_json(self, headers):
|
||||
"""Test login with malformed JSON"""
|
||||
response = requests.post(LOGIN_ENDPOINT, data="invalid json", headers=headers)
|
||||
assert response.status_code == 422, f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
assert (
|
||||
response.status_code == 422
|
||||
), f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
def test_empty_request(self, headers):
|
||||
"""Test login with empty request body"""
|
||||
response = requests.post(LOGIN_ENDPOINT, json={}, headers=headers)
|
||||
assert response.status_code == 422, f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
assert (
|
||||
response.status_code == 422
|
||||
), f"Expected 422, got {response.status_code}. Response: {response.text}"
|
||||
|
||||
Reference in New Issue
Block a user