Exemple #1
0
    def __test_fetch(self, category='events'):
        """Test whether the events are returned"""

        items_page = ReMoClient.ITEMS_PER_PAGE
        pages = 2  # two pages of testing data

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

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

        items = [page for page in remo.fetch(category=category)]

        self.assertEqual(len(items), items_page * pages)

        if category == 'events':
            self.__check_events_contents(items)
        elif category == 'users':
            self.__check_users_contents(items)
        elif category == 'activities':
            self.__check_activities_contents(items)

        # Check requests: page list, items, page list, items
        expected = [{'page':['1']}]
        for i in range(0, items_page):
            expected += [{}]
        expected += [{'page':['2']}]
        for i in range(0, items_page):
            expected += [{}]

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

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

        HTTPServer.routes(empty=True)

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

        self.assertEqual(len(events), 0)
Exemple #3
0
    def test_fetch_empty(self):
        """Test whether it works when no items are fetched"""

        HTTPServer.routes(empty=True)

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

        self.assertEqual(len(events), 0)
Exemple #4
0
    def test_fetch_offset(self):
        items_page = ReMoClient.ITEMS_PER_PAGE
        pages = 2  # two pages of testing data
        offset = 15

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

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

        # Test we get the correct number of items from an offset
        items = [page for page in remo.fetch(offset=15)]
        self.assertEqual(len(items), (items_page * pages) - offset)

        # Test that the same offset (17) is the same item
        items = [page for page in remo.fetch(offset=5)]
        uuid_17_1 = items[12]['uuid']
        self.assertEqual(items[12]['offset'], 17)
        items = [page for page in remo.fetch(offset=12)]
        uuid_17_2 = items[5]['uuid']
        self.assertEqual(items[5]['offset'], 17)
        self.assertEqual(uuid_17_1, uuid_17_2)
Exemple #5
0
    def test_fetch_offset(self):
        items_page = ReMoClient.ITEMS_PER_PAGE
        pages = 2  # two pages of testing data
        offset = 15

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

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

        # Test we get the correct number of items from an offset
        items = [page for page in remo.fetch(offset=15)]
        self.assertEqual(len(items), (items_page * pages) - offset)

        # Test that the same offset (17) is the same item
        items = [page for page in remo.fetch(offset=5)]
        uuid_17_1 = items[12]['uuid']
        self.assertEqual(items[12]['offset'], 17)
        items = [page for page in remo.fetch(offset=12)]
        uuid_17_2 = items[5]['uuid']
        self.assertEqual(items[5]['offset'], 17)
        self.assertEqual(uuid_17_1, uuid_17_2)
Exemple #6
0
    def __test_fetch(self, category='events'):
        """Test whether the events are returned"""

        items_page = ReMoClient.ITEMS_PER_PAGE
        pages = 2  # two pages of testing data

        HTTPServer.routes()
        prev_requests_http = len(HTTPServer.requests_http)

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

        items = [page for page in remo.fetch(category=category)]

        self.assertEqual(len(items), items_page * pages)

        if category == 'events':
            self.__check_events_contents(items)
        elif category == 'users':
            self.__check_users_contents(items)
        elif category == 'activities':
            self.__check_activities_contents(items)

        # Check requests: page list, items, page list, items
        expected = [{'page': ['1']}]
        for i in range(0, items_page):
            expected += [{}]
        expected += [{'page': ['2']}]
        for i in range(0, items_page):
            expected += [{}]

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

        for i in range(len(expected)):
            self.assertDictEqual(HTTPServer.requests_http[i].querystring,
                                 expected[i])
Exemple #7
0
    def __test_fetch_from_cache(self, category):
        """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)

        items = [item for item in remo.fetch(category=category)]

        requests_done = len(HTTPServer.requests_http)

        # Now, we get the items from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_items = [item for item 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_items), len(items))
        for i in range(0, len(items)):
            self.assertDictEqual(cached_items[i]['data'], items[i]['data'])
Exemple #8
0
    def __test_fetch_from_cache(self, category):
        """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)

        items = [item for item in remo.fetch(category=category)]

        requests_done = len(HTTPServer.requests_http)

        # Now, we get the items from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_items = [item for item 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_items), len(items))
        for i in range(0,len(items)):
            self.assertDictEqual(cached_items[i]['data'], items[i]['data'])