~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to portable/test/databasesanitytest.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Test database sanity checking.  Right now this is pretty short
2
 
because we don't do that much sanity checking.
3
 
"""
4
 
 
5
 
import os
6
 
import tempfile
7
 
import unittest
8
 
 
9
 
from miro import iconcache
10
 
from miro import item
11
 
from miro import feed
12
 
from miro import databasesanity
13
 
from miro import database
14
 
from miro import util
15
 
from miro.plat.utils import FilenameType
16
 
 
17
 
from miro.test.framework import MiroTestCase
18
 
 
19
 
class SanityCheckingTest(MiroTestCase):
20
 
    def setUp(self):
21
 
        MiroTestCase.setUp(self)
22
 
        self.save_path = tempfile.mktemp()
23
 
 
24
 
    def tearDown(self):
25
 
        try:
26
 
            os.unlink(self.save_path)
27
 
        except OSError:
28
 
            pass
29
 
        MiroTestCase.tearDown(self)
30
 
 
31
 
    def check_object_list_fails_test(self, object_list):
32
 
        self.assertRaises(databasesanity.DatabaseInsaneError,
33
 
                          databasesanity.check_sanity, object_list, False)
34
 
 
35
 
    def check_fix_if_possible(self, start_list, fixed_list):
36
 
        self.error_signal_okay = True
37
 
        rv = databasesanity.check_sanity(start_list)
38
 
        self.assertEquals(start_list, fixed_list)
39
 
        self.assertEquals(rv, False)
40
 
        self.assertEquals(self.saw_error, True)
41
 
 
42
 
    def check_object_list_passes_test(self, object_list):
43
 
        databasesanity.check_sanity(object_list)
44
 
 
45
 
    def test_phantom_feed_checking(self):
46
 
        f = feed.Feed(u"http://feed.uk")
47
 
        i = item.Item(item.FeedParserValues({}), feed_id=f.id)
48
 
        i2 = item.FileItem(FilenameType('/foo/bar.txt'), feed_id=f.id)
49
 
        self.check_object_list_fails_test([i])
50
 
        self.check_fix_if_possible([i, i2], [])
51
 
        self.check_object_list_passes_test([i, f])
52
 
        self.check_object_list_passes_test([])
53
 
 
54
 
    def test_manual_feed_checking(self):
55
 
        f = feed.Feed(u"dtv:manualFeed")
56
 
        f2 = feed.Feed(u"dtv:manualFeed")
57
 
        f3 = feed.Feed(u"dtv:manualFeed")
58
 
        self.check_object_list_passes_test([f])
59
 
        self.check_object_list_fails_test([f, f2])
60
 
        self.error_signal_okay = True
61
 
        test_list = [f, f2, f3]
62
 
        databasesanity.check_sanity(test_list)
63
 
        self.assertEquals(len(test_list), 1)
64
 
        self.assertEquals(self.saw_error, True)