def setup_class(self): super(TestLoaderGroups, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) assert count_pkgs() == 0, count_pkgs() pkg_dicts = [ { 'name': u'pkga' }, { 'name': u'pkgb' }, { 'name': u'pkgc' }, ] CreateTestData.create_arbitrary(pkg_dicts) group_dicts = [ { 'name': u'g1', 'packages': [u'pkga'] }, { 'name': u'g2' }, { 'name': u'g3' }, ] CreateTestData.create_groups(group_dicts, USER) self.pkgs = [model.Package.by_name(pkg_dict['name']) \ for pkg_dict in pkg_dicts] self.pkg_ids = [pkg.id for pkg in self.pkgs]
def setup_class(self): super(TestLoaderGroups, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) assert count_pkgs() == 0, count_pkgs() pkg_dicts = [{'name':u'pkga'}, {'name':u'pkgb'}, {'name':u'pkgc'}, ] CreateTestData.create_arbitrary(pkg_dicts) group_dicts = [ {'name':u'g1', 'packages':[u'pkga']}, {'name':u'g2'}, {'name':u'g3'}, ] CreateTestData.create_groups(group_dicts, USER) self.pkgs = [model.Package.by_name(pkg_dict['name']) \ for pkg_dict in pkg_dicts] self.pkg_ids = [pkg.id for pkg in self.pkgs]
def setup_class(self): super(TestLoader, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient)
class TestLoader(TestLoaderBase): @classmethod def setup_class(self): super(TestLoader, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) # teardown is in the base class def test_0_simple_load(self): pkg_dict = {'name':u'pkgname', 'title':u'Boris'} assert not model.Package.by_name(pkg_dict['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']]) res_pkg_dict = self.loader.load_package(pkg_dict) assert res_pkg_dict pkg = model.Package.by_name(pkg_dict['name']) assert_equal_dicts(res_pkg_dict, pkg.as_dict(), only_assert_these_keys=('name', 'title')) assert pkg assert pkg.name == pkg_dict['name'] assert pkg.title == pkg_dict['title'] def test_1_load_several(self): num_pkgs = count_pkgs() pkg_dicts = [{'name':u'pkgname_a', 'title':u'BorisA'}, {'name':u'pkgname_b', 'title':u'BorisB'}, ] assert not model.Package.by_name(pkg_dicts[0]['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name'] for pkg_dict in pkg_dicts]) res = self.loader.load_packages(pkg_dicts) assert (res['num_loaded'], res['num_errors']) == (2, 0), \ (res['num_loaded'], res['num_errors']) assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs) for pkg_index, pkg_dict in enumerate(pkg_dicts): pkg_name = pkg_dict['name'] pkg = model.Package.by_name(pkg_name) assert pkg.id == res['pkg_ids'][pkg_index], \ '%s != %s' % (pkg.id, res['pkg_ids'][pkg_index]) def test_1_load_several_with_errors(self): num_pkgs = count_pkgs() pkg_dicts = [{'name':u'pkgnameA', # not allowed uppercase name 'title':u'BorisA'}, {'name':u'pkgnameB', 'title':u'BorisB'}, ] assert not model.Package.by_name(pkg_dicts[0]['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name'] for pkg_dict in pkg_dicts]) res = self.loader.load_packages(pkg_dicts) assert (res['num_loaded'], res['num_errors']) == (0, 2), \ (res['num_loaded'], res['num_errors']) assert count_pkgs() == num_pkgs, (count_pkgs() - num_pkgs) assert res['pkg_ids'] == [], res['pkg_ids'] def test_2_reload(self): # load the package once num_pkgs = count_pkgs() pkg_dict = {'name':u'pkgname2', 'title':u'Boris'} assert not model.Package.by_name(pkg_dict['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']]) self.loader.load_package(pkg_dict) pkg = model.Package.by_name(pkg_dict['name']) assert pkg assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs) # load the package again pkg_dict = {'name':u'pkgname2', 'title':u'Boris Becker'} self.loader.load_package(pkg_dict) pkg = model.Package.by_name(pkg_dict['name']) assert pkg assert pkg.name == pkg_dict['name'] assert pkg.title == pkg_dict['title'], pkg.title assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
class TestLoaderGroups(TestLoaderBase): @classmethod def setup_class(self): super(TestLoaderGroups, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) assert count_pkgs() == 0, count_pkgs() pkg_dicts = [{'name':u'pkga'}, {'name':u'pkgb'}, {'name':u'pkgc'}, ] CreateTestData.create_arbitrary(pkg_dicts) group_dicts = [ {'name':u'g1', 'packages':[u'pkga']}, {'name':u'g2'}, {'name':u'g3'}, ] CreateTestData.create_groups(group_dicts, USER) self.pkgs = [model.Package.by_name(pkg_dict['name']) \ for pkg_dict in pkg_dicts] self.pkg_ids = [pkg.id for pkg in self.pkgs] # teardown is in the base class def test_0_add_to_empty_group(self): pkg_name = u'pkga' group_name = u'g2' pkg = model.Package.by_name(pkg_name) group = model.Group.by_name(group_name) assert group assert not group.packages, group.packages self.loader.add_pkg_to_group(pkg.name, group.name) group = model.Group.by_name(group_name) pkg = model.Package.by_name(pkg_name) assert group.packages == [pkg], group.packages def test_1_add_to_non_empty_group(self): pkg_name = u'pkgb' group_name = u'g1' pkg = model.Package.by_name(pkg_name) group = model.Group.by_name(group_name) assert group assert len(group.packages) == 1, group.packages self.loader.add_pkg_to_group(pkg.name, group.name) group = model.Group.by_name(group_name) pkg = model.Package.by_name(pkg_name) assert pkg in group.packages, group.packages assert len(group.packages) == 2, group.packages def test_2_add_multiple_packages(self): pkg_names = [u'pkgb', u'pkgc'] group_name = u'g2' pkgs = [model.Package.by_name(pkg_name) for pkg_name in pkg_names] group = model.Group.by_name(group_name) assert group num_pkgs_at_start = len(group.packages) assert num_pkgs_at_start in (0, 1), group.packages self.loader.add_pkgs_to_group(pkg_names, group.name) group = model.Group.by_name(group_name) pkgs = [model.Package.by_name(pkg_name) for pkg_name in pkg_names] for pkg in pkgs: assert pkg in group.packages, group.packages assert len(group.packages) == num_pkgs_at_start + 2, group.packages def test_3_add_to_missing_group(self): pkg_names = [u'pkgb', u'pkgc'] try: self.loader.add_pkgs_to_group(pkg_names, 'random_name') except LoaderError, e: assert e.args[0] == 'Group named \'random_name\' does not exist', e.args else:
class TestLoader(TestLoaderBase): @classmethod def setup_class(self): super(TestLoader, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) # teardown is in the base class def test_0_simple_load(self): pkg_dict = {'name': u'pkgname', 'title': u'Boris'} assert not model.Package.by_name(pkg_dict['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']]) res_pkg_dict = self.loader.load_package(pkg_dict) assert res_pkg_dict pkg = model.Package.by_name(pkg_dict['name']) assert_equal_dicts(res_pkg_dict, pkg.as_dict(), only_assert_these_keys=('name', 'title')) assert pkg assert pkg.name == pkg_dict['name'] assert pkg.title == pkg_dict['title'] def test_1_load_several(self): num_pkgs = count_pkgs() pkg_dicts = [ { 'name': u'pkgname_a', 'title': u'BorisA' }, { 'name': u'pkgname_b', 'title': u'BorisB' }, ] assert not model.Package.by_name(pkg_dicts[0]['name']) CreateTestData.flag_for_deletion( pkg_names=[pkg_dict['name'] for pkg_dict in pkg_dicts]) res = self.loader.load_packages(pkg_dicts) assert (res['num_loaded'], res['num_errors']) == (2, 0), \ (res['num_loaded'], res['num_errors']) assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs) for pkg_index, pkg_dict in enumerate(pkg_dicts): pkg_name = pkg_dict['name'] pkg = model.Package.by_name(pkg_name) assert pkg.id == res['pkg_ids'][pkg_index], \ '%s != %s' % (pkg.id, res['pkg_ids'][pkg_index]) def test_1_load_several_with_errors(self): num_pkgs = count_pkgs() pkg_dicts = [ { 'name': u'pkgnameA', # not allowed uppercase name 'title': u'BorisA' }, { 'name': u'pkgnameB', 'title': u'BorisB' }, ] assert not model.Package.by_name(pkg_dicts[0]['name']) CreateTestData.flag_for_deletion( pkg_names=[pkg_dict['name'] for pkg_dict in pkg_dicts]) res = self.loader.load_packages(pkg_dicts) assert (res['num_loaded'], res['num_errors']) == (0, 2), \ (res['num_loaded'], res['num_errors']) assert count_pkgs() == num_pkgs, (count_pkgs() - num_pkgs) assert res['pkg_ids'] == [], res['pkg_ids'] def test_2_reload(self): # load the package once num_pkgs = count_pkgs() pkg_dict = {'name': u'pkgname2', 'title': u'Boris'} assert not model.Package.by_name(pkg_dict['name']) CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']]) self.loader.load_package(pkg_dict) pkg = model.Package.by_name(pkg_dict['name']) assert pkg assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs) # load the package again pkg_dict = {'name': u'pkgname2', 'title': u'Boris Becker'} self.loader.load_package(pkg_dict) pkg = model.Package.by_name(pkg_dict['name']) assert pkg assert pkg.name == pkg_dict['name'] assert pkg.title == pkg_dict['title'], pkg.title assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
class TestLoaderGroups(TestLoaderBase): @classmethod def setup_class(self): super(TestLoaderGroups, self).setup_class() self.loader = ReplaceByNameLoader(self.testclient) assert count_pkgs() == 0, count_pkgs() pkg_dicts = [ { 'name': u'pkga' }, { 'name': u'pkgb' }, { 'name': u'pkgc' }, ] CreateTestData.create_arbitrary(pkg_dicts) group_dicts = [ { 'name': u'g1', 'packages': [u'pkga'] }, { 'name': u'g2' }, { 'name': u'g3' }, ] CreateTestData.create_groups(group_dicts, USER) self.pkgs = [model.Package.by_name(pkg_dict['name']) \ for pkg_dict in pkg_dicts] self.pkg_ids = [pkg.id for pkg in self.pkgs] # teardown is in the base class def test_0_add_to_empty_group(self): pkg_name = u'pkga' group_name = u'g2' pkg = model.Package.by_name(pkg_name) group = model.Group.by_name(group_name) assert group assert not group.packages, group.packages self.loader.add_pkg_to_group(pkg.name, group.name) group = model.Group.by_name(group_name) pkg = model.Package.by_name(pkg_name) assert group.packages == [pkg], group.packages def test_1_add_to_non_empty_group(self): pkg_name = u'pkgb' group_name = u'g1' pkg = model.Package.by_name(pkg_name) group = model.Group.by_name(group_name) assert group assert len(group.packages) == 1, group.packages self.loader.add_pkg_to_group(pkg.name, group.name) group = model.Group.by_name(group_name) pkg = model.Package.by_name(pkg_name) assert pkg in group.packages, group.packages assert len(group.packages) == 2, group.packages def test_2_add_multiple_packages(self): pkg_names = [u'pkgb', u'pkgc'] group_name = u'g2' pkgs = [model.Package.by_name(pkg_name) for pkg_name in pkg_names] group = model.Group.by_name(group_name) assert group num_pkgs_at_start = len(group.packages) assert num_pkgs_at_start in (0, 1), group.packages self.loader.add_pkgs_to_group(pkg_names, group.name) group = model.Group.by_name(group_name) pkgs = [model.Package.by_name(pkg_name) for pkg_name in pkg_names] for pkg in pkgs: assert pkg in group.packages, group.packages assert len(group.packages) == num_pkgs_at_start + 2, group.packages def test_3_add_to_missing_group(self): pkg_names = [u'pkgb', u'pkgc'] try: self.loader.add_pkgs_to_group(pkg_names, 'random_name') except LoaderError, e: assert e.args[ 0] == 'Group named \'random_name\' does not exist', e.args else: