Ejemplo n.º 1
0
    def test_multiple_repos(self):
        """
        Tests saving and loading multiple repos.
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo1['baseurl'] = 'http://localhost/repo1'

        repo2 = Repo('test-repo-2')
        repo2['baseurl'] = 'http://localhost/repo2'

        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        self.assertEqual(2, len(loaded.all_repos()))

        found_repo1 = loaded.get_repo('test-repo-1')
        self.assertTrue(found_repo1 is not None)
        self.assertTrue(_repo_eq(repo1, found_repo1))

        found_repo2 = loaded.get_repo('test-repo-2')
        self.assertTrue(found_repo2 is not None)
        self.assertTrue(_repo_eq(repo2, found_repo2))
Ejemplo n.º 2
0
    def test_one_repo_save_and_load(self):
        """
        Tests the normal flow of saving and loading, using only one repo to
        minimize complications.
        """

        # Setup
        add_me = Repo('test-repo-1')
        add_me['baseurl'] = 'http://localhost/repo'
        add_me['enabled'] = 1
        add_me['gpgkey'] = '/tmp/key'
        add_me['sslverify'] = 0
        add_me['gpgcheck'] = 0
        add_me['sslcacert'] = '/tmp/sslcacert'
        add_me['sslclientcert'] = '/tmp/clientcert'

        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test Save
        repo_file.add_repo(add_me)
        repo_file.save()

        # Verify Save
        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))

        # Test Load
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        # Verify Load
        self.assertEqual(1, len(loaded.all_repos()))

        found_repo = loaded.get_repo('test-repo-1')
        self.assertTrue(found_repo is not None)
        self.assertTrue(_repo_eq(add_me, found_repo))
Ejemplo n.º 3
0
    def test_delete_repo(self):
        """
        Tests removing an existing repo is correctly saved and loaded
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo2 = Repo('test-repo-2')

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()
        
        # Test
        repo_file.remove_repo_by_name('test-repo-1')
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()
        
        self.assertEqual(1, len(loaded.all_repos()))

        self.assertTrue(loaded.get_repo('test-repo-1') is None)
        self.assertTrue(loaded.get_repo('test-repo-2') is not None)
Ejemplo n.º 4
0
    def test_no_repos_save_load(self):
        """
        Tests that saving and loading a file with no repos is successful.
        """

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        # Verify
        self.assertEqual(0, len(loaded.all_repos()))