Beispiel #1
0
 def setUp(self):
     self.db = connect_db(':memory:')
     init_db(self.db)
     self.s = EntryService(self.db, TimestampService())
Beispiel #2
0
class EntryServiceTests(unittest.TestCase):
            
    def setUp(self):
        self.db = connect_db(':memory:')
        init_db(self.db)
        self.s = EntryService(self.db, TimestampService())
    
    def tearDown(self):
        self.db.close()
        
    def test_add_entry(self):
        #when
        self.s.add_entry('teohm', 'content')
        
        #then
        list = self.s.list_entries('teohm')
        self.assertEqual(len(list), 1)
        entry = list[0]
        self.assertEqual(entry['content'], 'content')
        
    def test_add_entry_returned_object(self):
        #when
        entry = self.s.add_entry('teohm', 'content', '2010-01-01T00:00:00Z')
        entry2 = self.s.add_entry('teohm', 'content')
        
        #then
        assert entry['content'] == 'content'
        assert entry['timestamp'] == '2010-01-01T00:00:00Z'
        assert entry2['content'] == 'content'
        assert entry2['timestamp'] is not None
    
    def test_list_no_entry(self):
        #when
        list = self.s.list_entries('teohm')
        
        #then
        self.assertEqual(len(list), 0)
    
    def test_list_entries(self):
        #when
        self.s.add_entry('teohm', 'content', '2010-01-01T00:00:00Z')
        self.s.add_entry('teohm', 'content', '2010-01-01T00:00:01Z')
        self.s.add_entry('teohm', 'content', '2010-01-01T00:00:02Z')
        self.s.add_entry('foo', 'content', '2010-01-01T00:00:03Z')
        
        #then
        list = self.s.list_entries('teohm')
        self.assertEqual(len(list), 3)
        self.assertTrue(list[0]['timestamp'] > list[1]['timestamp'])
        self.assertTrue(list[1]['timestamp'] > list[2]['timestamp'])