From: Torsten Werner Date: Wed, 26 Jan 2011 21:54:11 +0000 (+0100) Subject: Convert class Component to ORMObject. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=221c511735a22974ac5ee9e1d2d5d52bf29e263e;p=dak Convert class Component to ORMObject. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 1acb20d4..e1e21d2b 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -849,9 +849,9 @@ __all__.append('ChangePendingSource') ################################################################################ -class Component(object): - def __init__(self, *args, **kwargs): - pass +class Component(ORMObject): + def __init__(self, component_name = None): + self.component_name = component_name def __eq__(self, val): if isinstance(val, str): @@ -865,8 +865,12 @@ class Component(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '' % self.component_name + def properties(self): + return ['component_name', 'component_id', 'description', 'location', \ + 'meets_dfsg'] + + def not_null_constraints(self): + return ['component_name'] __all__.append('Component') @@ -1572,9 +1576,12 @@ __all__.append('get_dbchange') ################################################################################ +# TODO: Why do we have a separate Location class? Can't it be fully integrated +# into class Component? class Location(ORMObject): - def __init__(self, path = None): + def __init__(self, path = None, component = None): self.path = path + self.component = component # the column 'type' should go away, see comment at mapper self.archive_type = 'pool' @@ -2989,7 +2996,8 @@ class DBConn(object): mapper(Component, self.tbl_component, properties = dict(component_id = self.tbl_component.c.id, - component_name = self.tbl_component.c.name)) + component_name = self.tbl_component.c.name), + extension = validator) mapper(DBConfig, self.tbl_config, properties = dict(config_id = self.tbl_config.c.id)) @@ -3081,7 +3089,8 @@ class DBConn(object): mapper(Location, self.tbl_location, properties = dict(location_id = self.tbl_location.c.id, component_id = self.tbl_location.c.component, - component = relation(Component), + component = relation(Component, \ + backref=backref('location', uselist = False)), archive_id = self.tbl_location.c.archive, archive = relation(Archive), # FIXME: the 'type' column is old cruft and diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 371b633e..12ab5960 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -6,7 +6,7 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \ get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \ check_poolfile, get_poolfile_like_name, get_source_in_suite, \ get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \ - get_suites_binary_in, add_deb_to_db + get_suites_binary_in, add_deb_to_db, Component from daklib.queue_install import package_to_suite from daklib.queue import get_newest_source, get_suite_version_by_source, \ get_source_by_package_and_suite, get_suite_version_by_package @@ -62,16 +62,29 @@ class PackageTestCase(DBDakTestCase): self.arch['all'].arch_id = 2 self.session.add_all(self.arch.values()) + def setup_components(self): + 'create some Component objects' + + if 'comp' in self.__dict__: + return + self.comp = {} + self.comp['main'] = Component(component_name = 'main') + self.comp['contrib'] = Component(component_name = 'contrib') + self.session.add_all(self.comp.values()) + def setup_locations(self): - 'create some Location objects, TODO: add component' + 'create some Location objects' if 'loc' in self.__dict__: return + self.setup_components() self.loc = {} - self.loc['main'] = Location(path = \ - '/srv/ftp-master.debian.org/ftp/pool/') - self.loc['contrib'] = Location(path = \ - '/srv/ftp-master.debian.org/ftp/pool/') + self.loc['main'] = Location( \ + path = '/srv/ftp-master.debian.org/ftp/pool/', \ + component = self.comp['main']) + self.loc['contrib'] = Location( \ + path = '/srv/ftp-master.debian.org/ftp/pool/', \ + component = self.comp['contrib']) self.session.add_all(self.loc.values()) def setup_poolfiles(self): @@ -504,5 +517,11 @@ class PackageTestCase(DBDakTestCase): result = get_suite_version_by_package('python-hello', 'amd64', self.session) self.assertEqual([('squeeze', '2.2-1')], result) + def test_components(self): + 'test class Component' + + self.assertEqual(self.loc['main'], self.comp['main'].location) + self.assertEqual(self.loc['contrib'], self.comp['contrib'].location) + if __name__ == '__main__': unittest.main()