Example #1
0
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)
Example #2
0
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)