def handle(self, *args, **options): if len(args) != 4: raise CommandError("must provide all parameters") name, url, username, password = args import_jenkinsserver( name, url, username, password, update=options["update"], stdout=self.stdout) transaction.commit_unless_managed()
def test_import_jenkinsserver(self): """ We can import a new keypair with a name. """ stdout = StringIO() import_jenkinsserver( "server1", "http://example.com/", "admin", "testing", stdout=stdout) server = JenkinsServer.objects.get(name="server1") self.assertEqual("http://example.com/", server.url) self.assertEqual("admin", server.username) self.assertEqual("testing", server.password) self.assertEqual("Server created\n", stdout.getvalue())
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_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(self): """ We can import a new keypair with a name. """ stdout = StringIO() import_jenkinsserver("server1", "http://example.com/", "admin", "testing", stdout=stdout) server = JenkinsServer.objects.get(name="server1") self.assertEqual("http://example.com/", server.url) self.assertEqual("admin", server.username) self.assertEqual("testing", server.password) self.assertEqual("Server created\n", stdout.getvalue())
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())