1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
import unittest
import ConfigParser
from mock import Mock
from nvpy.view import View
from nvpy.nvpy import NotesListModel
from nvpy.nvpy import Controller
from nvpy.nvpy import Config
import os
from nvpy import utils
import time
import shutil
class Tags(unittest.TestCase):
def setUp(self):
if os.path.isdir('/tmp/.nvpyUnitTests'):
shutil.rmtree('/tmp/.nvpyUnitTests')
def __mock_config(self):
app_dir = os.path.abspath('nvpy')
mockConfig = Config(app_dir)
mockConfig.sn_username = ''
mockConfig.sn_password = ''
mockConfig.db_path = '/tmp/.nvpyUnitTests'
mockConfig.txt_path = '/tmp/.nvpyUnitTests/notes'
mockConfig.simplenote_sync = 0
return mockConfig
def test_tag_buttons_are_created_when_displaying_a_note(self):
mockNotesListModel = NotesListModel()
mockNotesListModel.add_observer = Mock()
view = View(self.__mock_config(), mockNotesListModel)
note = {
'content': "title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['atag', 'anotherTag']
}
view.set_note_data(note)
tag_elements = view.note_existing_tags_frame.children.values()
for element in tag_elements:
self.assertEqual(element.__class__.__name__, 'Button', "Tag element was not a button")
self.assertTrue(element['text'] in ['atag x', 'anotherTag x'], "Didn't expect to find a tag with text %s" % element['text'] )
self.assertEqual(len(tag_elements), 2)
view.close()
def test_view_can_check_if_a_note_has_not_changed(self):
mockNotesListModel = NotesListModel()
mockNotesListModel.add_observer = Mock()
view = View(self.__mock_config(), mockNotesListModel)
note = {
'content': "title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['atag', 'anotherTag']
}
view.set_note_data(note)
self.assertFalse(view.is_note_different(note))
view.close()
def test_view_can_check_if_a_notes_content_has_changed(self):
mockNotesListModel = NotesListModel()
mockNotesListModel.add_observer = Mock()
view = View(self.__mock_config(), mockNotesListModel)
note = {
'content': "title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['atag', 'anotherTag']
}
view.set_note_data(note)
new_note = {
'content': "new title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['atag', 'anotherTag']
}
view.set_note_data(note)
self.assertTrue(view.is_note_different(new_note))
view.close()
def test_view_can_check_if_a_notes_tags_has_changed(self):
mockNotesListModel = NotesListModel()
mockNotesListModel.add_observer = Mock()
view = View(self.__mock_config(), mockNotesListModel)
note = {
'content': "title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['atag', 'anotherTag']
}
view.set_note_data(note)
new_note = {
'content': "title",
'modifydate': "timestamp",
'createdate': "timestamp",
'savedate': 0, # never been written to disc
'syncdate': 0, # never been synced with server
'tags': ['anotherTag']
}
view.set_note_data(note)
self.assertTrue(view.is_note_different(new_note))
view.close()
if __name__ == '__main__':
unittest.main()
|