Test new Exoscale API
This commit is contained in:
parent
039b4a7031
commit
2e7143245a
2 changed files with 509 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import base64
|
||||
|
||||
import pytest
|
||||
|
||||
from servala.core.models import (
|
||||
|
|
@ -6,6 +8,13 @@ from servala.core.models import (
|
|||
OrganizationOrigin,
|
||||
User,
|
||||
)
|
||||
from servala.core.models.service import (
|
||||
CloudProvider,
|
||||
Plan,
|
||||
Service,
|
||||
ServiceCategory,
|
||||
ServiceOffering,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -30,3 +39,86 @@ def org_owner(organization):
|
|||
organization=organization, user=user, role="owner"
|
||||
)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_service_category():
|
||||
return ServiceCategory.objects.create(
|
||||
name="Databases",
|
||||
description="Database services",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_service(test_service_category):
|
||||
return Service.objects.create(
|
||||
name="Redis",
|
||||
slug="redis",
|
||||
category=test_service_category,
|
||||
description="Redis database service",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_cloud_provider():
|
||||
return CloudProvider.objects.create(
|
||||
name="Exoscale",
|
||||
description="Exoscale cloud provider",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_service_offering(test_service, test_cloud_provider):
|
||||
return ServiceOffering.objects.create(
|
||||
service=test_service,
|
||||
provider=test_cloud_provider,
|
||||
description="Redis on Exoscale",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_plan(test_service_offering):
|
||||
return Plan.objects.create(
|
||||
name="Small",
|
||||
description="Small Redis plan",
|
||||
term=1,
|
||||
service_offering=test_service_offering,
|
||||
features={"memory": "1GB", "connections": 100},
|
||||
pricing={"monthly": 10.0},
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def osb_client(client):
|
||||
credentials = base64.b64encode(b"testuser:testpass").decode("ascii")
|
||||
client.defaults = {"HTTP_AUTHORIZATION": f"Basic {credentials}"}
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_odoo_success(mocker):
|
||||
"""
|
||||
Mock Odoo client with successful responses for organization creation.
|
||||
Returns the mock object for further customization if needed.
|
||||
"""
|
||||
mock_client = mocker.patch("servala.core.models.organization.CLIENT")
|
||||
|
||||
# Default successful responses for organization creation
|
||||
mock_client.execute.side_effect = [
|
||||
123, # company_id
|
||||
456, # invoice_address_id
|
||||
789, # sale_order_id
|
||||
]
|
||||
mock_client.search_read.return_value = [{"name": "SO001"}]
|
||||
|
||||
return mock_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_odoo_failure(mocker):
|
||||
"""
|
||||
Mock Odoo client that raises an exception to simulate failure.
|
||||
"""
|
||||
mock_client = mocker.patch("servala.core.models.organization.CLIENT")
|
||||
mock_client.execute.side_effect = Exception("Odoo connection failed")
|
||||
return mock_client
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue