From 93d1125ff104f76abc1dc3c60b5f89e503d5249c Mon Sep 17 00:00:00 2001 From: Brandon Konkle Date: Thu, 8 Aug 2013 01:22:41 -0500 Subject: [PATCH] More tests --- tests/requirements.pip | 6 +-- tests/tests/test_runner.py | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 tests/tests/test_runner.py diff --git a/tests/requirements.pip b/tests/requirements.pip index b5c4253..2971ce7 100644 --- a/tests/requirements.pip +++ b/tests/requirements.pip @@ -1,8 +1,4 @@ django>=1.5 pylint>=0.23 coverage>=3.4 -pyflakes -pep8>=1.3 -lettuce -selenium -flake8 +mock>=1.0.1 diff --git a/tests/tests/test_runner.py b/tests/tests/test_runner.py new file mode 100644 index 0000000..b6e0346 --- /dev/null +++ b/tests/tests/test_runner.py @@ -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) +