class TestLoaderNoSearch(TestLoaderBase):
    '''Cope as best as possible if search indexing is flakey.'''
    @classmethod
    def setup_class(self):
        '''NB, no search indexing started'''
        if not is_search_supported():
            raise SkipTest("Search not supported")
        super(TestLoaderNoSearch, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris',
                    'extras':{u'ref':'boris'}}
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris 2',
                    'extras':{u'ref':'boris'}}
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
Exemple #2
0
class TestLoaderNoSearch(TestLoaderBase):
    '''Cope as best as possible if search indexing is flakey.'''
    @classmethod
    def setup_class(self):
        '''NB, no search indexing started'''
        if not is_search_supported():
            raise SkipTest("Search not supported")
        super(TestLoaderNoSearch, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris',
            'extras': {
                u'ref': 'boris'
            }
        }
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris 2',
            'extras': {
                u'ref': 'boris'
            }
        }
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
 def setup_class(self):
     # No TestSearchIndexer is initialised.
     if not is_search_supported():
         raise SkipTest("Search not supported")
     super(TestLoaderNoIndexing, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
class TestLoaderNoIndexing(TestLoaderBase):
    '''This checks you can re-load a package when the package name
    is unchanged, yet it is not search indexed (due to a problem with that).

    '''
    @classmethod
    def setup_class(self):
        # No TestSearchIndexer is initialised.
        if not is_search_supported():
            raise SkipTest("Search not supported")
        super(TestLoaderNoIndexing, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris',
                    'extras':{u'ref':'boris'}}
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris 2',
                    'extras':{u'ref':'boris'}}
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

    def test_1_reload_with_underscores(self):
        # Create decoy package
        pkg_dict = {'name':u'pkgname1',
                    'title':u'Old package decoy',
                    'extras':{u'ref':'decoy'}}
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([pkg_dict])

        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {'name':u'pkgname1_',
                    'title':u'The real Helga',
                    'extras':{u'ref':'helga'}}
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {'name':u'pkgname1',
                    'title':u'Helga updated',
                    'extras':{u'ref':'helga'}}
        self.loader.load_package(pkg_dict)
        pkg = model.Package.by_name(u'pkgname1_')
        assert pkg
        assert_equal(pkg.title, pkg_dict['title'])
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        decoy = model.Package.by_name(u'pkgname1')
        assert decoy
        assert_equal(decoy.title, u'Old package decoy')

        pkg = model.Package.by_name(u'pkgname1_')
        assert pkg
        assert_equal(pkg.title, u'Helga updated')

        assert not model.Package.by_name(u'pkgname1__')
 def setup_class(self):
     '''NB, no search indexing started'''
     if not is_search_supported():
         raise SkipTest("Search not supported")
     super(TestLoaderNoSearch, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
 def setup_class(self):
     self.tsi = TestSearchIndexer()
     super(TestLoaderUsingUniqueFields, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
class TestLoaderUsingUniqueFields(TestLoaderBase):
    @classmethod
    def setup_class(self):
        self.tsi = TestSearchIndexer()
        super(TestLoaderUsingUniqueFields, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris',
                    'extras':{u'ref':'boris'}}
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([pkg_dict])
        self.tsi.index()
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        # load the package with same name and ref
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris 2',
                    'extras':{u'ref':'boris'}}
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        # load the package with different name, same ref
        pkg_dict = {'name':u'pkgname0changed',
                    'title':u'Boris 3',
                    'extras':{u'ref':'boris'}}
        CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']])

        self.loader.load_package(pkg_dict)
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
        # for now we do not support renaming
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg is None, pkg
        pkg = model.Package.by_name(u'pkgname0')
        assert pkg
        assert pkg.title == pkg_dict['title']

        # load the package with same name, different ref - new package
        other_pkg_dict = pkg_dict
        pkg_dict = {'name':u'pkgname0',
                    'title':u'Boris 4',
                    'extras':{u'ref':'boris-4'}}
        CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']])
        self.loader.load_package(pkg_dict)
        assert pkg_dict['name'] == 'pkgname0_'
        orig_pkg = model.Package.by_name(u'pkgname0')
        assert orig_pkg
        assert orig_pkg.title == u'Boris 3'
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg
        assert pkg.name == pkg_dict['name']
        assert pkg.title == pkg_dict['title']
        assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs)

    def test_1_avoid_long_name_clash(self):
        # load the package once
        num_pkgs = count_pkgs()
        pkg_dict = {'name':u'a'*99,
                    'title':u'99 char name',
                    'extras':{u'ref':'aaa'}}
        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 a clashing package - name appended '_'
        orig_pkg = pkg_dict
        pkg_dict = {'name':orig_pkg['name'],
                     'title':u'bbb',
                     'extras':{u'ref':'bbb'}}
        self.loader.load_package(pkg_dict)
        clash_name = u'a'*99 + u'_'
        pkg = model.Package.by_name(clash_name)
        assert pkg
        assert pkg.title == pkg_dict['title'], pkg.title
        assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs)

        # load another clashing package - name over 100 chars so shortened
        # and finishes '__'
        orig_pkg = pkg_dict
        pkg_dict = {'name':orig_pkg['name'],
                     'title':u'ccc',
                     'extras':{u'ref':'ccc'}}
        self.loader.load_package(pkg_dict)
        clash_name = u'a'*98 + u'__'
        assert pkg_dict['name'] == clash_name, (pkg_dict['name'], clash_name)
        pkg = model.Package.by_name(clash_name)
        assert pkg
        assert pkg.title == pkg_dict['title'], pkg.title
        assert count_pkgs() == num_pkgs + 3, (count_pkgs() - num_pkgs)
