Ejemplo n.º 1
0
    def test_conditional_miss2(self):

        serialized_input = {
            "key": "alias",
            "title": "Alias",
            "type": "string",
            "help": "Name of alias to assign this custom dev stack",
            "required": True,
            "conditions": {
                "kvps": "env:dev,date:today"
            }
        }

        inputs = Input(serialized_input)

        params = Params({"env": {"value": "dev"}})

        # inject an invalid response followed by a valid response
        sys.stdin = io.StringIO("my-stack")

        value, user_prompted = inputs.process(params)

        # test that the user was not prompted and that no value was returned
        self.assertTrue(not user_prompted)
        self.assertTrue(not value)
Ejemplo n.º 2
0
    def test_bool(self):

        serialized_input = {
            "key": "rebuild",
            "title": "Rebuilt",
            "type": "bool",
            "help": "Rebuild the stack?",
            "required": True
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject the correct response to inputs prompt into stdin
        sys.stdin = io.StringIO('False')

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(not value)
Ejemplo n.º 3
0
    def test_string_no_options(self):

        serialized_input = {
            "key": "env",
            "title": "Environment",
            "type": "string",
            "help": "The environment to build stack for",
            "required": True
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject the correct response to inputs prompt into stdin
        sys.stdin = io.StringIO('dev')

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == 'dev')
Ejemplo n.º 4
0
    def test_int(self):

        serialized_input = {
            "key": "scale",
            "type": "int",
            "title": "Scale",
            "help": "Horizontal scale",
            "required": True
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject the correct response to inputs prompt into stdin
        sys.stdin = io.StringIO('4')

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == 4)
Ejemplo n.º 5
0
    def test_bool_invalid(self):

        serialized_input = {
          "key": "rebuild",
          "title": "Rebuilt",
          "type": "bool",
          "help":  "Rebuild the stack?",
          "required": True
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject an invalid response followed by a valid response
        sys.stdin = io.StringIO('yes\nfalse')

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(not value)  
Ejemplo n.º 6
0
    def test_int_invalid(self):

        serialized_input = {
          "key": "scale",
          "type": "int",
          "title": "Scale",
          "help":  "Horizontal scale",
          "required": True
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject an invalid response followed by a valid response
        sys.stdin = io.StringIO("test\n13")

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == 13)
Ejemplo n.º 7
0
    def test_optional(self):

        serialized_input = {
            "key": "alias",
            "title": "Alias",
            "type": "string",
            "help": "Name of alias to assign this custom dev stack",
            "required": False,
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject a carriage return
        sys.stdin = io.StringIO("\n")

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that an empty string was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == "")
Ejemplo n.º 8
0
    def test_required(self):

        serialized_input = {
            "key": "alias",
            "title": "Alias",
            "type": "string",
            "help": "Name of alias to assign this custom dev stack",
            "required": True,
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject a response
        sys.stdin = io.StringIO("my-stack")

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that 'my-stack' was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == "my-stack")
Ejemplo n.º 9
0
    def test_string_invalid_option(self):

        serialized_input = {
          "key": "env",
          "title": "Environment",
          "type": "string",
          "help":  "The environment to build stack for",
          "required": True,
          "options": ["stage"]
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject an invalid response followed by a valid response
        sys.stdin = io.StringIO("dev\nstage")

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that dev was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == 'stage')
Ejemplo n.º 10
0
    def test_optional_w_options(self):

        serialized_input = {
            "key": "color",
            "title": "Color",
            "type": "string",
            "help": "Your hair color",
            "required": False,
            "options": ["red", "brown"]
        }

        inputs = Input(serialized_input)

        params = Params({})

        # inject a carriage return
        sys.stdin = io.StringIO("\n")

        value, user_prompted = inputs.process(params)

        # test that the user was prompted and that an empty string was returned
        self.assertTrue(user_prompted)
        self.assertTrue(value == "")