示例#1
0
    def test_no_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=False)

        # Check result
        self.assertListEqual(
            releases,
            [
                (
                    Version("2.7.8"),
                    "https://github.com/nautobot/nautobot/releases/tag/v2.7.8",
                ),
                (
                    Version("2.5.9"),
                    "https://github.com/nautobot/nautobot/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"},
            proxies=settings.HTTP_PROXIES,
        )

        # 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"},
            proxies=settings.HTTP_PROXIES,
        )

        # 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_no_pre_releases(self, mock_cache_get: Mock, mock_cache_set: Mock,
                             mock_request_get: Mock):
        mock_cache_get.side_effect = CacheMiss()
        mock_request_get.side_effect = successful_github_response

        releases = get_releases(pre_releases=False)

        # Check result
        self.assertListEqual(
            releases,
            [
                (
                    "2.7.8",
                    "https://github.com/nautobot/nautobot/releases/tag/v2.7.8",
                ),
                (
                    "2.5.9",
                    "https://github.com/nautobot/nautobot/releases/tag/v2.5.9",
                ),
            ],
        )

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

        # Check if result is put in cache
        expected_version_str, expected_url = max(releases)
        expected_version = version.parse(expected_version_str)
        mock_cache_set.assert_called_once_with(
            "latest_release", (expected_version, expected_url), 160876)
示例#4
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()