예제 #1
0
    def test_pre_releases(self, dummy_cache_get: Mock, dummy_cache_set: Mock, dummy_request_get: Mock):
        dummy_cache_get.side_effect = CacheMiss()
        dummy_request_get.side_effect = successful_github_response

        releases = get_releases(pre_releases=True)

        # Check result
        self.assertListEqual(releases, [
            (Version('2.7.8'), 'https://github.com/netbox-community/netbox/releases/tag/v2.7.8'),
            (Version('2.6b1'), 'https://github.com/netbox-community/netbox/releases/tag/v2.6-beta1'),
            (Version('2.5.9'), 'https://github.com/netbox-community/netbox/releases/tag/v2.5.9')
        ])

        # Check if correct request is made
        dummy_request_get.assert_called_once_with(
            'https://localhost/unittest/releases',
            headers={'Accept': 'application/vnd.github.v3+json'}
        )

        # Check if result is put in cache
        dummy_cache_set.assert_called_once_with(
            'latest_release',
            max(releases),
            160876
        )
예제 #2
0
    def test_failed_request(self, dummy_cache_get: Mock, dummy_cache_set: Mock, dummy_request_get: Mock):
        dummy_cache_get.side_effect = CacheMiss()
        dummy_request_get.side_effect = unsuccessful_github_response

        with self.assertLogs(level=ERROR) as cm:
            releases = get_releases()

        # Check log entry
        self.assertEqual(len(cm.output), 1)
        log_output = cm.output[0]
        last_log_line = log_output.split('\n')[-1]
        self.assertRegex(last_log_line, '404 .* Not Found')

        # Check result
        self.assertListEqual(releases, [])

        # Check if correct request is made
        dummy_request_get.assert_called_once_with(
            'https://localhost/unittest/releases',
            headers={'Accept': 'application/vnd.github.v3+json'}
        )

        # Check if failure is put in cache
        dummy_cache_set.assert_called_once_with(
            'latest_release_no_retry',
            'https://localhost/unittest/releases',
            900
        )
예제 #3
0
    def test_blocked_retry(self, dummy_cache_get: Mock, dummy_cache_set: Mock, dummy_request_get: Mock):
        dummy_cache_get.return_value = 'https://localhost/unittest/releases'
        dummy_request_get.side_effect = successful_github_response

        releases = get_releases()

        # Check result
        self.assertListEqual(releases, [])

        # Check if request is NOT made
        dummy_request_get.assert_not_called()

        # Check if cache is not updated
        dummy_cache_set.assert_not_called()