More tests

This commit is contained in:
Brandon Konkle 2013-08-08 01:22:41 -05:00
parent e06346dfe9
commit 93d1125ff1
2 changed files with 76 additions and 5 deletions

View file

@ -1,8 +1,4 @@
django>=1.5
pylint>=0.23
coverage>=3.4
pyflakes
pep8>=1.3
lettuce
selenium
flake8
mock>=1.0.1

View file

@ -0,0 +1,75 @@
from mock import MagicMock, patch
from django.test import TestCase
from discover_jenkins import runner, tasks
class FakeTestRunner(object):
"""
A fake object to stub out the base methods that the mixin's super() calls
require.
"""
def setup_test_environment(self):
pass
def teardown_test_environment(self):
pass
class Runner(runner.CIRunner, FakeTestRunner):
"""CIRunner is a mixin, so use the FakeTestRunner as a base"""
pass
class TestCIRunner(TestCase):
def test_get_tasks(self):
"""
Make sure the correct tasks are imported based on the
test_project.settings.
"""
self.assertEqual(runner.get_tasks(),
[tasks.with_coverage.CoverageTask,
tasks.run_pylint.PyLintTask,
tasks.run_jshint.JSHintTask,
tasks.run_sloccount.SlocCountTask])
def test_get_task_options(self):
"""
For now, just do a simple test to make sure the right number of options
are gleaned from the tasks.
"""
self.assertEqual(len(runner.get_task_options()), 14)
def test_setup_test_environment(self):
"""
Make sure the setup_test_environment method on a task is triggered by
the runner.
"""
mock_task = MagicMock()
with patch.object(Runner, '__init__') as mock_init:
mock_init.return_value = None
cirun = Runner()
cirun.jenkins = True
cirun.tasks = [mock_task]
cirun.setup_test_environment()
self.assertTrue(mock_task.setup_test_environment.called)
def test_teardown_test_environment(self):
"""
Make sure the setup_test_environment method on a task is triggered by
the runner.
"""
mock_task = MagicMock()
with patch.object(Runner, '__init__') as mock_init:
mock_init.return_value = None
cirun = Runner()
cirun.jenkins = True
cirun.tasks = [mock_task]
cirun.teardown_test_environment()
self.assertTrue(mock_task.teardown_test_environment.called)