示例#1
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        remo = ReMo(MOZILLA_REPS_SERVER_URL, tag='test')

        self.assertEqual(remo.url, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.origin, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.tag, 'test')
        self.assertIsInstance(remo.client, ReMoClient)

        # When tag is empty or None it will be set to
        # the value in url
        remo = ReMo(MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.url, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.origin, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.tag, MOZILLA_REPS_SERVER_URL)

        remo = ReMo(MOZILLA_REPS_SERVER_URL, tag='')
        self.assertEqual(remo.url, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.origin, MOZILLA_REPS_SERVER_URL)
        self.assertEqual(remo.tag, MOZILLA_REPS_SERVER_URL)

        # If no url is provided, MOZILLA_REPS_URL is used
        remo = ReMo()
        self.assertEqual(remo.url, MOZILLA_REPS_URL)
        self.assertEqual(remo.origin, MOZILLA_REPS_URL)
        self.assertEqual(remo.tag, MOZILLA_REPS_URL)
示例#2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        remo = ReMo(MOZILLA_REPS_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = [event for event in remo.fetch_from_cache()]
示例#3
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any events returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        remo = ReMo(MOZILLA_REPS_SERVER_URL, cache=cache)
        cached_events = [event for event in remo.fetch_from_cache()]
        self.assertEqual(len(cached_events), 0)
示例#4
0
    def test_fetch(self):
        """Test whether the events are returned"""

        HTTPServer.routes()

        # Test fetch events with their reviews
        remo = ReMo(MOZILLA_REPS_SERVER_URL)

        events = [page for page in remo.fetch()]

        self.assertEqual(len(events), 4)

        self.__check_events_contents(events)

        # Check requests: first get all users, then the events
        expected = [{
            'limit': ['400']
        }, {
            'limit': ['40'],
            'offset': ['0']
        }, {
            'limit': ['40'],
            'offset': ['2']
        }]

        self.assertEqual(len(HTTPServer.requests_http), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(HTTPServer.requests_http[i].querystring,
                                 expected[i])
示例#5
0
    def test_fetch_empty(self):
        """Test whether it works when no jobs are fetched"""

        HTTPServer.routes(empty=True)

        remo = ReMo(MOZILLA_REPS_SERVER_URL)
        events = [event for event in remo.fetch()]

        self.assertEqual(len(events), 0)
示例#6
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        HTTPServer.routes()

        # First, we fetch the events from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        remo = ReMo(MOZILLA_REPS_SERVER_URL, cache=cache)

        events = [event for event in remo.fetch()]

        requests_done = len(HTTPServer.requests_http)

        # Now, we get the events from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_events = [event for event in remo.fetch_from_cache()]
        # No new requests to the server
        self.assertEqual(len(HTTPServer.requests_http), requests_done)
        # The contents should be the same
        self.assertEqual(len(cached_events), len(events))
        for i in range(0, len(events)):
            self.assertDictEqual(cached_events[i]['data'], events[i]['data'])