Skip to content

Commit

Permalink
Add management command to change Kiwi TCMS domain
Browse files Browse the repository at this point in the history
Closes #971
  • Loading branch information
schwarzkrieger committed May 13, 2020
1 parent 2f82e8c commit ef9537b
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 16 deletions.
File renamed without changes
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
2 changes: 1 addition & 1 deletion docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ to update some of them for your particular production environment.

After adjusting settings for your environment you have to configure
Kiwi TCMS via its web interface! As a minimum you have to
:ref:`configure-kiwi-base-url` and :ref:`configure-bug-trackers`!
:ref:`configure-kiwi-domain` and :ref:`configure-bug-trackers`!

.. note::

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-domain:

Configuration of Kiwi TCMS domain
---------------------------------

The first step you need to do is to configure the domain 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 the domain is
to use the command line tool::

docker exec -it kiwi_web /Kiwi/manage.py set_domain 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!

|Domain 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!


.. |Domain configuration| image:: ./_static/Configure_domain.png
7 changes: 7 additions & 0 deletions docs/source/modules/tcms.core.management.commands.domain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tcms.core.management.commands.domain module
===========================================

.. automodule:: tcms.core.management.commands.domain
: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.set_domain
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tcms.core.management.commands.set\_domain module
================================================

.. automodule:: tcms.core.management.commands.set_domain
:members:
:undoc-members:
:show-inheritance:
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/set_domain.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 domain of Kiwi TCMS instance. "
"If no arguments given returns current domain."
)

def add_arguments(self, parser):
parser.add_argument(
'domain', nargs='?', default=None,
help='The domain of Kiwi TCMS instance',
)

def handle(self, *args, **kwargs):
site = Site.objects.get(id=settings.SITE_ID)
if not kwargs['domain']:
self.stdout.write('%s' % (site.domain))
return
site.domain = kwargs['domain']
site.name = "Kiwi TCMS"
site.save()
self.stdout.write('Domain updated successfully.')
27 changes: 27 additions & 0 deletions tcms/core/tests/test_set_domain.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 TestSetDomainCommand(TestCase):
"""Test manage.py set_domain command"""

def test_without_params_returns_domain(self):
"""Test command without params returns current domain"""
out = StringIO()
call_command('set_domain', stdout=out)
self.assertEqual(
'127.0.0.1:8000\n',
out.getvalue())

def test_set_domain(self):
"""Test if command sets the domain correctly"""
out = StringIO()
newdomain = "kiwi.test.bogus:1234"
call_command('set_domain', newdomain, stdout=out)
site = Site.objects.get(id=settings.SITE_ID)
self.assertEqual(newdomain, site.domain)
self.assertEqual('Kiwi TCMS', site.name)

0 comments on commit ef9537b

Please sign in to comment.