Exemplo n.º 1
0
 def test_parse_title(self):
     title = 'Adventure Time GIF - Find Share on GIPHY'
     partial_html = """<!DOCTYPE html><html itemscope itemtype="http://schema.org/WebPage" >
         <head >
         <title>{}</title>
         <meta charset="utf-8" />
         <meta name="idk" content="test" />""".format(title)
     self.assertEqual(parse_title(html=partial_html), title)
Exemplo n.º 2
0
 def on_current_note_buffer_changed(self, tb):
     """ Called when text in the main buffer is changed. This
         means it's called when switching notes too.
     """
     if not self.lock:
         text = self.textbuffer.get_text(self.textbuffer.get_start_iter(),
                                         self.textbuffer.get_end_iter(),
                                         False)
         uid = self.liststore[self.cursor][1]
         self.db.update_note(text, uid)
         self.liststore[self.cursor][0] = parse_title(text)
Exemplo n.º 3
0
 def update_note(self, text, rowid):
     """Update note based on rowid. Parses title from text.
     
     Parameters
     ----------
     text: str
           The text of the note, to be updated in db
     rowid: int
          Unique id of the note. Must be non-empty. 
     """
     if rowid == '':
         raise WriteError
     # BUG? Sqlite does return nothing if we search by 'id' (or any INTEGER
     # PRIMARY KEY) rather than 'rowid'. This happens only with a virtual
     # table
     self.db.execute("UPDATE notes SET body=? WHERE rowid=?", [text, rowid]) 
     self.db.execute("UPDATE notes SET title=? WHERE rowid=?", [parse_title(text), rowid])
Exemplo n.º 4
0
 def add_note(self, text):
     """Adds a note to db. Returns the note title and its rowid (an int).
     
     Parameters
     ----------
     text = str
             Text of the note to be created. 
     """
     title = parse_title(text)
     # From Sqlite documentation:
     # >If you declare a column of a table to be INTEGER PRIMARY KEY, 
     #  then whenever you insert a NULL into that column of the table, the
     #  NULL is automatically converted into an integer which is one greater 
     #  than the largest value of that column over all other rows in the table,
     #  or 1 if the table is empty. (If the largest possible integer key, 
     #  9223372036854775807, then an unused key value is chosen at random.)
     self.db.execute("INSERT INTO notes VALUES (?, ?, NULL)", [title, text])
     # last_insert_rowid() is actually a C/C++ api call, so it needs the
     # parentesis
     cur = self.db.execute("SELECT last_insert_rowid();")
     rowid = cur.fetchone()[0]
     return title, rowid
Exemplo n.º 5
0
def test_add_notes(db, notes):
    for note in notes:
        title, _ = db.add_note(note)
        assert title == parse_title(note)