forked from kiwitcms/Kiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management command to change Kiwi TCMS domain
Closes kiwitcms#971
- Loading branch information
1 parent
2f82e8c
commit ef9537b
Showing
13 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
File renamed without changes
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tcms.core.management.commands.domain module | ||
=========================================== | ||
|
||
.. automodule:: tcms.core.management.commands.domain | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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 |
---|---|---|
@@ -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 |
7 changes: 7 additions & 0 deletions
7
docs/source/modules/tcms.core.management.commands.set_domain.rst
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tcms.core.management.commands.set\_domain module | ||
================================================ | ||
|
||
.. automodule:: tcms.core.management.commands.set_domain | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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 |
---|---|---|
@@ -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 |
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
Empty file.
Empty file.
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 |
---|---|---|
@@ -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.') |
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 |
---|---|---|
@@ -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) |