################################################################################
class BinContents(ORMObject):
- def properties(silf):
+ def __init__(self, file = None, binary = None):
+ self.file = file
+ self.binary = binary
+
+ def properties(self):
return ['file', 'binary']
__all__.append('BinContents')
return NotImplemented
def properties(self):
- return ['component_name', 'component_id', 'description', 'location', \
- 'meets_dfsg']
+ return ['component_name', 'component_id', 'description', \
+ 'location_count', 'meets_dfsg', 'overrides_count']
def not_null_constraints(self):
return ['component_name']
################################################################################
-class OverrideType(object):
- def __init__(self, *args, **kwargs):
- pass
+class OverrideType(ORMObject):
+ def __init__(self, overridetype = None):
+ self.overridetype = overridetype
- def __repr__(self):
- return '<OverrideType %s>' % self.overridetype
+ def properties(self):
+ return ['overridetype', 'overridetype_id', 'overrides_count']
+
+ def not_null_constraints(self):
+ return ['overridetype']
__all__.append('OverrideType')
################################################################################
-class Priority(object):
- def __init__(self, *args, **kwargs):
- pass
+class Priority(ORMObject):
+ def __init__(self, priority = None, level = None):
+ self.priority = priority
+ self.level = level
+
+ def properties(self):
+ return ['priority', 'priority_id', 'level', 'overrides_count']
+
+ def not_null_constraints(self):
+ return ['priority', 'level']
def __eq__(self, val):
if isinstance(val, str):
# This signals to use the normal comparison operator
return NotImplemented
- def __repr__(self):
- return '<Priority %s (%s)>' % (self.priority, self.priority_id)
-
__all__.append('Priority')
@session_wrapper
################################################################################
-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
self.version = version
def properties(self):
- return ['suite_name', 'version', 'sources_count', 'binaries_count']
+ return ['suite_name', 'version', 'sources_count', 'binaries_count', \
+ 'overrides_count']
def not_null_constraints(self):
return ['suite_name', 'version']
'binary_acl',
'binary_acl_map',
'build_queue',
+ 'build_queue_files',
'changelogs_text',
+ 'changes',
'component',
'config',
'changes_pending_binaries',
'suite',
'uid',
'upload_blocks',
- # The following tables have primary keys but sqlalchemy
- # version 0.5 fails to reflect them correctly with database
- # versions before upgrade #41.
- 'changes',
- 'build_queue_files',
)
tables_no_primary = (
'suite_src_formats',
'suite_build_queue_copy',
'udeb_contents',
- # see the comment above
- #'changes',
- #'build_queue_files',
)
views = (
mapper(Location, self.tbl_location,
properties = dict(location_id = self.tbl_location.c.id,
component_id = self.tbl_location.c.component,
- component = relation(Component, \
- backref=backref('location', uselist = False)),
+ component = relation(Component, backref='location'),
archive_id = self.tbl_location.c.archive,
archive = relation(Archive),
# FIXME: the 'type' column is old cruft and
mapper(Override, self.tbl_override,
properties = dict(suite_id = self.tbl_override.c.suite,
- suite = relation(Suite),
+ suite = relation(Suite, \
+ backref=backref('overrides', lazy='dynamic')),
package = self.tbl_override.c.package,
component_id = self.tbl_override.c.component,
- component = relation(Component),
+ component = relation(Component, \
+ backref=backref('overrides', lazy='dynamic')),
priority_id = self.tbl_override.c.priority,
- priority = relation(Priority),
+ priority = relation(Priority, \
+ backref=backref('overrides', lazy='dynamic')),
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)))
+ overridetype = relation(OverrideType, \
+ backref=backref('overrides', lazy='dynamic'))))
mapper(OverrideType, self.tbl_override_type,
properties = dict(overridetype = self.tbl_override_type.c.type,
--- /dev/null
+#!/usr/bin/env python
+
+from db_test import DBDakTestCase
+
+from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \
+ Section, get_section, get_sections, Priority, get_priority, get_priorities
+
+from sqlalchemy.exc import FlushError, IntegrityError
+import unittest
+
+class ContentsTestCase(DBDakTestCase):
+ """
+ This TestCase checks the behaviour of contents generation.
+ """
+
+ def test_duplicates1(self):
+ '''
+ Test the BinContents class for duplication problems.
+ '''
+ self.setup_binaries()
+ contents1 = BinContents(file = 'usr/bin/hello', \
+ binary = self.binary['hello_2.2-1_i386'])
+ self.session.add(contents1)
+ self.session.flush()
+ # test duplicates
+ contents2 = BinContents(file = 'usr/bin/hello', \
+ binary = self.binary['hello_2.2-1_i386'])
+ self.session.add(contents2)
+ self.assertRaises(FlushError, self.session.flush)
+
+ def test_duplicates2(self):
+ '''
+ Test the BinContents class for more duplication problems.
+ '''
+ self.setup_binaries()
+ contents1 = BinContents(file = 'usr/bin/hello', \
+ binary = self.binary['hello_2.2-1_i386'])
+ self.session.add(contents1)
+ contents2 = BinContents(file = 'usr/bin/gruezi', \
+ binary = self.binary['hello_2.2-1_i386'])
+ self.session.add(contents2)
+ self.session.flush()
+ # test duplicates
+ contents2.file = 'usr/bin/hello'
+ self.assertRaises(IntegrityError, self.session.flush)
+
+ def test_duplicates3(self):
+ '''
+ Test the BinContents class even more.
+ '''
+ self.setup_binaries()
+ contents1 = BinContents(file = 'usr/bin/hello', \
+ binary = self.binary['hello_2.2-1_i386'])
+ self.session.add(contents1)
+ # same file in different binary packages should be okay
+ contents2 = BinContents(file = 'usr/bin/hello', \
+ binary = self.binary['gnome-hello_2.2-1_i386'])
+ self.session.add(contents2)
+ self.session.flush()
+
+ def test_overridetype(self):
+ '''
+ Test the OverrideType class.
+ '''
+ debtype = OverrideType(overridetype = 'deb')
+ self.session.add(debtype)
+ self.session.flush()
+ self.assertEqual('deb', debtype.overridetype)
+ 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())
+
+ def test_priority(self):
+ '''
+ Test Priority class.
+ '''
+ priority = Priority(priority = 'standard', level = 7)
+ self.session.add(priority)
+ self.session.flush()
+ self.assertEqual('standard', priority.priority)
+ self.assertEqual(7, priority.level)
+ self.assertEqual('standard', priority)
+ self.assertTrue(priority != 'extra')
+ self.assertEqual(priority, get_priority('standard', self.session))
+ all_priorities = get_priorities(self.session)
+ self.assertEqual(priority.priority_id, all_priorities['standard'])
+ self.assertEqual(0, priority.overrides.count())
+
+if __name__ == '__main__':
+ unittest.main()