def test_tag_order(self):
     tag = Tag("a")
     self.database().add_tag(tag)
     tag = Tag("1. a")
     self.database().add_tag(tag)
     assert [tag.name for tag in self.database().tags()
             ] == ["1. a", "a", "__UNTAGGED__"]
Beispiel #2
0
 def tag_from_log_entry(self, log_entry):
     # When deleting, the log entry only contains the tag's id, so we pull
     # the object from the database. This is a bit slower than just filling
     # in harmless missing keys, but it is more robust against future
     # side effects of tag deletion.
     if log_entry["type"] == EventTypes.DELETED_TAG:
         # Work around legacy logs which contain duplicate deletion events.
         if self.has_tag_with_id(log_entry["o_id"]):
             return self.tag(log_entry["o_id"], is_id_internal=False)
         else:
             # Leftover from old bug, should not reoccur.
             self.main_widget().show_information(\
         _("Deleting same tag twice during sync. Inform the developpers."))
             log_entry["name"] = "irrelevant"
             return Tag(log_entry["name"], log_entry["o_id"])
     # If we are creating a tag that will be deleted at a later stage
     # during this sync, we are missing some (irrelevant) information
     # needed to properly create a tag object.
     if "name" not in log_entry:
         log_entry["name"] = "irrelevant"
     # Create tag object.
     tag = Tag(log_entry["name"], log_entry["o_id"])
     if "extra" in log_entry:
         tag.extra_data = eval(log_entry["extra"])
     # Make sure to create _id fields as well, otherwise database
     # operations or their side effects could fail.
     if log_entry["type"] != EventTypes.ADDED_TAG:
         tag._id = self.con.execute("select _id from tags where id=?",
                                    (tag.id, )).fetchone()[0]
     return tag
 def tag(self, _id):
     query = QtSql.QSqlQuery(\
         "select name from tags where _id=%d" % (_id, ))
     query.first()
     tag = Tag(query.value(0), "dummy_id")
     tag._id = _id
     return tag
 def test_tags(self):
     tag = Tag("test")
     self.database().add_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == "test"
     tag.name = "test2"
     self.database().update_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == "test2"