-
-
Notifications
You must be signed in to change notification settings - Fork 284
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 Base URL.
Closes #971
- Loading branch information
1 parent
2f82e8c
commit d81559d
Showing
10 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
docs/source/modules/tcms.core.management.commands.baseurl.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.baseurl module | ||
============================================ | ||
|
||
.. automodule:: tcms.core.management.commands.baseurl | ||
: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.baseurl |
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 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.') |
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 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) |