2020-10-22 13:39:55 +02:00
|
|
|
import requests
|
|
|
|
import responses
|
|
|
|
|
|
|
|
from zerver.lib.cache import cache_delete
|
|
|
|
from zerver.lib.github import InvalidPlatform, get_latest_github_release_download_link_for_platform
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
|
|
|
logger_string = "zerver.lib.github"
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-10-22 13:39:55 +02:00
|
|
|
class GitHubTestCase(ZulipTestCase):
|
|
|
|
@responses.activate
|
|
|
|
def test_get_latest_github_release_download_link_for_platform(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
responses.add(
|
|
|
|
responses.GET,
|
|
|
|
"https://api.github.com/repos/zulip/zulip-desktop/releases/latest",
|
|
|
|
json={"tag_name": "v5.4.3"},
|
|
|
|
status=200,
|
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
responses.add(
|
|
|
|
responses.HEAD,
|
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-Web-Setup-5.4.3.exe",
|
|
|
|
status=302,
|
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
self.assertEqual(
|
|
|
|
get_latest_github_release_download_link_for_platform("windows"),
|
2021-02-12 08:19:30 +01:00
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-Web-Setup-5.4.3.exe",
|
2020-10-22 13:39:55 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
responses.add(
|
|
|
|
responses.HEAD,
|
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-5.4.3-x86_64.AppImage",
|
|
|
|
status=302,
|
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
self.assertEqual(
|
|
|
|
get_latest_github_release_download_link_for_platform("linux"),
|
2021-02-12 08:19:30 +01:00
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-5.4.3-x86_64.AppImage",
|
2020-10-22 13:39:55 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
responses.add(
|
|
|
|
responses.HEAD,
|
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-5.4.3.dmg",
|
|
|
|
status=302,
|
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
self.assertEqual(
|
|
|
|
get_latest_github_release_download_link_for_platform("mac"),
|
2021-02-12 08:19:30 +01:00
|
|
|
"https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-5.4.3.dmg",
|
2020-10-22 13:39:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
api_url = "https://api.github.com/repos/zulip/zulip-desktop/releases/latest"
|
|
|
|
responses.replace(responses.GET, api_url, body=requests.RequestException())
|
|
|
|
cache_delete("download_link:windows")
|
2021-02-12 08:20:45 +01:00
|
|
|
with self.assertLogs(logger_string, level="ERROR") as error_log:
|
2020-10-22 13:39:55 +02:00
|
|
|
self.assertEqual(
|
|
|
|
get_latest_github_release_download_link_for_platform("windows"),
|
2021-02-12 08:19:30 +01:00
|
|
|
"https://github.com/zulip/zulip-desktop/releases/latest",
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
error_log.output,
|
|
|
|
[
|
2021-02-12 08:20:45 +01:00
|
|
|
f"ERROR:{logger_string}:Unable to fetch the latest release version from GitHub {api_url}"
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2020-10-22 13:39:55 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
responses.replace(
|
|
|
|
responses.GET,
|
|
|
|
"https://api.github.com/repos/zulip/zulip-desktop/releases/latest",
|
|
|
|
json={"tag_name": "5.4.4"},
|
|
|
|
status=200,
|
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
download_link = "https://github.com/zulip/zulip-desktop/releases/download/v5.4.4/Zulip-5.4.4-x86_64.AppImage"
|
|
|
|
responses.add(responses.HEAD, download_link, status=404)
|
|
|
|
cache_delete("download_link:linux")
|
2021-02-12 08:20:45 +01:00
|
|
|
with self.assertLogs(logger_string, level="ERROR") as error_log:
|
2020-10-22 13:39:55 +02:00
|
|
|
self.assertEqual(
|
|
|
|
get_latest_github_release_download_link_for_platform("linux"),
|
2021-02-12 08:19:30 +01:00
|
|
|
"https://github.com/zulip/zulip-desktop/releases/latest",
|
2020-10-22 13:39:55 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
|
|
|
error_log.output,
|
2021-02-12 08:20:45 +01:00
|
|
|
[f"ERROR:{logger_string}:App download link is broken {download_link}"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-10-22 13:39:55 +02:00
|
|
|
|
|
|
|
with self.assertRaises(InvalidPlatform):
|
|
|
|
get_latest_github_release_download_link_for_platform("plan9")
|