Пример #1
0
class TestRecipeManager(object):
    def setup(self):
        self.git_uri = os.path.join(tc.STAGING, 'git')
        self.config = copy.deepcopy(tc.CONF)
        self.config['pakit.recipe.uris'] = [{'uri': self.git_uri}]
        self.config['pakit.paths.recipes'] = \
            os.path.join(tc.STAGING, 'test_recipes')
        self.manager = None

    def teardown(self):
        if self.manager:
            tc.delete_it(self.manager.uri_db.filename)
        tc.delete_it(self.config.path_to('recipes'))
        os.makedirs(self.config.path_to('recipes'))

    def test_init_new_uris_vcs(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        expect = os.path.join(self.config.path_to('recipes'),
                              self.manager.uri_db[self.git_uri]['path'],
                              '.git')
        assert os.path.exists(expect)

    def test_init_new_uris_vcs_unsupported(self):
        self.config['pakit.recipe.uris'] = [{'uri': 'https://www.google.ca'}]
        self.manager = RecipeManager(self.config)
        with pytest.raises(PakitError):
            self.manager.init_new_uris()

    def test_init_new_uris_vcs_kwargs(self):
        uri = {'tag': '0.31.0', 'uri': self.git_uri}
        self.config['pakit.recipe.uris'] = [uri]
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        expect = os.path.join(self.config.path_to('recipes'),
                              self.manager.uri_db[self.git_uri]['path'],
                              '.git')
        assert os.path.exists(expect)

    def test_init_new_uris_local_path(self):
        uri = 'user_recipes'
        expect = os.path.join(self.config.path_to('recipes'), uri)
        self.config['pakit.recipe.uris'] = [{'uri': uri}]
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert os.path.exists(expect)

    def test_init_new_uris_local_path_exists(self):
        uri = 'user_recipes'
        expect = os.path.join(self.config.path_to('recipes'), uri)
        os.makedirs(expect)
        self.config['pakit.recipe.uris'] = [{'uri': uri}]
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert os.path.exists(expect)

    def test_paths(self):
        uri = 'user_recipes'
        expect = [os.path.join(self.config.path_to('recipes'), uri)]
        self.config['pakit.recipe.uris'] = [{'uri': uri}]
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert self.manager.paths == expect

    def test_check_for_deletions(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()

        path = os.path.join(self.config.path_to('recipes'),
                            self.manager.uri_db[self.git_uri]['path'])
        tc.delete_it(path)
        assert not os.path.exists(path)
        assert self.git_uri in self.manager.uri_db
        self.manager.check_for_deletions()
        assert self.git_uri not in self.manager.uri_db

    def test_check_for_updates_interval(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        interval = self.config.get('pakit.recipe.update_interval')
        old_time = self.manager.uri_db[self.git_uri]['time'] - 2 * interval
        self.manager.uri_db[self.git_uri]['time'] = old_time
        self.manager.uri_db.write()

        self.manager.check_for_updates()
        assert self.manager.uri_db[self.git_uri]['time'] != old_time

    def test_check_for_updates_kwargs(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        uri = {'tag': '0.31.0', 'uri': self.git_uri}
        self.config['pakit.recipe.uris'] = [uri]
        self.manager = RecipeManager(self.config)

        old_time = self.manager.uri_db[self.git_uri]['time']
        self.manager.check_for_updates()
        assert self.manager.uri_db[self.git_uri]['time'] != old_time
Пример #2
0
class TestRecipeManager(object):
    def setup(self):
        self.git_uri = os.path.join(tc.STAGING, "git")
        self.config = copy.deepcopy(tc.CONF)
        self.config.set("pakit.recipe.uris", [{"uri": self.git_uri}])
        self.config.set("pakit.paths.recipes", os.path.join(tc.STAGING, "test_recipes"))
        self.manager = None

    def teardown(self):
        if self.manager:
            tc.delete_it(self.manager.uri_db.filename)
        tc.delete_it(self.config.path_to("recipes"))
        os.makedirs(self.config.path_to("recipes"))

    def test_init_new_uris_vcs(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        expect = os.path.join(self.config.path_to("recipes"), self.manager.uri_db[self.git_uri]["path"], ".git")
        assert os.path.exists(expect)

    def test_init_new_uris_vcs_unsupported(self):
        self.config.set("pakit.recipe.uris", [{"uri": "https://www.google.ca"}])
        self.manager = RecipeManager(self.config)
        with pytest.raises(PakitError):
            self.manager.init_new_uris()

    def test_init_new_uris_vcs_kwargs(self):
        uri = {"tag": "0.31.0", "uri": self.git_uri}
        self.config.set("pakit.recipe.uris", [uri])
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        expect = os.path.join(self.config.path_to("recipes"), self.manager.uri_db[self.git_uri]["path"], ".git")
        assert os.path.exists(expect)

    def test_init_new_uris_local_path(self):
        uri = "user_recipes"
        expect = os.path.join(self.config.path_to("recipes"), uri)
        self.config.set("pakit.recipe.uris", [{"uri": uri}])
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert os.path.exists(expect)

    def test_init_new_uris_local_path_exists(self):
        uri = "user_recipes"
        expect = os.path.join(self.config.path_to("recipes"), uri)
        os.makedirs(expect)
        self.config.set("pakit.recipe.uris", [{"uri": uri}])
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert os.path.exists(expect)

    def test_paths(self):
        uri = "user_recipes"
        expect = [os.path.join(self.config.path_to("recipes"), uri)]
        self.config.set("pakit.recipe.uris", [{"uri": uri}])
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        assert self.manager.paths == expect

    def test_check_for_deletions(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()

        path = os.path.join(self.config.path_to("recipes"), self.manager.uri_db[self.git_uri]["path"])
        tc.delete_it(path)
        assert not os.path.exists(path)
        assert self.git_uri in self.manager.uri_db
        self.manager.check_for_deletions()
        assert self.git_uri not in self.manager.uri_db

    def test_check_for_updates_interval(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        interval = self.config.get("pakit.recipe.update_interval")
        old_time = self.manager.uri_db[self.git_uri]["time"] - 2 * interval
        self.manager.uri_db[self.git_uri]["time"] = old_time
        self.manager.uri_db.write()

        self.manager.check_for_updates()
        assert self.manager.uri_db[self.git_uri]["time"] != old_time

    def test_check_for_updates_kwargs(self):
        self.manager = RecipeManager(self.config)
        self.manager.init_new_uris()
        uri = {"tag": "0.31.0", "uri": self.git_uri}
        self.config.set("pakit.recipe.uris", [uri])
        self.manager = RecipeManager(self.config)

        old_time = self.manager.uri_db[self.git_uri]["time"]
        self.manager.check_for_updates()
        assert self.manager.uri_db[self.git_uri]["time"] != old_time