Esempio n. 1
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        jenkins = Jenkins(JENKINS_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = [build for build in jenkins.fetch_from_cache()]
Esempio n. 2
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any builds returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        jenkins = Jenkins(JENKINS_SERVER_URL, cache=cache)
        cached_builds = [build for build in jenkins.fetch_from_cache()]
        self.assertEqual(len(cached_builds), 0)
Esempio n. 3
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        jenkins = Jenkins(JENKINS_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = [build for build in jenkins.fetch_from_cache()]
Esempio n. 4
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any builds returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        jenkins = Jenkins(JENKINS_SERVER_URL, cache=cache)
        cached_builds = [build for build in jenkins.fetch_from_cache()]
        self.assertEqual(len(cached_builds), 0)
Esempio n. 5
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        bodies_jobs = read_file('data/jenkins_jobs.json', mode='rb')
        bodies_builds_job = read_file('data/jenkins_job_builds.json')

        def request_callback(method, uri, headers):
            if uri.startswith(JENKINS_JOBS_URL):
                body = bodies_jobs
            elif uri.startswith(JENKINS_JOB_BUILDS_URL_1) or \
                 uri.startswith(JENKINS_JOB_BUILDS_URL_2):
                body = bodies_builds_job
            else:
                body = ''

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOBS_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_1,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_2,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        # First, we fetch the builds from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        jenkins = Jenkins(JENKINS_SERVER_URL, cache=cache)

        builds = [build for build in jenkins.fetch()]

        # Now, we get the builds from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_builds = [build for build in jenkins.fetch_from_cache()]
        self.assertEqual(len(cached_builds), len(builds))

        with open("data/jenkins_build.json") as build_json:
            first_build = json.load(build_json)
            self.assertDictEqual(cached_builds[0]['data'], first_build['data'])
Esempio n. 6
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        bodies_jobs = read_file('data/jenkins_jobs.json', mode='rb')
        bodies_builds_job = read_file('data/jenkins_job_builds.json')

        def request_callback(method, uri, headers):
            if uri.startswith(JENKINS_JOBS_URL):
                body = bodies_jobs
            elif uri.startswith(JENKINS_JOB_BUILDS_URL_1) or \
                 uri.startswith(JENKINS_JOB_BUILDS_URL_2):
                body = bodies_builds_job
            else:
                body = ''

            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOBS_URL,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(3)
                               ])
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_1,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_2,
                               responses=[
                                    httpretty.Response(body=request_callback) \
                                    for _ in range(2)
                               ])

        # First, we fetch the builds from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        jenkins = Jenkins(JENKINS_SERVER_URL, cache=cache)

        builds = [build for build in jenkins.fetch()]

        # Now, we get the builds from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_builds = [build for build in jenkins.fetch_from_cache()]
        self.assertEqual(len(cached_builds), len(builds))

        with open("data/jenkins_build.json") as build_json:
            first_build = json.load(build_json)
            self.assertDictEqual(cached_builds[0]['data'], first_build['data'])