From d81559dcd5eba11caf9a6cd1cc7c116c222c3cf5 Mon Sep 17 00:00:00 2001 From: Ivajlo Karabojkov Date: Sun, 10 May 2020 13:18:47 +0300 Subject: [PATCH] Add management command to change Base URL. Closes #971 --- docs/source/admin.rst | 15 ----------- docs/source/installing_docker.rst | 25 +++++++++++++++++ .../tcms.core.management.commands.baseurl.rst | 7 +++++ .../modules/tcms.core.management.commands.rst | 15 +++++++++++ docs/source/modules/tcms.core.management.rst | 15 +++++++++++ docs/source/modules/tcms.core.rst | 1 + tcms/core/management/__init__.py | 0 tcms/core/management/commands/__init__.py | 0 tcms/core/management/commands/baseurl.py | 25 +++++++++++++++++ tcms/core/tests/test_baseurl.py | 27 +++++++++++++++++++ 10 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 docs/source/modules/tcms.core.management.commands.baseurl.rst create mode 100644 docs/source/modules/tcms.core.management.commands.rst create mode 100644 docs/source/modules/tcms.core.management.rst create mode 100644 tcms/core/management/__init__.py create mode 100644 tcms/core/management/commands/__init__.py create mode 100644 tcms/core/management/commands/baseurl.py create mode 100644 tcms/core/tests/test_baseurl.py diff --git a/docs/source/admin.rst b/docs/source/admin.rst index 9f281854d6..abb64e9cfa 100644 --- a/docs/source/admin.rst +++ b/docs/source/admin.rst @@ -14,20 +14,6 @@ user to add, edit and delete records in the database. |The Administration screen| -.. _configure-kiwi-base-url: - -Configure Kiwi's base URL -------------------------- - -The first step you need to do is configure the base URL of your Kiwi TCMS -installation. This is used to construct links to test plans, test cases, etc. -The default value is ``127.0.0.1:8000`` which is suitable if you are running -in devel mode. To update the setting go to -``https:///admin/sites/site/1/``! -Update **Domain name** to the fully qualified domain name or IP address, -including port if necessary and click the Save button! - -|Base URL configuration| .. _configure-bug-trackers: @@ -398,7 +384,6 @@ For this purpose the following fields are available: within a certain wight group Kiwi TCMS will crash! -.. |Base URL configuration| image:: ./_static/Configure_base_url.png .. |The Administration screen| image:: ./_static/Admin_Home.png .. |The Auth screen| image:: ./_static/Auth_Home.png .. |The Admin menu 1| image:: ./_static/Click_Auth.png diff --git a/docs/source/installing_docker.rst b/docs/source/installing_docker.rst index 1b1504c075..efd3d71c2f 100644 --- a/docs/source/installing_docker.rst +++ b/docs/source/installing_docker.rst @@ -79,6 +79,28 @@ You need to create the database schema by executing:: docker exec -it kiwi_web /Kiwi/manage.py createsuperuser +.. _configure-kiwi-base-url: + +Configuration of Kiwi's base URL +-------------------------------- + +The first step you need to do is configure the base URL of your Kiwi TCMS +installation. This is used to construct links to test plans, test cases, etc. +The default value is ``127.0.0.1:8000`` which is suitable if you are running +in devel mode. The easiest and automation-friendly way to set base URL is +to use command line tool:: + + ./manage.py baseurl https://public.tenant.kiwitcms.org + + +To update the setting using web interface go to +``https:///admin/sites/site/1/``! +Update **Domain name** to the fully qualified domain name or IP address, +including port if necessary and click the Save button! + +|Base URL configuration| + + Upgrading --------- @@ -340,3 +362,6 @@ the default 500 error page. When reporting issues please copy the relevant traceback as plain text into your reports! + + +.. |Base URL configuration| image:: ./_static/Configure_base_url.png diff --git a/docs/source/modules/tcms.core.management.commands.baseurl.rst b/docs/source/modules/tcms.core.management.commands.baseurl.rst new file mode 100644 index 0000000000..c259dc5025 --- /dev/null +++ b/docs/source/modules/tcms.core.management.commands.baseurl.rst @@ -0,0 +1,7 @@ +tcms.core.management.commands.baseurl module +============================================ + +.. automodule:: tcms.core.management.commands.baseurl + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/modules/tcms.core.management.commands.rst b/docs/source/modules/tcms.core.management.commands.rst new file mode 100644 index 0000000000..b9233a8bb5 --- /dev/null +++ b/docs/source/modules/tcms.core.management.commands.rst @@ -0,0 +1,15 @@ +tcms.core.management.commands package +===================================== + +.. automodule:: tcms.core.management.commands + :members: + :undoc-members: + :show-inheritance: + +Submodules +---------- + +.. toctree:: + :maxdepth: 4 + + tcms.core.management.commands.baseurl diff --git a/docs/source/modules/tcms.core.management.rst b/docs/source/modules/tcms.core.management.rst new file mode 100644 index 0000000000..d42b4ea3bf --- /dev/null +++ b/docs/source/modules/tcms.core.management.rst @@ -0,0 +1,15 @@ +tcms.core.management package +============================ + +.. automodule:: tcms.core.management + :members: + :undoc-members: + :show-inheritance: + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + tcms.core.management.commands diff --git a/docs/source/modules/tcms.core.rst b/docs/source/modules/tcms.core.rst index 621ac2ff27..e2d7dfc776 100644 --- a/docs/source/modules/tcms.core.rst +++ b/docs/source/modules/tcms.core.rst @@ -15,6 +15,7 @@ Subpackages tcms.core.contrib tcms.core.forms tcms.core.helpers + tcms.core.management tcms.core.models tcms.core.templatetags tcms.core.utils diff --git a/tcms/core/management/__init__.py b/tcms/core/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tcms/core/management/commands/__init__.py b/tcms/core/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tcms/core/management/commands/baseurl.py b/tcms/core/management/commands/baseurl.py new file mode 100644 index 0000000000..1d43f0e14d --- /dev/null +++ b/tcms/core/management/commands/baseurl.py @@ -0,0 +1,25 @@ +from django.conf import settings +from django.contrib.sites.models import Site +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + help = ("Sets the base URL of Kiwi TCMS instance. " + "If no arguments given returns current base URL." + ) + + def add_arguments(self, parser): + parser.add_argument( + 'baseurl', nargs='?', default=None, + help='Base URL of Kiwi TCMS instance', + ) + + def handle(self, *args, **kwargs): + site = Site.objects.get(id=settings.SITE_ID) + if not kwargs['baseurl']: + self.stdout.write('%s' % (site.domain)) + return + site.domain = kwargs['baseurl'] + site.name = "Kiwi TCMS" + site.save() + self.stdout.write('Base URL updated successfully.') diff --git a/tcms/core/tests/test_baseurl.py b/tcms/core/tests/test_baseurl.py new file mode 100644 index 0000000000..ca41ea42e3 --- /dev/null +++ b/tcms/core/tests/test_baseurl.py @@ -0,0 +1,27 @@ +from io import StringIO + +from django.conf import settings +from django.contrib.sites.models import Site +from django.core.management import call_command +from django.test import TestCase + + +class TestBaseurl(TestCase): + """Test manage.py baseurl command""" + + def test_without_params_returns_domain(self): + """Test command without arguments returns current Base URL""" + out = StringIO() + call_command('baseurl', stdout=out) + self.assertEqual( + '127.0.0.1:8000\n', + out.getvalue()) + + def test_set_url(self): + """Test if command sets Base URL correctly""" + out = StringIO() + newurl = "https://kiwi.test.bogus:1234" + call_command('baseurl', newurl, stdout=out) + site = Site.objects.get(id=settings.SITE_ID) + self.assertEqual(newurl, site.domain) + self.assertEqual('Kiwi TCMS', site.name)