Beispiel #1
0
    def test_fetch_from_cache(self):
        """ Test whether a list of questions is returned from cache """

        question = read_file('data/stackexchange_question')

        httpretty.register_uri(httpretty.GET,
                               STACKEXCHANGE_QUESTIONS_URL,
                               body=question,
                               status=200)

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        stack = StackExchange(site="stackoverflow",
                              tagged="python",
                              token="aaa",
                              max_questions=1,
                              cache=cache)

        questions = [question for question in stack.fetch(from_date=None)]
        del questions[0]['timestamp']

        # 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_questions = [
            cache_question for cache_question in stack.fetch_from_cache()
        ]
        del cache_questions[0]['timestamp']

        self.assertEqual(cache_questions, questions)
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        stack = StackExchange(site="stackoverflow", tagged="python", token="aaa", max_questions=1)

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

        stack = StackExchange(site="stackoverflow", tagged="python", token="aaa", max_questions=1)

        with self.assertRaises(CacheError):
            _ = [cache_question for cache_question in stack.fetch_from_cache()]
    def test_fetch_from_empty_cache(self):
        """Test if there are not any questions returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        stack = StackExchange(site="stackoverflow", tagged="python", token="aaa", max_questions=1, cache=cache)

        cache_questions = [cache_question for cache_question in stack.fetch_from_cache()]

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

        cache = Cache(self.tmp_path)
        stack = StackExchange(site="stackoverflow", tagged="python", token="aaa", max_questions=1, cache=cache)

        cache_questions = [cache_question for cache_question in stack.fetch_from_cache()]

        self.assertEqual(len(cache_questions), 0)
    def test_fetch_from_cache(self):
        """ Test whether a list of questions is returned from cache """

        question = read_file('data/stackexchange_question')

        httpretty.register_uri(httpretty.GET,
                               STACKEXCHANGE_QUESTIONS_URL,
                               body=question, status=200)

        # First, we fetch the bugs from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        stack = StackExchange(site="stackoverflow", tagged="python", token="aaa", max_questions=1, cache=cache)

        questions = [question for question in stack.fetch(from_date=None)]
        del questions[0]['timestamp']

        # 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_questions = [cache_question for cache_question in stack.fetch_from_cache()]
        del cache_questions[0]['timestamp']

        self.assertEqual(cache_questions, questions)