Exemple #1
0
    def test_fetch_removed_content(self):
        """Test if the method works when a content is not found"""

        http_requests = setup_http_server()

        # Set server to return a 404 error
        httpretty.register_uri(httpretty.GET,
                               CONFLUENCE_HISTORICAL_CONTENT_1,
                               status=404,
                               body="Mock 404 error")

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch()]

        expected = [('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976',
                     1467402626.0),
                    ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd',
                     1467831550.0)]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['origin'], CONFLUENCE_URL)
            self.assertEqual(hc['updated_on'], expected[x][3])
            self.assertEqual(hc['category'], 'historical content')
            self.assertEqual(hc['tag'], CONFLUENCE_URL)

        # Check requests
        expected = [
            {
                'cql':
                ["lastModified>='1970-01-01 00:00' order by lastModified"],
                'limit': ['200']
            },
            {
                'cql':
                ["lastModified>='1970-01-01 00:00' order by lastModified"],
                'start': ['2'],
                'limit': ['2']  # Hardcoded in JSON dataset
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            }
        ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        confluence = Confluence(CONFLUENCE_URL)

        with self.assertRaises(CacheError):
            _ = [hc for hc in confluence.fetch_from_cache()]
Exemple #3
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the contents from the server,
        # storing them in a cache
        cache = Cache(self.tmp_path)
        confluence = Confluence(CONFLUENCE_URL, cache=cache)

        hcs = [hc for hc in confluence.fetch()]
        self.assertEqual(len(http_requests), 6)

        # Now, we get the contents from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_hcs = [hc for hc in confluence.fetch_from_cache()]
        self.assertEqual(len(cached_hcs), len(hcs))

        expected = [('1', 1, '5b8bf26bfd906214ec82f5a682649e8f6fe87984', 1465589121.0),
                    ('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0),
                    ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0),
                    ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd', 1467831550.0)]

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

        for x in range(len(cached_hcs)):
            hc = cached_hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['updated_on'], expected[x][3])

        # No more requests were sent
        self.assertEqual(len(http_requests), 6)
    def test_fetch(self):
        """Test it it fetches and parses a list of contents"""

        http_requests = setup_http_server()

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch()]

        expected = [('1', 1, '5b8bf26bfd906214ec82f5a682649e8f6fe87984', 1465589121.0, 'historical content'),
                    ('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0, 'historical content'),
                    ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0, 'historical content'),
                    ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd', 1467831550.0, 'historical content')]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['updated_on'], expected[x][3])
            self.assertEqual(hc['category'], expected[x][4])

        # Check requests
        expected = [
                    {
                     'cql' : ["lastModified>='1970-01-01 00:00' order by lastModified"],
                     'limit' : ['200']
                    },
                    {
                     'cql' : ["lastModified>='1970-01-01 00:00' order by lastModified"],
                     'start' : ['2'],
                     'limit' : ['2'] # Hardcoded in JSON dataset
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['2']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    }
                   ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_fetch_from_empty_cache(self):
        """Test if there are not any content returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        confluence = Confluence(CONFLUENCE_URL, cache=cache)
        cached_hcs = [hc for hc in confluence.fetch_from_cache()]
        self.assertEqual(len(cached_hcs), 0)
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        confluence = Confluence(CONFLUENCE_URL)

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

        cache = Cache(self.tmp_path)
        confluence = Confluence(CONFLUENCE_URL, cache=cache)
        cached_hcs = [hc for hc in confluence.fetch_from_cache()]
        self.assertEqual(len(cached_hcs), 0)
    def test_fetch_removed_content(self):
        """Test if the method works when a content is not found"""

        http_requests = setup_http_server()

        # Set server to return a 404 error
        httpretty.register_uri(httpretty.GET,
                               CONFLUENCE_HISTORICAL_CONTENT_1,
                               status=404, body="Mock 404 error")

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch()]

        expected = [('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0),
                    ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd', 1467831550.0)]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['origin'], CONFLUENCE_URL)
            self.assertEqual(hc['updated_on'], expected[x][3])
            self.assertEqual(hc['category'], 'historical content')
            self.assertEqual(hc['tag'], CONFLUENCE_URL)

        # Check requests
        expected = [
                    {
                     'cql' : ["lastModified>='1970-01-01 00:00' order by lastModified"],
                     'limit' : ['200']
                    },
                    {
                     'cql' : ["lastModified>='1970-01-01 00:00' order by lastModified"],
                     'start' : ['2'],
                     'limit' : ['2'] # Hardcoded in JSON dataset
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    }
                   ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_initialization(self):
        """Test whether attributes are initializated"""

        confluence = Confluence(CONFLUENCE_URL, origin='test')

        self.assertEqual(confluence.url, CONFLUENCE_URL)
        self.assertEqual(confluence.origin, 'test')
        self.assertIsInstance(confluence.client, ConfluenceClient)

        # When origin is empty or None it will be set to
        # the value in url
        confluence = Confluence(CONFLUENCE_URL)
        self.assertEqual(confluence.url, CONFLUENCE_URL)
        self.assertEqual(confluence.url, CONFLUENCE_URL)

        confluence = Confluence(CONFLUENCE_URL, origin='')
        self.assertEqual(confluence.url, CONFLUENCE_URL)
        self.assertEqual(confluence.url, CONFLUENCE_URL)
    def test_parse_contents_summary(self):
        """Test if it parses a contents summary stream"""

        raw_contents = read_file('data/confluence_contents.json')

        contents = Confluence.parse_contents_summary(raw_contents)
        results = [content for content in contents]

        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['id'], '1')
        self.assertEqual(results[1]['id'], '2')

        # Parse a file without results
        raw_contents = read_file('data/confluence_contents_empty.json')

        contents = Confluence.parse_contents_summary(raw_contents)
        results = [content for content in contents]

        self.assertEqual(len(results), 0)
    def test_parse_contents_summary(self):
        """Test if it parses a contents summary stream"""

        raw_contents = read_file('data/confluence_contents.json')

        contents = Confluence.parse_contents_summary(raw_contents)
        results = [content for content in contents]

        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['id'], '1')
        self.assertEqual(results[1]['id'], '2')

        # Parse a file without results
        raw_contents = read_file('data/confluence_contents_empty.json')

        contents = Confluence.parse_contents_summary(raw_contents)
        results = [content for content in contents]

        self.assertEqual(len(results), 0)
    def test_parse_historical_content(self):
        """Test if it parses a historical content stream"""

        raw_hc = read_file('data/confluence_content_1_v1.json')
        hc = Confluence.parse_historical_content(raw_hc)

        self.assertEqual(hc['id'], '1')
        self.assertEqual(hc['history']['latest'], False)
        self.assertEqual(hc['version']['number'], 1)
        self.assertEqual(hc['version']['when'], '2016-06-10T20:05:21.000Z')
    def test_parse_historical_content(self):
        """Test if it parses a historical content stream"""

        raw_hc = read_file('data/confluence_content_1_v1.json')
        hc = Confluence.parse_historical_content(raw_hc)

        self.assertEqual(hc['id'], '1')
        self.assertEqual(hc['history']['latest'], False)
        self.assertEqual(hc['version']['number'], 1)
        self.assertEqual(hc['version']['when'], '2016-06-10T20:05:21.000Z')
    def test_fetch_empty(self):
        """Test if nothing is returnerd when there are no contents"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 7, 8, 0, 0, 0)

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch(from_date=from_date)]

        self.assertEqual(len(hcs), 0)

        # Check requests
        expected = {
                    'cql' : ["lastModified>='2016-07-08 00:00' order by lastModified"],
                    'limit' : ['200']
                   }

        self.assertEqual(len(http_requests), 1)
        self.assertDictEqual(http_requests[0].querystring, expected)
    def test_fetch_empty(self):
        """Test if nothing is returnerd when there are no contents"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 7, 8, 0, 0, 0)

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch(from_date=from_date)]

        self.assertEqual(len(hcs), 0)

        # Check requests
        expected = {
            'cql': ["lastModified>='2016-07-08 00:00' order by lastModified"],
            'limit': ['200']
        }

        self.assertEqual(len(http_requests), 1)
        self.assertDictEqual(http_requests[0].querystring, expected)
Exemple #16
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the contents from the server,
        # storing them in a cache
        cache = Cache(self.tmp_path)
        confluence = Confluence(CONFLUENCE_URL, cache=cache)

        hcs = [hc for hc in confluence.fetch()]
        self.assertEqual(len(http_requests), 6)

        # Now, we get the contents from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_hcs = [hc for hc in confluence.fetch_from_cache()]
        self.assertEqual(len(cached_hcs), len(hcs))

        expected = [
            ('1', 1, '5b8bf26bfd906214ec82f5a682649e8f6fe87984', 1465589121.0),
            ('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0),
            ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0),
            ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd',
             1467831550.0)
        ]

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

        for x in range(len(cached_hcs)):
            hc = cached_hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['origin'], CONFLUENCE_URL)
            self.assertEqual(hc['updated_on'], expected[x][3])
            self.assertEqual(hc['category'], 'historical content')
            self.assertEqual(hc['tag'], CONFLUENCE_URL)

        # No more requests were sent
        self.assertEqual(len(http_requests), 6)
    def test_fetch(self):
        """Test it it fetches and parses a list of contents"""

        http_requests = setup_http_server()

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch()]

        expected = [
            ('1', 1, '5b8bf26bfd906214ec82f5a682649e8f6fe87984', 1465589121.0),
            ('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0),
            ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0),
            ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd',
             1467831550.0)
        ]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['updated_on'], expected[x][3])

        # Check requests
        expected = [
            {
                'cql':
                ["lastModified>='1970-01-01 00:00' order by lastModified"],
                'limit': ['200']
            },
            {
                'cql':
                ["lastModified>='1970-01-01 00:00' order by lastModified"],
                'start': ['2'],
                'limit': ['2']  # Hardcoded in JSON dataset
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['2']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            }
        ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_fetch_from_date(self):
        """Test if a list of contents is returned from a given date"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 6, 16, 0, 0, 0)

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch(from_date=from_date)]

        # On this test case the first version of content #1
        # will not be returned becasue this version was
        # created before the given date
        expected = [('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0, 'historical content'),
                    ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0, 'historical content'),
                    ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd', 1467831550.0, 'historical content')]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['updated_on'], expected[x][3])
            self.assertEqual(hc['category'], expected[x][4])

        # Check requests
        expected = [
                    {
                     'cql' : ["lastModified>='2016-06-16 00:00' order by lastModified"],
                     'limit' : ['200']
                    },
                    { # Hardcoded in JSON dataset
                     'cql' : ["lastModified>='1970-01-01 00:00' order by lastModified"],
                     'start' : ['2'],
                     'limit' : ['2']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['2']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    },
                    {
                     'expand' : ['body.storage,history,version'],
                     'status' : ['historical'],
                     'version' : ['1']
                    }
                   ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_fetch_from_date(self):
        """Test if a list of contents is returned from a given date"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 6, 16, 0, 0, 0)

        confluence = Confluence(CONFLUENCE_URL)
        hcs = [hc for hc in confluence.fetch(from_date=from_date)]

        # On this test case the first version of content #1
        # will not be returned becasue this version was
        # created before the given date
        expected = [
            ('1', 2, '94b8015bcb52fca1155ecee14153c8634856f1bc', 1466107110.0),
            ('2', 1, 'eccc9b6c961f8753ee37fb8d077be80b9bea0976', 1467402626.0),
            ('att1', 1, 'ff21bba0b1968adcec2588e94ff42782330174dd',
             1467831550.0)
        ]

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

        for x in range(len(hcs)):
            hc = hcs[x]
            self.assertEqual(hc['data']['id'], expected[x][0])
            self.assertEqual(hc['data']['version']['number'], expected[x][1])
            self.assertEqual(hc['uuid'], expected[x][2])
            self.assertEqual(hc['updated_on'], expected[x][3])

        # Check requests
        expected = [
            {
                'cql':
                ["lastModified>='2016-06-16 00:00' order by lastModified"],
                'limit': ['200']
            },
            {  # Hardcoded in JSON dataset
                'cql':
                ["lastModified>='1970-01-01 00:00' order by lastModified"],
                'start': ['2'],
                'limit': ['2']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['2']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            },
            {
                'expand': ['body.storage,history,version'],
                'status': ['historical'],
                'version': ['1']
            }
        ]

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

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Confluence.has_resuming(), True)
Exemple #21
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Confluence.has_resuming(), True)