Ejemplo n.º 1
0
    def test_database_can_add_tags(self):
        notes_db = NotesDB(self.__mock_config())
        notes_db.notes = {'9': {'modifydate': 1424239444.609394, 'tags': [], 'createdate': 1424239444.609394, 'syncdate': 0, 'content': 'note', 'savedate': 0}}

        notes_db.add_note_tags('9', 'aTag,anotherTag')

        self.assertEqual(notes_db.notes['9']['tags'], ['aTag', 'anotherTag'])
Ejemplo n.º 2
0
 def test_search_by_valid_regexp(self):
     db = NotesDB(self.__mock_config())
     db.notes = copy.deepcopy(notes)
     filtered_notes, match_regexp, active_notes = db.filter_notes_regexp(
         'foo| [12]')
     self.assertEqual(len(filtered_notes), 3)
     self.assertEqual(match_regexp, 'foo| [12]')
     self.assertEqual(active_notes, 3)
Ejemplo n.º 3
0
 def test_search_by_tag(self):
     db = NotesDB(self.__mock_config())
     db.notes = copy.deepcopy(notes)
     filtered_notes, match_regexp, active_notes = db.filter_notes_gstyle(
         'tag:foo')
     self.assertEqual(len(filtered_notes), 1)
     self.assertEqual(filtered_notes[0].note['content'],
                      notes['3']['content'])
     self.assertEqual(match_regexp, '')  # Should ignore for tag pattern
     self.assertEqual(active_notes, 3)
Ejemplo n.º 4
0
 def test_search_by_multi_word(self):
     db = NotesDB(self.__mock_config())
     db.notes = copy.deepcopy(notes)
     filtered_notes, match_regexp, active_notes = db.filter_notes_gstyle(
         '"note 1" active')
     self.assertEqual(len(filtered_notes), 1)
     self.assertEqual(filtered_notes[0].note['content'],
                      notes['1']['content'])
     self.assertEqual(match_regexp,
                      r'note\ 1|active')  # Should ignore for tag pattern
     self.assertEqual(active_notes, 3)
Ejemplo n.º 5
0
 def test_search_by_none_or_empty(self):
     db = NotesDB(self.__mock_config())
     db.notes = copy.deepcopy(notes)
     filtered_notes, match_regexp, active_notes = db.filter_notes_gstyle()
     self.assertEqual(len(filtered_notes), 3)
     self.assertEqual(match_regexp, '')
     self.assertEqual(active_notes, 3)
     filtered_notes, match_regexp, active_notes = db.filter_notes_gstyle('')
     self.assertEqual(len(filtered_notes), 3)
     self.assertEqual(match_regexp, '')
     self.assertEqual(active_notes, 3)
Ejemplo n.º 6
0
    def test_database_can_add_tags(self):
        notes_db = NotesDB(self.__mock_config())
        notes_db.notes = {
            '9': {
                'modifydate': 1424239444.609394,
                'tags': [],
                'createdate': 1424239444.609394,
                'syncdate': 0,
                'content': 'note',
                'savedate': 0
            }
        }

        notes_db.add_note_tags('9', 'aTag,anotherTag')

        self.assertEqual(notes_db.notes['9']['tags'], ['aTag', 'anotherTag'])
Ejemplo n.º 7
0
 def _wait_worker(self, db: NotesDB):
     timeout = 1
     loop_interval = 0.1
     max_loop_count = math.ceil(timeout / loop_interval)
     for _ in range(max_loop_count):
         if not db.is_worker_busy():
             return
         time.sleep(0.1)
     raise TimeoutError('NotesDB workers still busy')
Ejemplo n.º 8
0
 def test_database_can_load_from_text_files(self):
     self.__write_json('1', note1)
     self.__write_json('2', note2)
     self.__write_text('note', note1['content'])
     self.__write_text('another_note', note2['content'])
     db = NotesDB(self.__mock_config(notes_as_txt=True))
     self.assertSetEqual(set(db.notes.keys()), {'1', '2'})
     self.assertEqual(db.notes['1']['content'], note1['content'])
     self.assertEqual(db.notes['2']['content'], note2['content'])
Ejemplo n.º 9
0
 def _db(self, notes_as_txt=False, simplenote_sync=False):
     return NotesDB(self._mock_config(notes_as_txt, simplenote_sync))
Ejemplo n.º 10
0
 def test_database_can_load_json_files(self):
     self.__write_json('1', note1)
     self.__write_json('2', note2)
     db = NotesDB(self.__mock_config())
     self.assertSetEqual(set(db.notes.keys()), {'1', '2'})
Ejemplo n.º 11
0
 def test_database_can_load_from_empty_dir(self):
     db = NotesDB(self.__mock_config())
     self.assertDictEqual(db.notes, {})