예제 #1
0
    def test_get_repo_by_name(self):
        """ Test the get_repo_by_name function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/19/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/20/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/i386')
        self.assertEqual(results, None)
예제 #2
0
    def test_get_repositories(self):
        """ Test the get_repositories function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name,
                         'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results[0].arch.name, 'x86_64')

        self.assertEqual(results[1].name,
                         'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results[1].arch.name, 'x86_64')

        self.assertEqual(results[2].name,
                         'pub/fedora/linux/updates/testing/21/x86_64')
        self.assertEqual(results[2].arch.name, 'x86_64')
예제 #3
0
    def test_get_repo_prefix_arch(self):
        """ Test the get_repo_prefix_arch function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f20', 'x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f26', 'x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/26/x86_64')

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f27', 'x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f20', 'i386')
        self.assertEqual(results, None)
예제 #4
0
    def setUp(self):
        """ Set up the environnment, ran before every test. """
        super(FlaskUiAdminTest, self).setUp()

        mirrormanager2.app.APP.config['TESTING'] = True
        mirrormanager2.app.SESSION = self.session
        mirrormanager2.app.ADMIN.SESSION = self.session
        mirrormanager2.app.APP.SESSION = self.session
        mirrormanager2.admin.SESSION = self.session
        mirrormanager2.admin.ADMIN.SESSION = self.session
        mirrormanager2.admin.APP.SESSION = self.session
        for view in mirrormanager2.admin.VIEWS:
            view.session = self.session
        self.app = mirrormanager2.app.APP.test_client()

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_site_admin(self.session)
        tests.create_hosts(self.session)
        tests.create_location(self.session)
        tests.create_netblockcountry(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_hostcategorydir(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)
        tests.create_repositoryredirect(self.session)
예제 #5
0
    def setUp(self):
        """ Set up the environnment, ran before every test. """
        super(FlaskUiAdminTest, self).setUp()

        mirrormanager2.app.APP.config['TESTING'] = True
        mirrormanager2.app.SESSION = self.session
        mirrormanager2.app.ADMIN.SESSION = self.session
        mirrormanager2.app.APP.SESSION = self.session
        mirrormanager2.admin.SESSION = self.session
        mirrormanager2.admin.ADMIN.SESSION = self.session
        mirrormanager2.admin.APP.SESSION = self.session
        for view in mirrormanager2.admin.VIEWS:
            view.session = self.session
        self.app = mirrormanager2.app.APP.test_client()

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_site_admin(self.session)
        tests.create_hosts(self.session)
        tests.create_location(self.session)
        tests.create_netblockcountry(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_hostcategorydir(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)
        tests.create_repositoryredirect(self.session)
예제 #6
0
    def test_get_repositories(self):
        """ Test the get_repositories function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(
            results[0].name, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results[0].arch.name, 'x86_64')

        self.assertEqual(
            results[1].name, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results[1].arch.name, 'x86_64')

        self.assertEqual(
            results[2].name, 'pub/fedora/linux/updates/testing/21/x86_64')
        self.assertEqual(results[2].arch.name, 'x86_64')
예제 #7
0
    def test_get_repo_by_name(self):
        """ Test the get_repo_by_name function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(
            results.name, 'pub/fedora/linux/updates/testing/19/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(
            results.name, 'pub/fedora/linux/updates/testing/20/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/i386')
        self.assertEqual(results, None)
예제 #8
0
    def test_version_arches(self):
        """ Test the Version.arches object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(item.arches, set([u'x86_64']))
        item = model.Version.get(self.session, 2)
        self.assertEqual(item.arches, set([]))
        item = model.Version.get(self.session, 3)
        self.assertEqual(item.arches, set([u'x86_64']))
    def test_version_arches(self):
        """ Test the Version.arches object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(item.arches, set([u'x86_64']))
        item = model.Version.get(self.session, 2)
        self.assertEqual(item.arches, set([]))
        item = model.Version.get(self.session, 3)
        self.assertEqual(item.arches, set([u'x86_64']))
예제 #10
0
    def test_mta(self):
        """ Test the mta script. """
        command = self.command[:]

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout, "No category could be found by the name: Fedora Linux\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'No category could be found by the name: Fedora Archive\n')
        self.assertEqual(stderr, '')

        # One step further
        item = model.Directory(
            name='pub/archive',
            readable=True,
        )
        self.session.add(item)
        self.session.flush()
        item = model.Category(name='Fedora Archive',
                              product_id=1,
                              canonicalhost='http://archive.fedoraproject.org',
                              topdir_id=10,
                              publiclist=True)
        self.session.add(item)

        item = model.CategoryDirectory(
            directory_id=6,
            category_id=1,
        )
        self.session.add(item)
        item = model.CategoryDirectory(
            directory_id=8,
            category_id=1,
        )
        self.session.add(item)

        self.session.commit()

        # Before the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 4)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(results[0].directory.name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(results[1].directory.name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(results[2].directory.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 10)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(results[6].name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[7].name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[8].name,
                         'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'trying to find pub/archive/fedora/linux/updates/testing/'
            '26/x86_64\n'
            'Unable to find a directory in [Fedora Archive] for pub/fedora/'
            'linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        # Run the script so that it works

        item = model.Directory(
            name='pub/archive/fedora/linux/updates/testing/26/x86_64',
            readable=True,
        )
        self.session.add(item)
        self.session.commit()

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'trying to find pub/archive/fedora/'
            'linux/updates/testing/26/x86_64\n'
            'pub/fedora/linux/updates/testing/26/x86_64 => '
            'pub/archive/fedora/linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 4)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(results[0].directory.name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(results[1].directory.name,
                         'pub/archive/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(results[2].directory.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        # After the script

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 11)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(results[6].name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[7].name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[8].name,
                         'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')
        self.assertEqual(results[10].name,
                         'pub/archive/fedora/linux/updates/testing/26/x86_64')
예제 #11
0
    def test_get_mirrors(self):
        """ Test the get_mirrors function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_hosts(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_netblockcountry(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, private=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'private.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, internet2=True)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 internet2_clients=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 internet2_clients=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 asn_clients=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 asn_clients=False)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'private.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=False)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawl_duration=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawl_duration=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawled=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawled=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_checked_in=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_checked_in=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_private=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, up2date=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, up2date=False)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(self.session, version_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, version_id=3)

        tests.create_version(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session, version_id=1)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
        results = mirrormanager2.lib.get_mirrors(self.session, version_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, arch_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, arch_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
예제 #12
0
    def test_mta(self):
        """ Test the mta script. """
        command = self.command[:]

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout,
            "No category could be found by the name: Fedora Linux\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'No category could be found by the name: Fedora Archive\n')
        self.assertEqual(stderr, '')

        # One step further
        item = model.Directory(
            name='pub/archive',
            readable=True,
        )
        self.session.add(item)
        self.session.flush()
        item = model.Category(
            name='Fedora Archive',
            product_id=1,
            canonicalhost='http://archive.fedoraproject.org',
            topdir_id=10,
            publiclist=True
        )
        self.session.add(item)

        item = model.CategoryDirectory(
            directory_id=6,
            category_id=1,
        )
        self.session.add(item)
        item = model.CategoryDirectory(
            directory_id=8,
            category_id=1,
        )
        self.session.add(item)

        self.session.commit()

        # Before the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(
            results[0].directory.name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(
            results[1].directory.name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(
            results[2].directory.name,
            'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 10)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(
            results[6].name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(
            results[7].name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(
            results[8].name,
            'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'trying to find pub/archive/fedora/linux/updates/testing/'
            '26/x86_64\n'
            'Unable to find a directory in [Fedora Archive] for pub/fedora/'
            'linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        # Run the script so that it works

        item = model.Directory(
            name='pub/archive/fedora/linux/updates/testing/26/x86_64',
            readable=True,
        )
        self.session.add(item)
        self.session.commit()

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'trying to find pub/archive/fedora/'
            'linux/updates/testing/26/x86_64\n'
            'pub/fedora/linux/updates/testing/26/x86_64 => '
            'pub/archive/fedora/linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(
            results[0].directory.name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(
            results[1].directory.name,
            'pub/archive/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(
            results[2].directory.name,
            'pub/fedora/linux/updates/testing/27/x86_64')

        # After the script

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 11)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(
            results[6].name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(
            results[7].name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(
            results[8].name,
            'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')
        self.assertEqual(
            results[10].name,
            'pub/archive/fedora/linux/updates/testing/26/x86_64')
예제 #13
0
    def test_get_mirrors(self):
        """ Test the get_mirrors function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_hosts(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_netblockcountry(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, private=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'private.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, internet2=True)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(
            self.session, internet2_clients=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, internet2_clients=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, asn_clients=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        results = mirrormanager2.lib.get_mirrors(
            self.session, asn_clients=False)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'private.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=False)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawl_duration=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawl_duration=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawled=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawled=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_checked_in=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_checked_in=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_private=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, up2date=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, up2date=False)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=3)

        tests.create_version(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=1)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, arch_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, arch_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')