Beispiel #1
0
def _parse_properties(properties):
    """
    :param properties: JSON items in the form key=value
    :type properties: [str]
    :returns: resource JSON
    :rtype: dict
    """

    if len(properties) == 0:
        if sys.stdin.isatty():
            # We don't support TTY right now. In the future we will start an
            # editor
            raise DCOSException(
                "We currently don't support reading from the TTY. Please "
                "specify an application JSON.\n"
                "E.g. dcos marathon app update your-app-id < app_update.json")
        else:
            return util.load_jsons(sys.stdin.read())

    resource_json = {}
    for prop in properties:
        key, value = jsonitem.parse_json_item(prop, None)

        key = jsonitem.clean_value(key)
        if key in resource_json:
            raise DCOSException(
                'Key {!r} was specified more than once'.format(key))

        resource_json[key] = value
    return resource_json
Beispiel #2
0
    def get_resource_from_properties(properties):
        """
        :param properties: JSON items in the form key=value
        :type properties: [str]
        :returns: resource JSON
        :rtype: dict
        """

        if len(properties) == 0:
            example =\
                "E.g. dcos marathon app update your-app-id < app_update.json"
            ResourceReader._assert_no_tty(example)

            return util.load_jsons(sys.stdin.read())

        resource_json = {}
        for prop in properties:
            key, value = jsonitem.parse_json_item(prop, None)

            key = jsonitem.clean_value(key)
            if key in resource_json:
                raise DCOSException(
                    'Key {!r} was specified more than once'.format(key))

            resource_json[key] = value
        return resource_json
Beispiel #3
0
    def get_resource_from_properties(properties):
        """
        :param properties: JSON items in the form key=value
        :type properties: [str]
        :returns: resource JSON
        :rtype: dict
        """

        if len(properties) == 0:
            example =\
                "E.g. dcos marathon app update your-app-id < app_update.json"
            ResourceReader._assert_no_tty(example)

            return util.load_jsons(sys.stdin.read())

        resource_json = {}
        for prop in properties:
            key, value = jsonitem.parse_json_item(prop, None)

            key = jsonitem.clean_value(key)
            if key in resource_json:
                raise DCOSException(
                    'Key {!r} was specified more than once'.format(key))

            resource_json[key] = value
        return resource_json
Beispiel #4
0
def test_parse_bad_json_item(schema, bad_parse):
    with pytest.raises(DCOSException):
        jsonitem.parse_json_item(bad_parse, schema)
Beispiel #5
0
def test_parse_json_item(schema, parse_tuple):
    arg, result = parse_tuple
    assert jsonitem.parse_json_item(arg, schema) == result
Beispiel #6
0
def test_parse_bad_json_item(schema, bad_parse):
    with pytest.raises(DCOSException):
        jsonitem.parse_json_item(bad_parse, schema)
Beispiel #7
0
def test_parse_json_item(schema, parse_tuple):
    arg, result = parse_tuple
    assert jsonitem.parse_json_item(arg, schema) == result
Beispiel #8
0
def test_parse_json_string_item_without_schema():
    assert jsonitem.parse_json_item("string=val", None) == ('"string"', "val")