self.overridetype = overridetype
def properties(self):
- return ['overridetype', 'overridetype_id']
+ return ['overridetype', 'overridetype_id', 'overrides_count']
def not_null_constraints(self):
return ['overridetype']
################################################################################
-class Section(object):
- def __init__(self, *args, **kwargs):
- pass
+class Section(ORMObject):
+ def __init__(self, section = None):
+ self.section = section
+
+ def properties(self):
+ return ['section', 'section_id', 'overrides_count']
+
+ def not_null_constraints(self):
+ return ['section']
def __eq__(self, val):
if isinstance(val, str):
# This signals to use the normal comparison operator
return NotImplemented
- def __repr__(self):
- return '<Section %s>' % self.section
-
__all__.append('Section')
@session_wrapper
priority_id = self.tbl_override.c.priority,
priority = relation(Priority),
section_id = self.tbl_override.c.section,
- section = relation(Section),
+ section = relation(Section, \
+ backref=backref('overrides', lazy='dynamic')),
overridetype_id = self.tbl_override.c.type,
overridetype = relation(OverrideType, \
backref=backref('overrides', lazy='dynamic'))))
from db_test import DBDakTestCase
-from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type
+from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \
+ Section, get_section, get_sections
from sqlalchemy.exc import FlushError, IntegrityError
import unittest
self.assertEqual(0, debtype.overrides.count())
self.assertEqual(debtype, get_override_type('deb', self.session))
+ def test_section(self):
+ '''
+ Test Section class.
+ '''
+ section = Section(section = 'python')
+ self.session.add(section)
+ self.session.flush()
+ self.assertEqual('python', section.section)
+ self.assertEqual('python', section)
+ self.assertTrue(section != 'java')
+ self.assertEqual(section, get_section('python', self.session))
+ all_sections = get_sections(self.session)
+ self.assertEqual(section.section_id, all_sections['python'])
+ self.assertEqual(0, section.overrides.count())
+
if __name__ == '__main__':
unittest.main()