def test_tag_update(self): """Test that hashtags are updated if text changes""" note = Note(text='foo #tag1 #tag2') self.assertEqual({'tag1', 'tag2'}, note.tags) note.text = 'updated text #tag3' self.assertEqual({'tag3'}, note.tags)
def test_str_format(self): """Test that note can be rendered and parsed from string""" notestr = str(Note('hello world', created_time=0)) date = datetime.fromtimestamp(0).strftime("%x %I:%M %p") self.assertEqual('{}: hello world'.format(date), notestr) note = Note.parse_from_str(notestr) self.assertEqual('hello world', note.text) self.assertEqual(0, note.created_time)
def setUp(self): """Setup notes in DB""" fakenote1 = Note('result1', created_time=0) fakenote2 = Note('result2', created_time=0) fakemn = Mock() fakemn.search.return_value = iter([fakenote1, fakenote2]) self.fake_config = None self.fakenote1 = fakenote1 self.fakenote2 = fakenote2 self.fakemn = fakemn
def test_convert_evernote(self): """Test that an Evernote note is converted to a Mininote note""" note = convert_to_enote(Note(text=' content ', guid=123, created_time=1), notebook_guid='guid') self.assertEqual(123, note.guid) self.assertEqual('" content "', note.title) self.assertEqual(1000, note.created) self.assertEqual('guid', note.notebookGuid)
def test_add_note(self, MockEvernoteClient): """Ensure that server call is made to add a note""" client = MockMininote(token='foo') client.add_note(Note('bar #unittest')) pargs, kwargs = client._note_store().createNote.call_args self.assertEqual({'unittest'}, pargs[0].tagNames) self.assertEqual('"bar #unittest"', pargs[0].title) self.assertEqual(encode_note_text('bar #unittest'), pargs[0].content)
def test_str_parse_error(self): """Test that exception is raised when parsing invalid note""" self.assertRaises(NoteParseError, lambda: Note.parse_from_str('something: invalid'))
def test_parse_tags(self): """Test that hashtags are parsed from a note""" self.assertEqual(set(), Note(text="starbucks").tags) self.assertEqual(set(), Note(text="http://google.com#foo has no tags").tags) self.assertEqual({"tag1", "tag2"}, Note(text="ice coffee #tag1 #tag2").tags) self.assertEqual({"dup"}, Note(text="note with #dup #dup").tags) self.assertEqual({"normalized"}, Note(text="note with #normalized #Normalized").tags) self.assertEqual({"has-dash"}, Note(text="note with #has-dash").tags) self.assertEqual({"has_uscore"}, Note(text="note with #has_uscore").tags) self.assertEqual({u"ß".encode("utf-8"), u"öo".encode("utf-8")}, Note(text=u"#ß #öo".encode('utf-8')).tags) self.assertEqual({"start", "end"}, Note(text="#start #end").tags) self.assertEqual({"tab"}, Note(text="\t#tab").tags) self.assertEqual({"sub"}, Note(text="#sub#tag?").tags) self.assertEqual({"coffee"}, Note(text="#coffee: caramel mocha").tags) self.assertEqual({"coffee"}, Note(text="#coffee- caramel mocha").tags) self.assertEqual(set(), Note(text="#: #.").tags) self.assertEqual({"-b", "w"}, Note(text="single char tags #-b #w-").tags)
def test_convert_evernote_empty(self): """Test that empty note is converted""" note = convert_to_enote(Note(text='')) self.assertEqual('""', note.title)
def test_convert_evernote_trunc(self): """Test that note size is truncated if too long for Evernote""" note = convert_to_enote(Note(text='x' * 1000)) self.assertEqual('"{}"'.format('x' * 253), note.title)
def test_adds_first(self): """Ensure that additions come before deletions in pairs list""" before = [Note('foo', created_time=0)] after = [Note('foo', created_time=1)] self.assertEqual([(None, 0), (0, None)], match_notes(before, after))
def test_diff_change_date(self): """Ensure that notes with modified dates are treated as new notes""" before = [Note('foo', created_time=0), Note('bar', created_time=1)] after = [Note('foo', created_time=0), Note('bar', created_time=2)] self.assertEqual([(0, 0), (None, 1), (1, None)], match_notes(before, after))
def make_notes(texts): return [Note(text, created_time=0) for text in texts]