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

        phab = Phabricator(PHABRICATOR_URL, 'AAAA')

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

        cache = Cache(self.tmp_path)
        phab = Phabricator(PHABRICATOR_URL, 'AAAA', cache=cache)
        cached_tasks = [task for task in phab.fetch_from_cache()]
        self.assertEqual(len(cached_tasks), 0)
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        phab = Phabricator(PHABRICATOR_URL, 'AAAA')

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

        cache = Cache(self.tmp_path)
        phab = Phabricator(PHABRICATOR_URL, 'AAAA', cache=cache)
        cached_tasks = [task for task in phab.fetch_from_cache()]
        self.assertEqual(len(cached_tasks), 0)
Beispiel #5
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the tasks from the server,
        # storing them in a cache
        cache = Cache(self.tmp_path)
        phab = Phabricator(PHABRICATOR_URL, 'AAAA', cache=cache)

        tasks = [task for task in phab.fetch()]
        self.assertEqual(len(http_requests), 12)

        # Now, we get the tasks from the cache.
        # The tasks should be the same and there won't be
        # any new request to the server
        cached_tasks = [task for task in phab.fetch_from_cache()]
        self.assertEqual(len(cached_tasks), len(tasks))

        expected = [(69, 16, 0, 'jdoe', 'jdoe',
                     '1b4c15d26068efcae83cd920bcada6003d2c4a6c', 1462306027.0),
                    (73, 20, 0, 'jdoe', 'janesmith',
                     '5487fc704f2d3c4e83ab0cd065512a181c1726cc', 1462464642.0),
                    (78, 17, 0, 'jdoe', None,
                     'fa971157c4d0155652f94b673866abd83b929b27', 1462792338.0),
                    (296, 18, 2, 'jane', 'jrae',
                     'e8fa3e4a4381d6fea3bcf5c848f599b87e7dc4a6', 1467196707.0)]

        self.assertEqual(len(cached_tasks), len(expected))

        for x in range(len(cached_tasks)):
            task = cached_tasks[x]
            expc = expected[x]
            self.assertEqual(task['data']['id'], expc[0])
            self.assertEqual(len(task['data']['transactions']), expc[1])
            self.assertEqual(len(task['data']['projects']), expc[2])
            self.assertEqual(task['data']['fields']['authorData']['userName'],
                             expc[3])

            # Check owner data; when it is null owner is not included
            if not expc[4]:
                self.assertNotIn('ownerData', task['data']['fields'])
            else:
                self.assertEqual(
                    task['data']['fields']['ownerData']['userName'], expc[4])

            self.assertEqual(task['uuid'], expc[5])
            self.assertEqual(task['origin'], PHABRICATOR_URL)
            self.assertEqual(task['updated_on'], expc[6])
            self.assertEqual(task['category'], 'task')
            self.assertEqual(task['tag'], PHABRICATOR_URL)

            # Compare chached and fetched task
            self.assertDictEqual(task['data'], tasks[x]['data'])

        # No more requests were sent
        self.assertEqual(len(http_requests), 12)
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the tasks from the server,
        # storing them in a cache
        cache = Cache(self.tmp_path)
        phab = Phabricator(PHABRICATOR_URL, 'AAAA', cache=cache)

        tasks = [task for task in phab.fetch()]
        self.assertEqual(len(http_requests), 12)

        # Now, we get the tasks from the cache.
        # The tasks should be the same and there won't be
        # any new request to the server
        cached_tasks = [task for task in phab.fetch_from_cache()]
        self.assertEqual(len(cached_tasks), len(tasks))

        expected = [(69, 16, 0, 'jdoe', 'jdoe', '1b4c15d26068efcae83cd920bcada6003d2c4a6c', 1462306027.0),
                    (73, 20, 0, 'jdoe', 'janesmith', '5487fc704f2d3c4e83ab0cd065512a181c1726cc', 1462464642.0),
                    (78, 17, 0, 'jdoe', None, 'fa971157c4d0155652f94b673866abd83b929b27', 1462792338.0),
                    (296, 18, 2, 'jane', 'jrae','e8fa3e4a4381d6fea3bcf5c848f599b87e7dc4a6', 1467196707.0)]

        self.assertEqual(len(cached_tasks), len(expected))

        for x in range(len(cached_tasks)):
            task = cached_tasks[x]
            expc = expected[x]
            self.assertEqual(task['data']['id'], expc[0])
            self.assertEqual(len(task['data']['transactions']), expc[1])
            self.assertEqual(len(task['data']['projects']), expc[2])
            self.assertEqual(task['data']['fields']['authorData']['userName'], expc[3])

            # Check owner data; when it is null owner is not included
            if not expc[4]:
                self.assertNotIn('ownerData', task['data']['fields'])
            else:
                self.assertEqual(task['data']['fields']['ownerData']['userName'], expc[4])

            self.assertEqual(task['uuid'], expc[5])
            self.assertEqual(task['origin'], PHABRICATOR_URL)
            self.assertEqual(task['updated_on'], expc[6])
            self.assertEqual(task['category'], 'task')
            self.assertEqual(task['tag'], PHABRICATOR_URL)

            # Compare chached and fetched task
            self.assertDictEqual(task['data'], tasks[x]['data'])

        # No more requests were sent
        self.assertEqual(len(http_requests), 12)