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

        github = GitHub("zhquan_example", "repo", "aaa")

        with self.assertRaises(CacheError):
            _ = [cache_issues for cache_issues in github.fetch_from_cache()]
Beispiel #2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        github = GitHub("zhquan_example", "repo", "aaa")

        with self.assertRaises(CacheError):
            _ = [cache_issues for cache_issues in github.fetch_from_cache()]
Beispiel #3
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any issues returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        github = GitHub("zhquan_example", "repo", "aaa", cache=cache)

        cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()]

        self.assertEqual(len(cache_issues), 0)
Beispiel #4
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any issues returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        github = GitHub("zhquan_example", "repo", "aaa", None, cache=cache)

        cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()]

        self.assertEqual(len(cache_issues), 0)
Beispiel #5
0
    def test_fetch_from_cache(self):
        """ Test whether a list of issues is returned from cache """

        body = read_file('data/github_request')
        login = read_file('data/github_login')

        httpretty.register_uri(httpretty.GET,
                               GITHUB_ISSUES_URL,
                               body=body,
                               status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_USER_URL,
                               body=login,
                               status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body="[]",
                               status=200,
                               forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                               })

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        github = GitHub("zhquan_example", "repo", "aaa", cache=cache)

        issues = [issues for issues in github.fetch()]

        # Now, we get the bugs from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cache_issues = [
            cache_issues for cache_issues in github.fetch_from_cache()
        ]

        del issues[0]['timestamp']
        del cache_issues[0]['timestamp']
        self.assertDictEqual(issues[0], cache_issues[0])
        self.assertEqual(len(issues), len(cache_issues))
Beispiel #6
0
    def test_fetch_from_cache(self):
        """ Test whether a list of issues is returned from cache """

        body = read_file('data/github_request')
        login = read_file('data/github_login')

        httpretty.register_uri(httpretty.GET,
                               GITHUB_ISSUES_URL,
                               body=body, status=200,
                               forcing_headers={
                                    'X-RateLimit-Remaining': '20',
                                    'X-RateLimit-Reset': '15'
                               })
        httpretty.register_uri(httpretty.GET,
                              GITHUB_USER_URL,
                              body=login, status=200,
                              forcing_headers={
                                   'X-RateLimit-Remaining': '20',
                                   'X-RateLimit-Reset': '15'
                              })
        httpretty.register_uri(httpretty.GET,
                               GITHUB_ORGS_URL,
                               body="[]", status=200,
                               forcing_headers={
                                    'X-RateLimit-Remaining': '20',
                                    'X-RateLimit-Reset': '15'
                               })

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        github = GitHub("zhquan_example", "repo", "aaa", cache=cache)

        issues = [issues for issues in github.fetch()]

        # Now, we get the bugs from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()]

        del issues[0]['timestamp']
        del cache_issues[0]['timestamp']
        self.assertDictEqual(issues[0], cache_issues[0])
        self.assertEqual(len(issues), len(cache_issues))