Skip to content

Commit

Permalink
Add management command to change Base URL.
Browse files Browse the repository at this point in the history
Closes #971
  • Loading branch information
schwarzkrieger committed May 10, 2020
1 parent 2f82e8c commit d81559d
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 15 deletions.
15 changes: 0 additions & 15 deletions docs/source/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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://<your_domain_or_ip>/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:

Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions docs/source/installing_docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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://<your_domain_or_ip>/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
---------

Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions docs/source/modules/tcms.core.management.commands.baseurl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tcms.core.management.commands.baseurl module
============================================

.. automodule:: tcms.core.management.commands.baseurl
:members:
:undoc-members:
:show-inheritance:
15 changes: 15 additions & 0 deletions docs/source/modules/tcms.core.management.commands.rst
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions docs/source/modules/tcms.core.management.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docs/source/modules/tcms.core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions tcms/core/management/commands/baseurl.py
Original file line number Diff line number Diff line change
@@ -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.')
27 changes: 27 additions & 0 deletions tcms/core/tests/test_baseurl.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d81559d

Please sign in to comment.