def test_get_archieve(self):

        basedir = os.path.abspath(os.path.dirname(__file__))
        try:
            handle = open(basedir + "/../../fixture/start-cbab6de129fdece998a7aa1c4f6e8be34d2170be.tar.gz", "rb")
            content = handle.read()
        except Exception as inst:
            print(inst)
        finally:
            handle.close()

        httpretty.enable()  # enable HTTPretty so that it will monkey patch the socket module
        httpretty.register_uri(httpretty.GET,
                               "https://localhost/api/v3/projects/web-jenkins-jobs%2Funit-tests-codeception/repository/tags?private_token=123456",
                               body=self.get_gitlab_responnse(),
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               "https://localhost/web-jenkins-jobs/unit-tests-codeception/repository/archive.tar.gz?ref=v1.1.1",
                               body=content,
                               # content_type="text/plain",
                               status=200)

        gitlab = Download(self.get_data())
        result_archieve = gitlab.get_archieve("unit", "unit-tests-codeception", "v*")

        abstract_job = result_archieve.split("/")
        assert abstract_job.pop() == "unit-tests-codeception.tar.gz"
        os.remove(result_archieve)
    def test_get_latest_version(self):
        httpretty.enable()  # enable HTTPretty so that it will monkey patch the socket module
        httpretty.register_uri(httpretty.GET,
                               "https://localhost/api/v3/projects/web-jenkins-jobs%2Funit-tests-codeception/repository/tags?private_token=123456",
                               body=self.get_gitlab_responnse(),
                               status=200)

        gitlab = Download(self.get_data())
        gitlab.get_latest_version("unit-tests-codeception", "v1.*") is "v1.1.1"
    def test_get_git_abstract_project(self):
        parser = Parser(self._get_parser_data())

        download = Download(self.get_git_download_data())
        download.get_archieve = Mock(
            return_value="/tmp/unitests/build-composer-cc2632fae2cab2f73ce6e6607d9b0befec0b82a1.tar.gz")
        job = JobBuilder(parser, download)
        file = job.get_git_abstract_project(parser)

        assert file is "/tmp/unitests/build-composer-cc2632fae2cab2f73ce6e6607d9b0befec0b82a1.tar.gz"
    def test_get_latest_version_no_version_exception(self):
        httpretty.enable()  # enable HTTPretty so that it will monkey patch the socket module
        httpretty.register_uri(httpretty.GET,
                               "https://localhost/api/v3/projects/web-jenkins-jobs%2Funit-tests-codeception/repository/tags?private_token=123456",
                               body="{}",
                               status=200)

        gitlab = Download(self.get_data())
        with pytest.raises(Exception) as inst:
            gitlab.get_latest_version("unit-tests-codeception", "v2.*")
        assert str(inst.value) == "No matching version for unit-tests-codeception v2.*."
    def test_get_archieve_job_not_not_found(self):

        httpretty.register_uri(httpretty.GET,
                               "https://localhost/web-jenkins-jobs/unit-tests-codeception/repository/archive.tar.gz?ref=v1.1.1",
                               body="",
                               content_type="text/plain",
                               status=404)

        gitlab = Download(self.get_data())
        with pytest.raises(Exception) as inst:
            gitlab.get_archieve("unit", "unit-tests-codeception", "v1.1.1.")
        assert str(inst.value) == "It was not find the abstract job unit-tests-codeception in gitlab."
 def test_get_archieve_configuration_not_not_found(self):
     gitlab = Download({})
     with pytest.raises(Exception) as inst:
         gitlab.get_archieve("unit", "unit-tests-codeception", "v1.1.1.")
     assert str(inst.value) == "It was not possible to find the gitlab key host in configuration."