# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tests import FunctionalTest


class TestRunnerTypesController(FunctionalTest):

    def test_get_one(self):
        resp = self.app.get('/v1/runnertypes')
        self.assertEqual(resp.status_int, 200)
        self.assertTrue(len(resp.json) > 0, '/v1/runnertypes did not return correct runnertypes.')
        runnertype_id = TestRunnerTypesController.__get_runnertype_id(resp.json[0])
        resp = self.app.get('/v1/runnertypes/%s' % runnertype_id)
        retrieved_id = TestRunnerTypesController.__get_runnertype_id(resp.json)
        self.assertEqual(resp.status_int, 200)
        self.assertEqual(retrieved_id, runnertype_id,
                         '/v1/runnertypes returned incorrect runnertype.')

    def test_get_all(self):
        resp = self.app.get('/v1/runnertypes')
        self.assertEqual(resp.status_int, 200)
        self.assertTrue(len(resp.json) > 0, '/v1/runnertypes did not return correct runnertypes.')

    def test_get_one_fail(self):
        resp = self.app.get('/v1/runnertypes/1', expect_errors=True)
        self.assertEqual(resp.status_int, 404)

    @staticmethod
    def __get_runnertype_id(resp_json):
        return resp_json['id']

@@ -1733,16 +1733,29 @@
 one_fail
+_doesnt_exist
 (self):%0A
@@ -1871,16 +1871,1020 @@
 , 404)%0A%0A
+    def test_put_disable_runner(self):%0A        runnertype_id = 'action-chain'%0A        resp = self.app.get('/v1/runnertypes/%25s' %25 runnertype_id)%0A        self.assertTrue(resp.json%5B'enabled'%5D)%0A%0A        # Disable the runner%0A        update_input = resp.json%0A        update_input%5B'enabled'%5D = False%0A        update_input%5B'name'%5D = 'foobar'%0A%0A        put_resp = self.__do_put(runnertype_id, update_input)%0A        self.assertFalse(put_resp.json%5B'enabled'%5D)%0A%0A        # Verify that the name hasn't been updated - we only allow updating%0A        # enabled attribute on the runner%0A        self.assertEqual(put_resp.json%5B'name'%5D, 'action-chain')%0A%0A        # Enable the runner%0A        update_input = resp.json%0A        update_input%5B'enabled'%5D = True%0A%0A        put_resp = self.__do_put(runnertype_id, update_input)%0A        self.assertTrue(put_resp.json%5B'enabled'%5D)%0A%0A    def __do_put(self, runner_type_id, runner_type):%0A        return self.app.put_json('/v1/runnertypes/%25s' %25 runner_type_id, runner_type, expect_errors=True)%0A%0A
     @sta

Add a test case for disabling and re-enabling a runner.