October feature list #226
2 changed files with 32 additions and 37 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import json
|
||||
import logging
|
||||
from contextlib import suppress
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_not_required
|
||||
|
|
@ -102,24 +101,22 @@ class OSBServiceInstanceView(OSBBasicAuthPermission, View):
|
|||
)
|
||||
|
||||
exoscale_origin = get_exoscale_origin()
|
||||
with suppress(Organization.DoesNotExist):
|
||||
try:
|
||||
organization = Organization.objects.get(
|
||||
osb_guid=organization_guid, origin=exoscale_origin
|
||||
)
|
||||
self._send_service_welcome_email(
|
||||
request, organization, user, service, service_offering
|
||||
)
|
||||
organization.limit_osb_services.add(service)
|
||||
if service in organization.limit_osb_services.all():
|
||||
return JsonResponse({"message": "Service already enabled"}, status=200)
|
||||
|
||||
except Organization.DoesNotExist:
|
||||
odoo_data = {
|
||||
"company_name": organization_display_name,
|
||||
"invoice_email": user.email,
|
||||
}
|
||||
try:
|
||||
with transaction.atomic():
|
||||
try:
|
||||
billing_entity = BillingEntity.create_from_data(
|
||||
name=f"{organization_display_name} (Exoscale)", odoo_data=odoo_data
|
||||
name=f"{organization_display_name} (Exoscale)",
|
||||
odoo_data=odoo_data,
|
||||
)
|
||||
organization = Organization(
|
||||
name=organization_display_name,
|
||||
|
|
@ -128,19 +125,15 @@ class OSBServiceInstanceView(OSBBasicAuthPermission, View):
|
|||
osb_guid=organization_guid,
|
||||
)
|
||||
organization = Organization.create_organization(organization, user)
|
||||
|
||||
self._send_invitation_email(request, organization, user)
|
||||
except Exception:
|
||||
return JsonResponse({"error": "Internal server error"}, status=500)
|
||||
|
||||
organization.limit_osb_services.add(service)
|
||||
self._send_service_welcome_email(
|
||||
request, organization, user, service, service_offering
|
||||
)
|
||||
|
||||
return JsonResponse(
|
||||
{"message": "Successfully enabled service"}, status=201
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating organization for Exoscale: {str(e)}")
|
||||
return JsonResponse({"error": "Internal server error"}, status=500)
|
||||
return JsonResponse({"message": "Successfully enabled service"}, status=201)
|
||||
|
||||
def _send_invitation_email(self, request, organization, user):
|
||||
subject = f"Welcome to Servala - {organization.name}"
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ def test_successful_onboarding_new_organization(
|
|||
|
||||
assert org.odoo_sale_order_id == 789
|
||||
assert org.odoo_sale_order_name == "SO001"
|
||||
assert org.limit_osb_services.all().count() == 1
|
||||
|
||||
assert len(mail.outbox) == 2
|
||||
invitation_email = mail.outbox[0]
|
||||
|
|
@ -107,11 +108,12 @@ def test_duplicate_organization_returns_existing(
|
|||
exoscale_origin,
|
||||
instance_id,
|
||||
):
|
||||
Organization.objects.create(
|
||||
org = Organization.objects.create(
|
||||
name="Existing Org",
|
||||
osb_guid="test-org-guid-123",
|
||||
origin=exoscale_origin,
|
||||
)
|
||||
org.limit_osb_services.add(test_service)
|
||||
|
||||
valid_osb_payload["service_id"] = test_service.osb_service_id
|
||||
valid_osb_payload["plan_id"] = test_service_offering.osb_plan_id
|
||||
|
|
@ -126,7 +128,7 @@ def test_duplicate_organization_returns_existing(
|
|||
response_data = json.loads(response.content)
|
||||
assert response_data["message"] == "Service already enabled"
|
||||
assert Organization.objects.filter(osb_guid="test-org-guid-123").count() == 1
|
||||
assert len(mail.outbox) == 1 # Only one email was sent
|
||||
assert len(mail.outbox) == 0 # No email necessary
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue