def test_verify_server_with_authentication_error(self): """ Verify a server setup for use with Capomastro. """ server = JenkinsServerFactory.create() with mock.patch("jenkins.models.Jenkins", spec=jenkins.Jenkins) as mock_jenkins: error = HTTPError(401, "No authentication") mock_jenkins.side_effect = error messages = verify_jenkinsserver(server) mock_jenkins.assert_called_with(server.url, username=u"root", password=u"testing") self.assertEqual(["ERROR: [Errno 401] No authentication"], messages)
def test_import_jenkinsserver_fails_with_preexisting_name(self): """ import_jenkinsserver should fail if we have a server with that name. """ server = JenkinsServerFactory.create(name="testing", url="http://example.com/") with self.assertRaises(CommandError) as cm: import_jenkinsserver("testing", "http://example.com/2", "admin", "password") self.assertEqual("Server already exists", str(cm.exception)) server = JenkinsServer.objects.get(name=server.name) self.assertEqual("http://example.com/", server.url) self.assertEqual("root", server.username) self.assertEqual("testing", server.password)
def test_import_jenkinsserver_updates_existing_server(self): """ import_jenkinsserver should update update the details if we supply the update parameter. """ stdout = StringIO() server = JenkinsServerFactory.create() import_jenkinsserver( server.name, "http://www1.example.com/", "admin", "secret", update=True, stdout=stdout) server = JenkinsServer.objects.get(name=server.name) self.assertEqual("http://www1.example.com/", server.url) self.assertEqual("admin", server.username) self.assertEqual("secret", server.password) self.assertEqual("Server updated\n", stdout.getvalue())
def test_import_jenkinsserver_fails_with_preexisting_name(self): """ import_jenkinsserver should fail if we have a server with that name. """ server = JenkinsServerFactory.create( name="testing", url="http://example.com/") with self.assertRaises(CommandError) as cm: import_jenkinsserver( "testing", "http://example.com/2", "admin", "password") self.assertEqual("Server already exists", str(cm.exception)) server = JenkinsServer.objects.get(name=server.name) self.assertEqual("http://example.com/", server.url) self.assertEqual("root", server.username) self.assertEqual("testing", server.password)
def test_verify_server_with_authentication_error(self): """ Verify a server setup for use with Capomastro. """ server = JenkinsServerFactory.create() with mock.patch( "jenkins.models.Jenkins", spec=jenkins.Jenkins) as mock_jenkins: error = HTTPError(401, "No authentication") mock_jenkins.side_effect = error messages = verify_jenkinsserver(server) mock_jenkins.assert_called_with( server.url, username=u"root", password=u"testing") self.assertEqual( ["ERROR: [Errno 401] No authentication"], messages)
def test_verify_server(self): """ Verify a server setup for use with Capomastro. """ server = JenkinsServerFactory.create() # TODO: This is a fragile test because it doesn't completely mock out # the Plugins object that's returned by get_plugins. with mock.patch("jenkins.models.Jenkins", spec=jenkins.Jenkins) as mock_jenkins: messages = verify_jenkinsserver(server) mock_jenkins.assert_called_with(server.url, username=u"root", password=u"testing") mock_jenkins.return_value.get_plugins.assert_called_once() self.assertEqual(["Missing plugins: notification"], messages)
def test_verify_server(self): """ Verify a server setup for use with Capomastro. """ server = JenkinsServerFactory.create() # TODO: This is a fragile test because it doesn't completely mock out # the Plugins object that's returned by get_plugins. with mock.patch( "jenkins.models.Jenkins", spec=jenkins.Jenkins) as mock_jenkins: messages = verify_jenkinsserver(server) mock_jenkins.assert_called_with( server.url, username=u"root", password=u"testing") mock_jenkins.return_value.get_plugins.assert_called_once() self.assertEqual( ["Missing plugins: notification"], messages)
def test_import_jenkinsserver_updates_existing_server(self): """ import_jenkinsserver should update update the details if we supply the update parameter. """ stdout = StringIO() server = JenkinsServerFactory.create() import_jenkinsserver(server.name, "http://www1.example.com/", "admin", "secret", update=True, stdout=stdout) server = JenkinsServer.objects.get(name=server.name) self.assertEqual("http://www1.example.com/", server.url) self.assertEqual("admin", server.username) self.assertEqual("secret", server.password) self.assertEqual("Server updated\n", stdout.getvalue())
def setUp(self): self.user = User.objects.create_superuser( "testing", "*****@*****.**", "password") self.jobtype = JobTypeFactory.create( config_xml="this is the job xml") self.server = JenkinsServerFactory.create()