diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc2039..2dde53d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ We follow [Semantic Versions](https://semver.org/) starting at the `0.4.0` release. +## 1.4.0 (2024-05-06) + +### Features +* Added management command for simple use of create_public_tenant by @jgentil in [#565](https://github.com/Corvia/django-tenant-users/pull/565) +* Adds support for Django 5.0 and Python 3.12 +* Drops support for Django 3.2 and Python 3.7 + +### Misc + +* Correct function reference in 'using' page by @Dresdn in [#532](https://github.com/Corvia/django-tenant-users/pull/532) +* Implement Ruff by @Dresdn in [#535](https://github.com/Corvia/django-tenant-users/pull/535) + + ## 1.3.0 (2023-11-14) ### Features diff --git a/docs/pages/installation.rst b/docs/pages/installation.rst index 2a6b7ba..52e5407 100644 --- a/docs/pages/installation.rst +++ b/docs/pages/installation.rst @@ -160,6 +160,13 @@ which takes care of this for you. create_public_tenant(domain_url="public.domain.com", owner_email="admin@domain.com") +Or, alternatively, use the management command: + +.. code-block:: bash + + manage.py create_public_tenant --domain_url public.domain.com --owner_email admin@domain.com + + Fin! ---- diff --git a/poetry.lock b/poetry.lock index 41a4547..b9e5f06 100644 --- a/poetry.lock +++ b/poetry.lock @@ -616,13 +616,13 @@ Django = ">=2.1,<5.1" [[package]] name = "doc8" -version = "1.0.0" +version = "1.1.1" description = "Style checker for Sphinx (or other) RST documentation" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "doc8-1.0.0-py3-none-any.whl", hash = "sha256:0c6c3104fa7f7bb2103589c0a8e272c105fdff3ddd1ef4808e51b2782185e9ab"}, - {file = "doc8-1.0.0.tar.gz", hash = "sha256:1e999a14fe415ea96d89d5053c790d01061f19b6737706b817d1579c2a07cc16"}, + {file = "doc8-1.1.1-py3-none-any.whl", hash = "sha256:e493aa3f36820197c49f407583521bb76a0fde4fffbcd0e092be946ff95931ac"}, + {file = "doc8-1.1.1.tar.gz", hash = "sha256:d97a93e8f5a2efc4713a0804657dedad83745cca4cd1d88de9186f77f9776004"}, ] [package.dependencies] @@ -734,19 +734,29 @@ files = [ orderedmultidict = ">=1.0.1" six = ">=1.8.0" +[[package]] +name = "gitignore-parser" +version = "0.1.11" +description = "A spec-compliant gitignore parser for Python 3.5+" +optional = false +python-versions = "*" +files = [ + {file = "gitignore_parser-0.1.11.tar.gz", hash = "sha256:fa10fde48b44888eeefac096f53bcdad9b87a4ffd7db788558dbdf71ff3bc9db"}, +] + [[package]] name = "hypothesis" -version = "6.79.4" +version = "6.100.4" description = "A library for property-based testing" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "hypothesis-6.79.4-py3-none-any.whl", hash = "sha256:5ce05bc70aa4f20114effaf3375dc8b51d09a04026a0cf89d4514fc0b69f6304"}, - {file = "hypothesis-6.79.4.tar.gz", hash = "sha256:e9a9ff3dc3f3eebbf214d6852882ac96ad72023f0e9770139fd3d3c1b87673e2"}, + {file = "hypothesis-6.100.4-py3-none-any.whl", hash = "sha256:f1909d4702d21be55720bbbc58e0b42172e14bf712a8ecbab00ad6ae209a5ec9"}, + {file = "hypothesis-6.100.4.tar.gz", hash = "sha256:f6858353a5fae943cae149cc618b9f2b261143df9d8d792cf1065a1b289bbb24"}, ] [package.dependencies] -attrs = ">=19.2.0" +attrs = ">=22.2.0" django = {version = ">=3.2", optional = true, markers = "extra == \"django\""} exceptiongroup = {version = ">=1.0.0", markers = "python_version < \"3.11\""} pytest = {version = ">=4.6", optional = true, markers = "extra == \"pytest\""} @@ -754,9 +764,10 @@ pytz = {version = ">=2014.1", optional = true, markers = "extra == \"pytz\""} sortedcontainers = ">=2.1.0,<3.0.0" [package.extras] -all = ["backports.zoneinfo (>=0.2.1)", "black (>=19.10b0)", "click (>=7.0)", "django (>=3.2)", "dpcontracts (>=0.4)", "importlib-metadata (>=3.6)", "lark (>=0.10.1)", "libcst (>=0.3.16)", "numpy (>=1.17.3)", "pandas (>=1.1)", "pytest (>=4.6)", "python-dateutil (>=1.4)", "pytz (>=2014.1)", "redis (>=3.0.0)", "rich (>=9.0.0)", "tzdata (>=2023.3)"] +all = ["backports.zoneinfo (>=0.2.1)", "black (>=19.10b0)", "click (>=7.0)", "crosshair-tool (>=0.0.54)", "django (>=3.2)", "dpcontracts (>=0.4)", "hypothesis-crosshair (>=0.0.2)", "lark (>=0.10.1)", "libcst (>=0.3.16)", "numpy (>=1.17.3)", "pandas (>=1.1)", "pytest (>=4.6)", "python-dateutil (>=1.4)", "pytz (>=2014.1)", "redis (>=3.0.0)", "rich (>=9.0.0)", "tzdata (>=2024.1)"] cli = ["black (>=19.10b0)", "click (>=7.0)", "rich (>=9.0.0)"] codemods = ["libcst (>=0.3.16)"] +crosshair = ["crosshair-tool (>=0.0.54)", "hypothesis-crosshair (>=0.0.2)"] dateutil = ["python-dateutil (>=1.4)"] django = ["django (>=3.2)"] dpcontracts = ["dpcontracts (>=0.4)"] @@ -767,7 +778,7 @@ pandas = ["pandas (>=1.1)"] pytest = ["pytest (>=4.6)"] pytz = ["pytz (>=2014.1)"] redis = ["redis (>=3.0.0)"] -zoneinfo = ["backports.zoneinfo (>=0.2.1)", "tzdata (>=2023.3)"] +zoneinfo = ["backports.zoneinfo (>=0.2.1)", "tzdata (>=2024.1)"] [[package]] name = "identify" @@ -1144,13 +1155,13 @@ files = [ [[package]] name = "nitpick" -version = "0.33.2" +version = "0.35.0" description = "Enforce the same settings across multiple language-independent projects" optional = false -python-versions = ">=3.7,<4.0" +python-versions = ">=3.8,<4.0" files = [ - {file = "nitpick-0.33.2-py3-none-any.whl", hash = "sha256:8b77d5968c36384c7a4cc957dc45c22bb8024e8cab83fb58fa7fbef45d3aae98"}, - {file = "nitpick-0.33.2.tar.gz", hash = "sha256:e0f9f96128f390f95409a3d27fa922484e900ac8b974646b50ea4b8a3458cad7"}, + {file = "nitpick-0.35.0-py3-none-any.whl", hash = "sha256:9911d32c2d488b41914aa1a6d230531fa92bbe3d6610e4a468a5cb5e30fab907"}, + {file = "nitpick-0.35.0.tar.gz", hash = "sha256:098167a4c65655aca52c0ea3876b1e71cf634a27d0e17b971bce9bfcc1f3febe"}, ] [package.dependencies] @@ -1163,13 +1174,15 @@ dpath = "*" flake8 = ">=3.0.0" flatten-dict = "*" furl = "*" +gitignore_parser = "*" identify = "*" -importlib-resources = {version = "*", markers = "python_version >= \"3.7\" and python_version < \"3.9\""} +importlib-resources = {version = "*", markers = "python_version >= \"3.8\" and python_version < \"3.9\""} jmespath = "*" loguru = "*" marshmallow = ">=3.0.0b10" marshmallow-polyfield = ">=5.10,<6.0" more-itertools = "*" +packaging = "*" pluggy = "*" python-slugify = "*" requests = "*" @@ -1249,13 +1262,13 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co [[package]] name = "pluggy" -version = "1.2.0" +version = "1.5.0" description = "plugin and hook calling mechanisms for python" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, - {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, ] [package.extras] @@ -1444,13 +1457,13 @@ plugins = ["importlib-metadata"] [[package]] name = "pytest" -version = "7.4.4" +version = "8.2.0" description = "pytest: simple powerful testing with Python" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, - {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, + {file = "pytest-8.2.0-py3-none-any.whl", hash = "sha256:1733f0620f6cda4095bbf0d9ff8022486e91892245bb9e7d5542c018f612f233"}, + {file = "pytest-8.2.0.tar.gz", hash = "sha256:d507d4482197eac0ba2bae2e9babf0672eb333017bcedaa5fb1a3d42c1174b3f"}, ] [package.dependencies] @@ -1458,21 +1471,21 @@ colorama = {version = "*", markers = "sys_platform == \"win32\""} exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" -pluggy = ">=0.12,<2.0" -tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} +pluggy = ">=1.5,<2.0" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] -testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] [[package]] name = "pytest-cov" -version = "4.1.0" +version = "5.0.0" description = "Pytest plugin for measuring coverage." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, - {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, + {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, + {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, ] [package.dependencies] @@ -1480,7 +1493,7 @@ coverage = {version = ">=5.2.1", extras = ["toml"]} pytest = ">=4.6" [package.extras] -testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] [[package]] name = "pytest-deadfixtures" @@ -1498,17 +1511,17 @@ pytest = ">=3.0.0" [[package]] name = "pytest-django" -version = "4.5.2" +version = "4.8.0" description = "A Django plugin for pytest." optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "pytest-django-4.5.2.tar.gz", hash = "sha256:d9076f759bb7c36939dbdd5ae6633c18edfc2902d1a69fdbefd2426b970ce6c2"}, - {file = "pytest_django-4.5.2-py3-none-any.whl", hash = "sha256:c60834861933773109334fe5a53e83d1ef4828f2203a1d6a0fa9972f4f75ab3e"}, + {file = "pytest-django-4.8.0.tar.gz", hash = "sha256:5d054fe011c56f3b10f978f41a8efb2e5adfc7e680ef36fb571ada1f24779d90"}, + {file = "pytest_django-4.8.0-py3-none-any.whl", hash = "sha256:ca1ddd1e0e4c227cf9e3e40a6afc6d106b3e70868fd2ac5798a22501271cd0c7"}, ] [package.dependencies] -pytest = ">=5.4.0" +pytest = ">=7.0.0" [package.extras] docs = ["sphinx", "sphinx-rtd-theme"] @@ -1516,13 +1529,13 @@ testing = ["Django", "django-configurations (>=2.0)"] [[package]] name = "pytest-randomly" -version = "3.12.0" +version = "3.15.0" description = "Pytest plugin to randomly order tests and control random.seed." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest-randomly-3.12.0.tar.gz", hash = "sha256:d60c2db71ac319aee0fc6c4110a7597d611a8b94a5590918bfa8583f00caccb2"}, - {file = "pytest_randomly-3.12.0-py3-none-any.whl", hash = "sha256:f4f2e803daf5d1ba036cc22bf4fe9dbbf99389ec56b00e5cba732fb5c1d07fdd"}, + {file = "pytest_randomly-3.15.0-py3-none-any.whl", hash = "sha256:0516f4344b29f4e9cdae8bce31c4aeebf59d0b9ef05927c33354ff3859eeeca6"}, + {file = "pytest_randomly-3.15.0.tar.gz", hash = "sha256:b908529648667ba5e54723088edd6f82252f540cc340d748d1fa985539687047"}, ] [package.dependencies] @@ -1531,18 +1544,18 @@ pytest = "*" [[package]] name = "pytest-testmon" -version = "2.0.15" +version = "2.1.1" description = "selects tests affected by changed files and methods" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pytest-testmon-2.0.15.tar.gz", hash = "sha256:d08efd4fe46a267c146c84d5a27cbda0080387aeaf4007c309102cb581eedbf6"}, - {file = "pytest_testmon-2.0.15-py3-none-any.whl", hash = "sha256:91c3b0cfb2f0f94cc9c429f2d279f8a97aaab91cc06eceaf7e33497666f52c94"}, + {file = "pytest-testmon-2.1.1.tar.gz", hash = "sha256:8ebe2c3de42d99306ee54cd4536fed0fc48346a954420da904b18e8d59b5da98"}, + {file = "pytest_testmon-2.1.1-py3-none-any.whl", hash = "sha256:8271ca47bc8c80760c4fc7fd7895ea786b111bbb31f13eeea879a6fd11fe2226"}, ] [package.dependencies] coverage = ">=6,<8" -pytest = ">=5,<8" +pytest = ">=5,<9" [[package]] name = "pytest-timeout" @@ -1872,26 +1885,26 @@ files = [ [[package]] name = "sphinx" -version = "5.3.0" +version = "7.1.2" description = "Python documentation generator" optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "Sphinx-5.3.0.tar.gz", hash = "sha256:51026de0a9ff9fc13c05d74913ad66047e104f56a129ff73e174eb5c3ee794b5"}, - {file = "sphinx-5.3.0-py3-none-any.whl", hash = "sha256:060ca5c9f7ba57a08a1219e547b269fadf125ae25b06b9fa7f66768efb652d6d"}, + {file = "sphinx-7.1.2-py3-none-any.whl", hash = "sha256:d170a81825b2fcacb6dfd5a0d7f578a053e45d3f2b153fecc948c37344eb4cbe"}, + {file = "sphinx-7.1.2.tar.gz", hash = "sha256:780f4d32f1d7d1126576e0e5ecc19dc32ab76cd24e950228dcf7b1f6d3d9e22f"}, ] [package.dependencies] alabaster = ">=0.7,<0.8" babel = ">=2.9" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} -docutils = ">=0.14,<0.20" +docutils = ">=0.18.1,<0.21" imagesize = ">=1.3" importlib-metadata = {version = ">=4.8", markers = "python_version < \"3.10\""} Jinja2 = ">=3.0" packaging = ">=21.0" -Pygments = ">=2.12" -requests = ">=2.5.0" +Pygments = ">=2.13" +requests = ">=2.25.0" snowballstemmer = ">=2.0" sphinxcontrib-applehelp = "*" sphinxcontrib-devhelp = "*" @@ -1902,27 +1915,27 @@ sphinxcontrib-serializinghtml = ">=1.1.5" [package.extras] docs = ["sphinxcontrib-websupport"] -lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-bugbear", "flake8-comprehensions", "flake8-simplify", "isort", "mypy (>=0.981)", "sphinx-lint", "types-requests", "types-typed-ast"] -test = ["cython", "html5lib", "pytest (>=4.6)", "typed_ast"] +lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-simplify", "isort", "mypy (>=0.990)", "ruff", "sphinx-lint", "types-requests"] +test = ["cython", "filelock", "html5lib", "pytest (>=4.6)"] [[package]] name = "sphinx-autodoc-typehints" -version = "1.23.0" +version = "2.0.1" description = "Type hints (PEP 484) support for the Sphinx autodoc extension" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "sphinx_autodoc_typehints-1.23.0-py3-none-any.whl", hash = "sha256:ac099057e66b09e51b698058ba7dd76e57e1fe696cd91b54e121d3dad188f91d"}, - {file = "sphinx_autodoc_typehints-1.23.0.tar.gz", hash = "sha256:5d44e2996633cdada499b6d27a496ddf9dbc95dd1f0f09f7b37940249e61f6e9"}, + {file = "sphinx_autodoc_typehints-2.0.1-py3-none-any.whl", hash = "sha256:f73ae89b43a799e587e39266672c1075b2ef783aeb382d3ebed77c38a3fc0149"}, + {file = "sphinx_autodoc_typehints-2.0.1.tar.gz", hash = "sha256:60ed1e3b2c970acc0aa6e877be42d48029a9faec7378a17838716cacd8c10b12"}, ] [package.dependencies] -sphinx = ">=5.3" +sphinx = ">=7.1.2" [package.extras] -docs = ["furo (>=2022.12.7)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.23.4)"] -testing = ["covdefaults (>=2.2.2)", "coverage (>=7.2.2)", "diff-cover (>=7.5)", "nptyping (>=2.5)", "pytest (>=7.2.2)", "pytest-cov (>=4)", "sphobjinv (>=2.3.1)", "typing-extensions (>=4.5)"] -type-comment = ["typed-ast (>=1.5.4)"] +docs = ["furo (>=2024.1.29)"] +numpy = ["nptyping (>=2.5)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.4.2)", "diff-cover (>=8.0.3)", "pytest (>=8.0.1)", "pytest-cov (>=4.1)", "sphobjinv (>=2.3.1)", "typing-extensions (>=4.9)"] [[package]] name = "sphinx-rtd-theme" @@ -2252,4 +2265,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "5dfba248001469f64fa4ddb6e447ca8424b3d0c0b5dcf03cfa4c706a57d614d7" +content-hash = "33d9ec5bb8130061a9782c1fddc6eeaf2d86aecd6f583785cc2979b541a6e203" diff --git a/pyproject.toml b/pyproject.toml index dd5824d..e6aabae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ include = '\.pyi?$' [tool.poetry] name = "django-tenant-users" description = "A Django app to extend django-tenants to incorporate global multi-tenant users" -version = "1.3.0" +version = "1.4.0" license = "MIT License" packages = [ @@ -62,14 +62,14 @@ mypy = "1.10.0" django-stubs = { version = "5.0.0", extras = ["compatible-mypy"] } # Code Quality -nitpick = ">=0.32,<0.34" +nitpick = ">=0.32,<0.36" safety = ">=2.2,<4.0" black = ">=22.8,<25.0" ruff = ">=0.1.14,<0.5.0" # Testing Utilities -pytest = "^7.2.2" -pytest-cov = "^4.0" +pytest = ">=7.2.2,<9.0.0" +pytest-cov = ">=4,<6" pytest-randomly = "^3.12" pytest-django = "^4.5.2" pytest-deadfixtures = "^2.2.1" @@ -93,7 +93,7 @@ optional = true [tool.poetry.group.docs.dependencies] sphinx = ">=5.0,<8.0" sphinx-rtd-theme = ">=1.3,<3.0" -sphinx-autodoc-typehints = "^1.19.5" +sphinx-autodoc-typehints = ">=1.19.5,<3.0.0" m2r2 = "^0.3" psycopg2-binary = "^2.9.6" tomli = "^2.0.1" diff --git a/tenant_users/tenants/management/__init__.py b/tenant_users/tenants/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tenant_users/tenants/management/commands/__init__.py b/tenant_users/tenants/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tenant_users/tenants/management/commands/create_public_tenant.py b/tenant_users/tenants/management/commands/create_public_tenant.py new file mode 100644 index 0000000..3937f8c --- /dev/null +++ b/tenant_users/tenants/management/commands/create_public_tenant.py @@ -0,0 +1,29 @@ +from django.core.management.base import BaseCommand + +from tenant_users.tenants.models import ExistsError, SchemaError +from tenant_users.tenants.utils import create_public_tenant + + +class Command(BaseCommand): + help = "Creates the initial public tenant" + + def add_arguments(self, parser): + parser.add_argument("--domain_url", nargs=1, required=True, type=str, + help="The URL for the public tenant's domain.") + parser.add_argument("--owner_email", nargs=1, required=True, type=str, + help="Email address of the owner user.") + + def handle(self, domain_url: str, owner_email: str, **kwargs): # noqa: ARG002, kwargs must be here. + try: + create_public_tenant(domain_url=domain_url, owner_email=owner_email) + self.stdout.write( + self.style.SUCCESS( + f"Successfully created public tenant with Domain URL ({domain_url}) and Owner ({owner_email})" + ) + ) + except (ExistsError, SchemaError) as e: + self.stdout.write( + self.style.ERROR( + f"Error creating public tenant: {e}" + ) + ) diff --git a/tests/test_tenants/test_commands.py b/tests/test_tenants/test_commands.py new file mode 100644 index 0000000..78c16bf --- /dev/null +++ b/tests/test_tenants/test_commands.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +from io import StringIO +from unittest.mock import patch + +from django.core.management import call_command + +from tenant_users.tenants.models import ExistsError + +DOMAIN_URL = "example.net" +OWNER_EMAIL = "example@example.net" +ERROR_MSG = "Schema Exists" + + +def test_create_public_tenant_command_success(): + out = StringIO() + + with patch("tenant_users.tenants.management.commands.create_public_tenant.create_public_tenant" + ) as mocked_cpt: + call_command("create_public_tenant", stdout=out, domain_url=DOMAIN_URL, + owner_email=OWNER_EMAIL) + + mocked_cpt.assert_called_once_with(domain_url=DOMAIN_URL, owner_email=OWNER_EMAIL) + out_value = out.getvalue() + assert DOMAIN_URL in out_value + assert OWNER_EMAIL in out_value + assert "Successfully created public tenant" in out_value + + +def test_create_public_tenant_command_failure(): + out = StringIO() + + with patch("tenant_users.tenants.management.commands.create_public_tenant.create_public_tenant", + side_effect=ExistsError(ERROR_MSG)) as mocked_cpt: + call_command("create_public_tenant", stdout=out, domain_url=DOMAIN_URL, + owner_email=OWNER_EMAIL) + + mocked_cpt.assert_called_once_with(domain_url=DOMAIN_URL, owner_email=OWNER_EMAIL) + out_value = out.getvalue() + assert ERROR_MSG in out_value + assert "Error creating public tenant" in out_value