]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_ormobject.py
Merge remote branch 'mhy/psimport' into merge
[dak.git] / tests / dbtest_ormobject.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import Architecture, Suite
6
7 try:
8     # python >= 2.6
9     import json
10 except:
11     # python <= 2.5
12     import simplejson as json
13
14 import re
15 import unittest
16
17 class ORMObjectTestCase(DBDakTestCase):
18     """
19     The ORMObjectTestCase tests the behaviour of the ORMObject.
20     """
21
22     def test_strings(self):
23         'tests json(), __repr__(), and __str__()'
24         architecture = Architecture(arch_string = 'i386')
25         # test json()
26         data = json.loads(architecture.json())
27         self.assertEqual('i386', data['arch_string'])
28         # test repr()
29         self.assertEqual('<Architecture i386>', repr(architecture))
30         # test str()
31         self.assertTrue(re.match('<Architecture {.*}>', str(architecture)))
32         self.assertTrue(re.search('"arch_string": "i386"', str(architecture)))
33         sid = Suite(suite_name = 'sid')
34         squeeze = Suite(suite_name = 'squeeze')
35         architecture.suites = [sid, squeeze]
36         self.assertTrue(re.search('"suites_count": 2', str(architecture)))
37
38 if __name__ == '__main__':
39     unittest.main()