def test_get_all(self, tag_manager, stored_tag_batch_factory): """Make sure we get all stored categories.""" tags = stored_tag_batch_factory(5) result = tag_manager.GetAll() result = [helpers.dbus_to_hamster_tag(each) for each in result] assert len(result) == 5 for tag in tags: assert tag in result
def get_all(self): """ Return a list of all tags. Returns: list: List of ``Tags``, ordered by ``lower(name)``. """ result = self._interface.GetAll() return [helpers.dbus_to_hamster_tag(tag) for tag in result]
def test_save_new(self, tag_manager, tag, tag_name_parametrized): """Make sure an instance is created and returned.""" tag.name = tag_name_parametrized dbus_tag = helpers.hamster_to_dbus_tag(tag) result = tag_manager.Save(dbus_tag) result = helpers.dbus_to_hamster_tag(result) assert result.pk assert tag.as_tuple(include_pk=False) == result.as_tuple( include_pk=False)
def get_by_name(self, name): """ Look up a tag by its name. Args: name (text_type): Unique name of the ``Tag`` to we want to fetch. Returns: hamster_lib.Tag: ``Tag`` with given name. """ result = self._interface.GetByName(name) return helpers.dbus_to_hamster_tag(result)
def get(self, pk): """ Get an ``Tag`` by its primary key. Args: pk (int): Primary key of the ``Tag`` to be fetched. Returns: hamster_lib.Tag: ``Tag`` with given primary key. """ result = self._interface.Get(int(pk)) return helpers.dbus_to_hamster_tag(result)
def save(self, tag): """ Save a tag. For details see the corresponding method in ``hamster_lib.storage``. """ if not isinstance(tag, lib_objects.Tag): message = _( "You need to pass a ``hamster_lib.objects.Tag`` instance") raise TypeError(message) dbus_tag = helpers.hamster_to_dbus_tag(tag) result = self._interface.Save(dbus_tag) return helpers.dbus_to_hamster_tag(result)
def Save(self, tag_tuple): # NOQA """ Save tag. Args: tag_tuple: hamster_lib.Tag tuple. Returns: helpers.DBusTag: For details please see ``helpers.haster_to_dbus_tag``. """ tag = helpers.dbus_to_hamster_tag(tag_tuple) tag = self._controller.store.tags.save(tag) self._main_object.TagChanged() return helpers.hamster_to_dbus_tag(tag)
def get_or_create(self, tag): """ Check if we already got a tag with that name, if not create one. For details see the corresponding method in ``hamster_lib.storage``. Args: tag (hamster_lib.Tag): The tag we want. Returns: hamster_lib.Tag: The retrieved or created tag. Raises: TypeError: If ``tag`` is not a ``lib_objects.Tag`` instance. """ if not isinstance(tag, lib_objects.Tag): message = _( "You need to pass a ``hamster_lib.objects.Tag`` instance") raise TypeError(message) dbus_tag = helpers.hamster_to_dbus_tag(tag) result = self._interface.GetOrCreate(dbus_tag) return helpers.dbus_to_hamster_tag(result)
def test_dbus_to_hamster_tag(tag_tuple, expectation): """Make sure that de-serialization works as intended.""" result = helpers.dbus_to_hamster_tag(tag_tuple) assert result == expectation if expectation: assert isinstance(result, Tag)
def factory(**kwargs): tag = tag_factory.build(**kwargs) result = tag_manager.Save(helpers.hamster_to_dbus_tag(tag)) return helpers.dbus_to_hamster_tag(result)
def test_get_by_name(self, tag_manager, stored_tag): """Make sure a matching tag is returned.""" result = tag_manager.GetByName(stored_tag.name) result = helpers.dbus_to_hamster_tag(result) assert result.pk == stored_tag.pk assert result.name == stored_tag.name