1
# Copyright 2009-2010 Canonical Ltd.
3
# This file is part of desktopcouch-notes.
5
# desktopcouch is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3
7
# as published by the Free Software Foundation.
9
# desktopcouch is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
17
# Authors: Nicola Larosa <nicola.larosa@canonical.com>
18
# Rodrigo Moya <rodrigo.moya@canonical.com>
20
"""Tests for the NoteDocument class"""
23
from time import (strftime, gmtime)
24
from desktopcouch.notes import record as note_mod
26
class TestNoteRecord(testtools.TestCase):
27
"""Test the Note Record object."""
29
def test_note_record(self):
30
"""Test that we get the correct record type."""
31
note = note_mod.Note()
32
self.assertEqual(note_mod.NOTE_RECORD_TYPE, note.record_type)
33
for field_name in note_mod.FIELDS:
34
field_type = note_mod.FIELDS[field_name]
35
if field_type == 'string':
36
setattr(note, field_name, 'value')
37
self.assertEqual('value', note._data[field_name])
38
self.assertEqual(getattr(note, field_name), 'value')
39
elif field_type == 'date':
40
current_time = strftime("%Y-%m-%dT%H:%M:%S", gmtime())
41
setattr(note, field_name, current_time)
42
self.assertEqual(current_time, note._data[field_name])
43
self.assertEqual(getattr(note, field_name), current_time)
45
self.fail('Unknown field type: %s' % field_type)
48
all_keys = set(note_mod.FIELDS)
49
all_keys.add('record_type')
50
self.assertEqual(set(note.keys()), all_keys)