-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tenants): allow verbosity to be set when creating public tenant
Add a new 'verbosity' parameter to the create_public_tenant function.
- Loading branch information
Showing
2 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from unittest.mock import patch | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
from django.conf import settings | ||
|
@@ -63,21 +63,25 @@ def test_create_public_tenant_with_specified_password(): | |
assert user.check_password(secret) | ||
|
||
|
||
@patch("django_test_app.companies.models.Company.objects.create") | ||
@patch("tenant_users.tenants.utils.get_tenant_model") | ||
@pytest.mark.usefixtures("_tenant_type_settings") | ||
@pytest.mark.django_db() | ||
@pytest.mark.no_db_setup() | ||
def test_tenant_public_tenant_with_multitype(mock_create): | ||
def test_tenant_public_tenant_with_multitype(mock_get_tenant_model): | ||
"""Tests that multi-type information is used during the Public Tenant creation.""" | ||
mock_tenant_model = Mock() | ||
mock_tenant_model.objects.filter.return_value.first.return_value = None | ||
mock_get_tenant_model.return_value = mock_tenant_model | ||
|
||
# Since we're mocking, we expect an exception to be thrown after Tenant.create() | ||
with pytest.raises(ValueError, match='must be a "Company" instance'): | ||
utils.create_public_tenant("domain.test", "[email protected]") | ||
|
||
# Check the mock was called | ||
assert mock_create.called | ||
assert mock_tenant_model.called | ||
|
||
# Get the arguments it was called with | ||
_, kwargs = mock_create.call_args | ||
_, kwargs = mock_tenant_model.call_args | ||
|
||
# Ensure the multi-type database field was added during Tenant creation | ||
assert kwargs.get(settings.MULTI_TYPE_DATABASE_FIELD) == get_public_schema_name() | ||
|
@@ -116,3 +120,24 @@ def test_create_public_tenant_with_tenant_extras(): | |
# Test deleting tenant | ||
with pytest.raises(ValueError, match="Cannot delete public tenant schema"): | ||
public_tenant.delete_tenant() | ||
|
||
|
||
@patch("tenant_users.tenants.utils.get_tenant_model") | ||
@pytest.mark.django_db() | ||
@pytest.mark.no_db_setup() | ||
def test_tenant_public_tenant_save_verbosity(mock_get_tenant_model): | ||
"""Tests that the verbosity parameter is correctly passed to save().""" | ||
mock_tenant_model = Mock() | ||
mock_tenant_model.objects.filter.return_value.first.return_value = None | ||
mock_get_tenant_model.return_value = mock_tenant_model | ||
|
||
# Since we're mocking, we expect an exception to be thrown after Tenant.create() | ||
with pytest.raises(ValueError, match='must be a "Company" instance'): | ||
utils.create_public_tenant("domain.test", "[email protected]", verbosity=3) | ||
|
||
# Check the mock was called | ||
assert mock_tenant_model.called | ||
|
||
# Check that save() was called with the correct verbosity | ||
mock_tenant_instance = mock_tenant_model.return_value | ||
mock_tenant_instance.save.assert_called_once_with(verbosity=3) |