Fixed SSH test cases
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
"""Pytest fixtures for API tests."""
|
||||
import pytest
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from gatehouse_app import create_app, db
|
||||
from gatehouse_app.models.user.user import User
|
||||
from gatehouse_app.models.organization.organization import Organization
|
||||
from gatehouse_app.models.organization.organization_member import OrganizationMember
|
||||
from gatehouse_app.models.ssh_ca.ca import CA, CaType, KeyType
|
||||
from gatehouse_app.utils.constants import OrganizationRole
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
"""Create test Flask app with in-memory SQLite."""
|
||||
app = create_app(config_name="testing")
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
|
||||
app.config["TESTING"] = True
|
||||
app.config["WTF_CSRF_ENABLED"] = False
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
yield app
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_user(app):
|
||||
"""Create a test user."""
|
||||
with app.app_context():
|
||||
user = User(email="test_user@test.com", full_name="Test User")
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return user.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_org(app):
|
||||
"""Create a test organization."""
|
||||
with app.app_context():
|
||||
org = Organization(name="Test Org", slug="test-org")
|
||||
db.session.add(org)
|
||||
db.session.commit()
|
||||
return org.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_membership(app, test_user, test_org):
|
||||
"""Create a test membership."""
|
||||
with app.app_context():
|
||||
membership = OrganizationMember(
|
||||
user_id=test_user,
|
||||
organization_id=test_org,
|
||||
role=OrganizationRole.MEMBER,
|
||||
)
|
||||
db.session.add(membership)
|
||||
db.session.commit()
|
||||
return membership.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_ca(app, test_org, test_membership):
|
||||
"""Create a test CA."""
|
||||
with app.app_context():
|
||||
ca = CA(
|
||||
organization_id=test_org,
|
||||
name="Test CA",
|
||||
ca_type=CaType.USER,
|
||||
key_type=KeyType.ED25519,
|
||||
private_key="encrypted_private_key_placeholder",
|
||||
public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...",
|
||||
fingerprint="sha256:TEST123...",
|
||||
is_active=True,
|
||||
)
|
||||
db.session.add(ca)
|
||||
db.session.commit()
|
||||
return ca.id
|
||||
Reference in New Issue
Block a user