Began testing and fleshing out the NoteHandler.

This commit is contained in:
David Snopek 2013-07-22 23:48:06 +01:00
parent 0b7628f5e4
commit 28ad457773
2 changed files with 38 additions and 2 deletions

View File

@ -487,10 +487,21 @@ class NoteHandler(RestHandlerBase):
def _serialize(note): def _serialize(note):
d = { d = {
'id': note.id, 'id': note.id,
'guid': note.guid,
'model': note.model(), 'model': note.model(),
'tags': ' '.join(note.tags), 'mid': note.mid,
'mod': note.mod,
'scm': note.scm,
'tags': note.tags,
'string_tags': ' '.join(note.tags),
'fields': {},
'flags': note.flags,
'usn': note.usn,
} }
# TODO: do more stuff!
# add all the fields
for name, value in note.items():
d['fields'][name] = value
return d return d

View File

@ -406,6 +406,31 @@ class ImportExportHandlerTest(CollectionTestBase):
ret = self.execute('import_file', data) ret = self.execute('import_file', data)
self.check_import() self.check_import()
class NoteHandlerTest(CollectionTestBase):
def setUp(self):
super(NoteHandlerTest, self).setUp()
self.handler = NoteHandler()
def execute(self, name, data, note_id):
ids = ['collection_name', note_id]
func = getattr(self.handler, name)
req = RestHandlerRequest(self.mock_app, data, ids, {})
return func(self.collection, req)
def test_index(self):
self.add_default_note()
note_id = self.collection.findNotes('')[0]
ret = self.execute('index', {}, note_id)
self.assertEqual(ret['id'], note_id)
self.assertEqual(len(ret['fields']), 2)
self.assertEqual(ret['flags'], 0)
self.assertEqual(ret['model']['name'], 'Basic')
self.assertEqual(ret['tags'], ['Tag1', 'Tag2'])
self.assertEqual(ret['string_tags'], 'Tag1 Tag2')
self.assertEqual(ret['usn'], -1)
class DeckHandlerTest(CollectionTestBase): class DeckHandlerTest(CollectionTestBase):
def setUp(self): def setUp(self):
super(DeckHandlerTest, self).setUp() super(DeckHandlerTest, self).setUp()