Exemple #8
0
 def setup_class(self):
     # No TestSearchIndexer is initialised.
     if not is_search_supported():
         raise SkipTest("Search not supported")
     super(TestLoaderNoIndexing, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
Exemple #9
0
class TestLoaderNoIndexing(TestLoaderBase):
    '''This checks you can re-load a package when the package name
    is unchanged, yet it is not search indexed (due to a problem with that).

    '''
    @classmethod
    def setup_class(self):
        # No TestSearchIndexer is initialised.
        if not is_search_supported():
            raise SkipTest("Search not supported")
        super(TestLoaderNoIndexing, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris',
            'extras': {
                u'ref': 'boris'
            }
        }
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris 2',
            'extras': {
                u'ref': 'boris'
            }
        }
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

    def test_1_reload_with_underscores(self):
        # Create decoy package
        pkg_dict = {
            'name': u'pkgname1',
            'title': u'Old package decoy',
            'extras': {
                u'ref': 'decoy'
            }
        }
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([pkg_dict])

        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {
            'name': u'pkgname1_',
            'title': u'The real Helga',
            'extras': {
                u'ref': 'helga'
            }
        }
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([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 with same name and ref
        pkg_dict = {
            'name': u'pkgname1',
            'title': u'Helga updated',
            'extras': {
                u'ref': 'helga'
            }
        }
        self.loader.load_package(pkg_dict)
        pkg = model.Package.by_name(u'pkgname1_')
        assert pkg
        assert_equal(pkg.title, pkg_dict['title'])
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        decoy = model.Package.by_name(u'pkgname1')
        assert decoy
        assert_equal(decoy.title, u'Old package decoy')

        pkg = model.Package.by_name(u'pkgname1_')
        assert pkg
        assert_equal(pkg.title, u'Helga updated')

        assert not model.Package.by_name(u'pkgname1__')
Exemple #10
0
 def setup_class(self):
     '''NB, no search indexing started'''
     if not is_search_supported():
         raise SkipTest("Search not supported")
     super(TestLoaderNoSearch, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
Exemple #11
0
 def setup_class(self):
     self.tsi = TestSearchIndexer()
     super(TestLoaderUsingUniqueFields, self).setup_class()
     self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')
Exemple #12
0
class TestLoaderUsingUniqueFields(TestLoaderBase):
    @classmethod
    def setup_class(self):
        self.tsi = TestSearchIndexer()
        super(TestLoaderUsingUniqueFields, self).setup_class()
        self.loader = ReplaceByExtraFieldLoader(self.testclient, 'ref')

    # teardown is in the base class

    def test_0_reload(self):
        # create initial package
        num_pkgs = count_pkgs()
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris',
            'extras': {
                u'ref': 'boris'
            }
        }
        assert not model.Package.by_name(pkg_dict['name'])
        CreateTestData.create_arbitrary([pkg_dict])
        self.tsi.index()
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        # load the package with same name and ref
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris 2',
            'extras': {
                u'ref': 'boris'
            }
        }
        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']
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)

        # load the package with different name, same ref
        pkg_dict = {
            'name': u'pkgname0changed',
            'title': u'Boris 3',
            'extras': {
                u'ref': 'boris'
            }
        }
        CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']])

        self.loader.load_package(pkg_dict)
        assert count_pkgs() == num_pkgs + 1, (count_pkgs() - num_pkgs)
        # for now we do not support renaming
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg is None, pkg
        pkg = model.Package.by_name(u'pkgname0')
        assert pkg
        assert pkg.title == pkg_dict['title']

        # load the package with same name, different ref - new package
        other_pkg_dict = pkg_dict
        pkg_dict = {
            'name': u'pkgname0',
            'title': u'Boris 4',
            'extras': {
                u'ref': 'boris-4'
            }
        }
        CreateTestData.flag_for_deletion(pkg_names=[pkg_dict['name']])
        self.loader.load_package(pkg_dict)
        assert pkg_dict['name'] == 'pkgname0_'
        orig_pkg = model.Package.by_name(u'pkgname0')
        assert orig_pkg
        assert orig_pkg.title == u'Boris 3'
        pkg = model.Package.by_name(pkg_dict['name'])
        assert pkg
        assert pkg.name == pkg_dict['name']
        assert pkg.title == pkg_dict['title']
        assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs)

    def test_1_avoid_long_name_clash(self):
        # load the package once
        num_pkgs = count_pkgs()
        pkg_dict = {
            'name': u'a' * 99,
            'title': u'99 char name',
            'extras': {
                u'ref': 'aaa'
            }
        }
        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 a clashing package - name appended '_'
        orig_pkg = pkg_dict
        pkg_dict = {
            'name': orig_pkg['name'],
            'title': u'bbb',
            'extras': {
                u'ref': 'bbb'
            }
        }
        self.loader.load_package(pkg_dict)
        clash_name = u'a' * 99 + u'_'
        pkg = model.Package.by_name(clash_name)
        assert pkg
        assert pkg.title == pkg_dict['title'], pkg.title
        assert count_pkgs() == num_pkgs + 2, (count_pkgs() - num_pkgs)

        # load another clashing package - name over 100 chars so shortened
        # and finishes '__'
        orig_pkg = pkg_dict
        pkg_dict = {
            'name': orig_pkg['name'],
            'title': u'ccc',
            'extras': {
                u'ref': 'ccc'
            }
        }
        self.loader.load_package(pkg_dict)
        clash_name = u'a' * 98 + u'__'
        assert pkg_dict['name'] == clash_name, (pkg_dict['name'], clash_name)
        pkg = model.Package.by_name(clash_name)
        assert pkg
        assert pkg.title == pkg_dict['title'], pkg.title
        assert count_pkgs() == num_pkgs + 3, (count_pkgs() - num_pkgs)