From 28ad4577738a98531ca7356e38962e73fad21183 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Mon, 22 Jul 2013 23:48:06 +0100 Subject: [PATCH] Began testing and fleshing out the NoteHandler. --- AnkiServer/apps/rest_app.py | 15 +++++++++++++-- tests/test_rest_app.py | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/AnkiServer/apps/rest_app.py b/AnkiServer/apps/rest_app.py index ab0ad3e..3fe7131 100644 --- a/AnkiServer/apps/rest_app.py +++ b/AnkiServer/apps/rest_app.py @@ -487,10 +487,21 @@ class NoteHandler(RestHandlerBase): def _serialize(note): d = { 'id': note.id, + 'guid': note.guid, '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 diff --git a/tests/test_rest_app.py b/tests/test_rest_app.py index 849fdd6..39405ca 100644 --- a/tests/test_rest_app.py +++ b/tests/test_rest_app.py @@ -406,6 +406,31 @@ class ImportExportHandlerTest(CollectionTestBase): ret = self.execute('import_file', data) 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): def setUp(self): super(DeckHandlerTest, self).setUp()