Exemplo n.º 1
0
    def test_valid_from_dict(self):
        plug_dict = OrderedDict({"interface": "somevalue", "someprop": "somevalue"})
        plug_name = "plug-test"

        plug = Plug.from_dict(plug_dict=plug_dict, plug_name=plug_name)

        plug.validate()
Exemplo n.º 2
0
    def test_invalid_from_dict_raises_exception(self):
        plug_dict = OrderedDict({})
        plug_name = "plug-test"

        plug = Plug.from_dict(plug_dict=plug_dict, plug_name=plug_name)

        self.assertRaises(errors.PlugValidationError, plug.validate)
Exemplo n.º 3
0
    def test_from_empty_dict(self):
        plug_dict = OrderedDict({})
        plug_name = "plug-test"

        plug = Plug.from_dict(plug_dict=plug_dict, plug_name=plug_name)

        plug.validate()
Exemplo n.º 4
0
    def test_plug_name(self):
        plug_name = "plug-test"

        plug = Plug(plug_name=plug_name)
        plug_from_dict = Plug.from_dict(
            plug_dict={"interface": "somevalue"}, plug_name=plug_name
        )

        self.assertEqual(plug_name, plug.plug_name)
        self.assertEqual(plug_name, plug_from_dict.plug_name)
Exemplo n.º 5
0
    def from_dict(cls, snap_dict: Dict[str, Any]) -> "Snap":
        snap_dict = deepcopy(snap_dict)

        snap = Snap()

        if "passthrough" in snap_dict:
            snap.passthrough = snap_dict.pop("passthrough")

        for key in snap_dict:
            if key == "plugs":
                for plug_name, plug_dict in snap_dict[key].items():
                    plug = Plug.from_dict(plug_dict=plug_dict,
                                          plug_name=plug_name)
                    snap.plugs[plug_name] = plug
            elif key == "slots":
                for slot_name, slot_dict in snap_dict[key].items():
                    slot = Slot.from_dict(slot_dict=slot_dict,
                                          slot_name=slot_name)
                    snap.slots[slot_name] = slot
            elif key == "apps":
                for app_name, app_dict in snap_dict[key].items():
                    app = Application.from_dict(app_dict=app_dict,
                                                app_name=app_name)
                    snap.apps[app_name] = app
            elif key == "hooks":
                for hook_name, hook_dict in snap_dict[key].items():
                    hook = Hook.from_dict(hook_dict=hook_dict,
                                          hook_name=hook_name)
                    snap.hooks[hook_name] = hook
            elif key in _MANDATORY_PACKAGE_KEYS:
                snap.__dict__[key] = snap_dict[key]
            elif key in _OPTIONAL_PACKAGE_KEYS:
                snap.__dict__[key] = snap_dict[key]
            else:
                logger.debug(
                    "ignoring or passing through unknown key: {}".format(key))
                continue

        if "adopt-info" in snap_dict:
            snap.adopt_info = snap_dict["adopt-info"]

        return snap
Exemplo n.º 6
0
    def test_invalid_target_from_dict_raise_exception(self):
        plug_dict = OrderedDict({"interface": "content", "target": ""})

        plug = Plug.from_dict(plug_dict=plug_dict, plug_name="plug-test")

        self.assertRaises(errors.PlugValidationError, plug.validate)