From ef018c9c1c310c51e07dc326d208720e778bc489 Mon Sep 17 00:00:00 2001 From: lphoward Date: Tue, 15 Oct 2013 07:33:45 -0500 Subject: [PATCH] added tests for parameterized builds for issue [#178] --- .../systests/test_parameterized_builds.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/jenkinsapi_tests/systests/test_parameterized_builds.py b/jenkinsapi_tests/systests/test_parameterized_builds.py index ba4cc15..680feb4 100644 --- a/jenkinsapi_tests/systests/test_parameterized_builds.py +++ b/jenkinsapi_tests/systests/test_parameterized_builds.py @@ -8,6 +8,8 @@ from jenkinsapi_tests.systests.base import BaseSystemTest from jenkinsapi_tests.test_utils.random_strings import random_string from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE from jenkinsapi_tests.systests.job_configs import JOB_WITH_PARAMETERS +from jenkinsapi.custom_exceptions import WillNotBuild + class TestParameterizedBuilds(BaseSystemTest): @@ -46,5 +48,48 @@ class TestParameterizedBuilds(BaseSystemTest): self.assertIn(param_B, b.get_console()) + def test_parameterized_job_build_queuing(self): + """Accept multiple builds of parameterized jobs with unique + parameters.""" + job_name = 'create_%s' % random_string() + job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS) + + for i in range(3): + param_B = random_string() + params = {'B': param_B} + job.invoke(build_params=params) + + self.assertTrue(job.has_queued_build(params)) + + while(job.has_queued_build(params)): + time.sleep(0.25) + + b = job.get_last_build() + while b.is_running(): + time.sleep(0.25) + + artifacts = b.get_artifact_dict() + self.assertIsInstance(artifacts, dict) + artB = artifacts['b.txt'] + self.assertTrue(artB.get_data().strip(), param_B) + + self.assertIn(param_B, b.get_console()) + + def test_parameterized_job_build_rejection(self): + """Reject build of paramterized job when existing build with same + parameters is queued, raising WillNotBuild.""" + job_name = 'create_%s' % random_string() + job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS) + + for i in range(3): + params = {'B': random_string()} + job.invoke(build_params=params) + + with self.assertRaises(WillNotBuild) as na: + job.invoke(build_params=params) + expected_msg = 'A build with these parameters is already queued.' + self.assertEqual(na.exception.message, expected_msg) + + if __name__ == '__main__': unittest.main() -- 2.7.4