def internal_configurations():
    query_params = request.args
    if request.method == "GET":
        internal_configs = InternalConfigurations()
        if query_params.get("feature"):
            return jsonify(internal_configs.find_by("feature", query_params.get("feature"))), 200
        else:
            return jsonify(internal_configs.all), 200

    elif request.method == "POST":
        internal_configs = InternalConfigurations(params=request.get_json())

        if internal_configs.save:
            return jsonify({"message": "Internal Configuration created."}), 200
        else:
            return jsonify({"message": "Internal Configuration not created."}), 400

    elif request.method == "PUT":
        if not query_params.get("feature"):
            return jsonify({"missing query `feature`."}), 400

        internal_configs = InternalConfigurations(
            feature=query_params.get("feature"))

        if internal_configs.exists:
            try:
                if internal_configs.update(request.get_json()):
                    return jsonify({"message": "Succssefuly upated."}), 200
                else:
                    return jsonify({"message": "Something went wrong while upating."}), 200
            except Exception as e:
                raise ApiException(e.message, 500)

        else:
            return jsonify({"message": "`{}`feature not found.".format(query_params.get("feature"))}), 404
 def test_update_internal_config(self):
     updates = {"config": {"image": "some_image_address", "display": False}}
     internal_configs = InternalConfigurations(feature="test_feature")
     assert internal_configs.update(updates)
 def test_save_internal_config(self, internal_configuration_new):
     internal_configs = InternalConfigurations(
         params=internal_configuration_new.data)
     assert internal_configs.save
    def test_get_internal_config_by_feature_name_that_dosent_exist(self):

        internal_config = InternalConfigurations().find_by(
            "feature", "random1")
        assert len(internal_config) == 0
    def test_get_internal_config_by_feature_name(self):

        internal_config = InternalConfigurations().find_by(
            "feature", "test_feature")
        assert len(internal_config) == 1
    def test_get_internal_config(self):

        internal_config = InternalConfigurations().all
        assert len(internal_config) > 0
    def test_invalid_update(self):
        updates = {"config": {"image": "some_image_address", "display": False}}

        internal_configs = InternalConfigurations(feature="random23")
        assert not internal_configs.update(updates)
    def test_invalid_input_updates(self):
        updates = ["hello"]

        internal_configs = InternalConfigurations()
        assert not internal_configs.update(updates)
 def test_update_not_missing_feature(self):
     updates = {"config": {"image": "some_image_address", "display": False}}
     internal_configs = InternalConfigurations()
     assert not internal_configs.update(updates)