]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_fingerprint.py
debianqueued: No early notifications
[dak.git] / tests / dbtest_fingerprint.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import Fingerprint, Uid
6 from daklib.dak_exceptions import DBUpdateError
7
8 from sqlalchemy.exc import IntegrityError
9 import unittest
10
11 class FingerprintTestCase(DBDakTestCase):
12     """
13     The FingerprintTestCase tests the relation between Fingerprint and Uid
14     objects.
15     1. It creates a fresh Fingerprint object.
16     2. It assigns a fresh Uid object to the Fingerprint object.
17     3. It fetches the Uid object from the database.
18     4. It checks that the original fingerprint is assigned to the freshly
19        fetched Uid object.
20
21     Furthermore it checks various constraints like not null and unique.
22
23     TODO: the not null constraints should be enforced by the constructor in
24     dbconn.py. Should we check the exact format of the fingerprint?
25     """
26
27     def test_relation(self):
28         fingerprint = Fingerprint(fingerprint = 'deadbeefdeadbeef')
29         self.session.add(fingerprint)
30         query = self.session.query(Fingerprint)
31         self.assertEqual(1, query.count())
32         self.assertEqual('deadbeefdeadbeef', query.one().fingerprint)
33         fingerprint.uid = Uid(uid = 'ftp-master@debian.org', name = 'ftpteam')
34         uid = self.session.query(Uid).one()
35         self.assertEqual('ftp-master@debian.org', uid.uid)
36         self.assertEqual('ftpteam', uid.name)
37         self.assertEqual(1, len(uid.fingerprint))
38         self.assertEqual('deadbeefdeadbeef', uid.fingerprint[0].fingerprint)
39
40     def fingerprint_no_fingerprint(self):
41         self.session.add(Fingerprint())
42         self.session.flush()
43
44     def fingerprint_duplicate_fingerprint(self):
45         self.session.add(Fingerprint(fingerprint = 'affe0815'))
46         self.session.add(Fingerprint(fingerprint = 'affe0815'))
47         self.session.flush()
48
49     def uid_no_uid(self):
50         self.session.add(Uid(name = 'foobar'))
51         self.session.flush()
52
53     def uid_duplicate_uid(self):
54         self.session.add(Uid(uid = 'duplicate'))
55         self.session.add(Uid(uid = 'duplicate'))
56         self.session.flush()
57
58     def test_exceptions(self):
59         self.assertRaises(DBUpdateError, self.fingerprint_no_fingerprint)
60         self.session.rollback()
61         self.assertRaises(IntegrityError, self.fingerprint_duplicate_fingerprint)
62         self.session.rollback()
63         self.assertRaises(DBUpdateError, self.uid_no_uid)
64         self.session.rollback()
65         self.assertRaises(IntegrityError, self.uid_duplicate_uid)
66         self.session.rollback()
67
68 if __name__ == '__main__':
69     unittest.main()