Add tests to the platform app
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
==================
|
||||
- Move IMAPMockServer to its own module.
|
||||
- Display feedback message when testing a mailing profile.
|
||||
- Add tests to the platform app.
|
||||
|
||||
3.2.8 (2019-10-01)
|
||||
==================
|
||||
|
||||
@@ -9,7 +9,7 @@ class PlatformApp(MayanAppConfig):
|
||||
app_namespace = 'platform'
|
||||
app_url = 'platform'
|
||||
has_rest_api = False
|
||||
has_tests = False
|
||||
has_tests = True
|
||||
name = 'mayan.apps.platform'
|
||||
verbose_name = _('Platform')
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ except ImportError:
|
||||
from yaml import SafeLoader
|
||||
|
||||
from django.template import loader
|
||||
from django.template.base import Template
|
||||
from django.template.context import Context
|
||||
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -34,8 +36,10 @@ class PlatformTemplate(object):
|
||||
context = {}
|
||||
context_defaults = {}
|
||||
label = None
|
||||
name = None
|
||||
settings = None
|
||||
template_name = None
|
||||
template_string = None
|
||||
variables = None
|
||||
|
||||
@classmethod
|
||||
@@ -99,10 +103,15 @@ class PlatformTemplate(object):
|
||||
stream=context_string, Loader=SafeLoader
|
||||
)
|
||||
)
|
||||
return loader.render_to_string(
|
||||
template_name=self.get_template_name(),
|
||||
context=context
|
||||
)
|
||||
|
||||
if self.template_string:
|
||||
template = Template(template_string=self.template_string)
|
||||
return template.render(context=Context(dict_=context))
|
||||
else:
|
||||
return loader.render_to_string(
|
||||
template_name=self.get_template_name(),
|
||||
context=context
|
||||
)
|
||||
|
||||
|
||||
class PlatformTemplateSupervisord(PlatformTemplate):
|
||||
@@ -159,9 +168,7 @@ class PlatformTemplateSupervisord(PlatformTemplate):
|
||||
)
|
||||
|
||||
def get_context(self):
|
||||
return {
|
||||
'workers': Worker.all()
|
||||
}
|
||||
return {'workers': Worker.all()}
|
||||
|
||||
|
||||
class PlatformTemplateSupervisordDocker(PlatformTemplate):
|
||||
|
||||
@@ -40,6 +40,8 @@ class Command(management.BaseCommand):
|
||||
)
|
||||
exit(1)
|
||||
else:
|
||||
self.stdout.write(template().render(
|
||||
context_string=options.get('context'))
|
||||
self.stdout.write(
|
||||
template().render(
|
||||
context_string=options.get('context')
|
||||
)
|
||||
)
|
||||
|
||||
0
mayan/apps/platform/tests/__init__.py
Normal file
0
mayan/apps/platform/tests/__init__.py
Normal file
61
mayan/apps/platform/tests/test_management_commands.py
Normal file
61
mayan/apps/platform/tests/test_management_commands.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
from django.core import management
|
||||
from django.test import TestCase
|
||||
|
||||
from ..classes import PlatformTemplate
|
||||
|
||||
TEST_TEMPLATE_LABEL = 'test template label'
|
||||
TEST_TEMPLATE_NAME = 'test_template_name'
|
||||
TEST_TEMPLATE_STRING = '''
|
||||
test template string
|
||||
test template variable: {{ test_template_variable }}
|
||||
'''
|
||||
TEST_TEMPLATE_VARIABLE_VALUE = 'test_variable_value'
|
||||
TEST_TEMPLATE_VARIABLE_VALUE_ALT = 'test_variable_value_alt'
|
||||
TEST_TEMPLATE_STRING_RENDER = '''
|
||||
test template string
|
||||
test template variable: {}
|
||||
'''.format(TEST_TEMPLATE_VARIABLE_VALUE)
|
||||
TEST_TEMPLATE_STRING_RENDER_ALT = '''
|
||||
test template string
|
||||
test template variable: {}
|
||||
'''.format(TEST_TEMPLATE_VARIABLE_VALUE_ALT)
|
||||
|
||||
|
||||
class TestPlatformTemplate(PlatformTemplate):
|
||||
context = {'test_template_variable': TEST_TEMPLATE_VARIABLE_VALUE}
|
||||
label = TEST_TEMPLATE_LABEL
|
||||
name = TEST_TEMPLATE_NAME
|
||||
template_string = TEST_TEMPLATE_STRING
|
||||
|
||||
|
||||
PlatformTemplate.register(klass=TestPlatformTemplate)
|
||||
|
||||
|
||||
class PlatformTemplateManagementCommandTestCase(TestCase):
|
||||
|
||||
def test_platform_template_simple(self):
|
||||
output = BytesIO()
|
||||
args = (TEST_TEMPLATE_NAME,)
|
||||
options = {
|
||||
'stdout': output
|
||||
}
|
||||
management.call_command('platformtemplate', *args, **options)
|
||||
self.assertEqual(output.getvalue(), TEST_TEMPLATE_STRING_RENDER)
|
||||
|
||||
def test_platform_template_context(self):
|
||||
output = BytesIO()
|
||||
args = (
|
||||
TEST_TEMPLATE_NAME, '--context',
|
||||
'test_template_variable: {}'.format(
|
||||
TEST_TEMPLATE_VARIABLE_VALUE_ALT
|
||||
)
|
||||
)
|
||||
options = {
|
||||
'stdout': output
|
||||
}
|
||||
management.call_command('platformtemplate', *args, **options)
|
||||
self.assertEqual(output.getvalue(), TEST_TEMPLATE_STRING_RENDER_ALT)
|
||||
Reference in New Issue
Block a user