Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Fix most of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Dec 4, 2021
1 parent 2eaf3e9 commit 567665c
Show file tree
Hide file tree
Showing 51 changed files with 94 additions and 63 deletions.
30 changes: 15 additions & 15 deletions app/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,8 @@ def parse_metadata(ini: str):


def update():
repo_file = Gio.File.new_for_path(f"{config.settings.flatpak_user_dir}/repo")
repo = OSTree.Repo.new(repo_file)
repo.open(None)

status, summary, signatures = repo.remote_fetch_summary("flathub", None)
data = GLib.Variant.new_from_bytes(
GLib.VariantType.new(OSTree.SUMMARY_GVARIANT_STRING), summary, True
)

status_beta, summary_beta, signatures_beta = repo.remote_fetch_summary(
"flathub-beta", None
)
data_beta = GLib.Variant.new_from_bytes(
GLib.VariantType.new(OSTree.SUMMARY_GVARIANT_STRING), summary_beta, True
)
data = get_summary_data("flathub")
data_beta = get_summary_data("flathub-beta")

summary_dict, recently_updated_zset = parse_summary_data(data)
summary_dict_beta, recently_updated_beta_zset = parse_summary_data(data_beta)
Expand All @@ -120,6 +107,19 @@ def update():
return len(recently_updated_zset), len(recently_updated_beta_zset)


def get_summary_data(remote_name):
repo_file = Gio.File.new_for_path(f"{config.settings.flatpak_user_dir}/repo")
repo = OSTree.Repo.new(repo_file)
repo.open(None)

status, summary, signatures = repo.remote_fetch_summary(remote_name, None)
data = GLib.Variant.new_from_bytes(
GLib.VariantType.new(OSTree.SUMMARY_GVARIANT_STRING), summary, True
)

return data


def parse_summary_data(data):
summary_dict = defaultdict(lambda: {"arches": []})
recently_updated_zset = {}
Expand Down
6 changes: 3 additions & 3 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from . import config


def appstream2dict(reponame: str) -> dict[str, object]:
def appstream2dict(repo_name: str) -> dict[str, object]:
if config.settings.appstream_repos is not None:
appstream_path = os.path.join(
config.settings.appstream_repos,
reponame,
repo_name,
"appstream",
"x86_64",
"appstream.xml",
Expand All @@ -23,7 +23,7 @@ def appstream2dict(reponame: str) -> dict[str, object]:
appstream = file.read()
else:
appstream_url = (
f"https://hub.flathub.org/{reponame}/appstream/x86_64/appstream.xml.gz"
f"https://hub.flathub.org/{repo_name}/appstream/x86_64/appstream.xml.gz"
)
r = requests.get(appstream_url, stream=True)
appstream = gzip.decompress(r.raw.data)
Expand Down
2 changes: 1 addition & 1 deletion tests/appstream/beta-repo/appstream/x86_64/appstream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<name>Beta app</name>
<summary>A simple beta test app</summary>
<developer_name>Developer</developer_name>
<description>Developers, Developers, Developers, Developers</description>
<description><p>Developers, Developers, Developers, Developers</p></description>
<icon type="cached" height="64" width="64">com.only.in.beta.Repo.png</icon>
<icon type="cached" height="128" width="128">com.only.in.beta.Repo.png</icon>
<categories>
Expand Down
24 changes: 13 additions & 11 deletions tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def setup_module():

installation_path = os.path.join(workspace.name, "flatpak")
repo_path = os.path.join(installation_path, "repo")
beta_repo_path = os.path.join(installation_path, "beta-repo")

os.mkdir(installation_path)
os.environ["FLATPAK_USER_DIR"] = installation_path
Expand All @@ -50,12 +49,7 @@ def setup_module():
repo.create(OSTree.RepoMode.BARE, None)
remote_path = os.path.join(os.getcwd(), "tests/ostree/repo")
repo.remote_add("flathub", f"file://{remote_path}")

beta_file = Gio.File.new_for_path(beta_repo_path)
beta_repo = OSTree.Repo.new(beta_file)
beta_repo.create(OSTree.RepoMode.BARE, None)
beta_remote_path = os.path.join(os.getcwd(), "tests/ostree/beta-repo")
beta_repo.remote_add("flathub-beta", f"file://{beta_remote_path}")
repo.remote_add("flathub-beta", f"file://{remote_path}")

for i, test_stats_json in enumerate(
sorted(glob.glob("tests/stats/*.json"), reverse=True)
Expand Down Expand Up @@ -107,13 +101,17 @@ def test_appstream_by_appid():
def test_appstream_by_appid_stable_only():
response = client.get("/appstream/com.anydesk.Anydesk")
assert response.status_code == 200
assert response.json() == _get_expected_json_result("test_appstream_by_appid_stable_only")
assert response.json() == _get_expected_json_result(
"test_appstream_by_appid_stable_only"
)


def test_appstream_by_appid_beta_only():
response = client.get("/appstream/com.only.in.beta.Repo")
assert response.status_code == 200
assert response.json() == _get_expected_json_result("test_appstream_by_appid_beta_only")
assert response.json() == _get_expected_json_result(
"test_appstream_by_appid_beta_only"
)


def test_appstream_by_non_existent_appid():
Expand Down Expand Up @@ -265,13 +263,17 @@ def test_summary_by_appid():
def test_summary_by_appid_stable_only():
response = client.get("/summary/com.anydesk.Anydesk")
assert response.status_code == 200
assert response.json() == _get_expected_json_result("test_summary_by_appid_stable_only")
assert response.json() == _get_expected_json_result(
"test_summary_by_appid_stable_only"
)


def test_summary_by_appid_beta_only():
response = client.get("/summary/com.only.in.beta.Repo")
assert response.status_code == 200
assert response.json() == _get_expected_json_result("test_summary_by_appid_beta_only")
assert response.json() == _get_expected_json_result(
"test_summary_by_appid_beta_only"
)


def test_summary_by_non_existent_id():
Expand Down
Empty file removed tests/ostree/beta-repo/.lock
Empty file.
4 changes: 0 additions & 4 deletions tests/ostree/beta-repo/config

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/ostree/beta-repo/summary
Binary file not shown.
Binary file removed tests/ostree/beta-repo/summary.idx
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/results/test_appstream_by_appid.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stable": {
"beta": {
"description": "<p>Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.</p>",
"screenshots": [
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"sdk": "org.gnome.Sdk/x86_64/3.36"
}
},
"beta": {
"stable": {
"description": "<p>Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.</p>",
"screenshots": [
{
Expand Down Expand Up @@ -99,7 +99,7 @@
"type": "gettext"
},
"name": "Maze",
"summary": "A simple maze game, but this is the beta version",
"summary": "A simple maze game",
"developer_name": "Sugar Labs Community",
"categories": ["Game"],
"kudos": ["HiDpiIcon"],
Expand Down
12 changes: 8 additions & 4 deletions tests/results/test_appstream_by_appid_beta_only.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"beta": {
"description": "Developers, Developers, Developers, Developers",
"description": "<p>Developers, Developers, Developers, Developers</p>",
"screenshots": [
{
"624x351": "https://dl.flathub.org/repo/screenshots/com.only.in.beta.Repo-stable/624x351/com.only.in.beta.Repo-4308958995b5f213eac85c7053e01a33.png",
Expand Down Expand Up @@ -39,8 +39,12 @@
"name": "Beta app",
"summary": "A simple beta test app",
"developer_name": "Developer",
"categories": ["Game"],
"kudos": ["HiDpiIcon"],
"categories": [
"Game"
],
"kudos": [
"HiDpiIcon"
],
"project_license": "GPL-3.0-or-later",
"launchable": {
"value": "com.only.in.beta.Repo.desktop",
Expand All @@ -53,4 +57,4 @@
"sdk": "org.gnome.Sdk/x86_64/3.36"
}
}
}
}
48 changes: 39 additions & 9 deletions tests/results/test_appstream_by_appid_stable_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,50 @@
}
],
"content_rating": {
"type": "oars-1.1"
"drugs-alcohol": "none",
"drugs-narcotics": "none",
"drugs-tobacco": "none",
"language-discrimination": "none",
"language-humor": "none",
"language-profanity": "none",
"money-gambling": "none",
"money-purchasing": "none",
"sex-adultery": "none",
"sex-appearance": "none",
"sex-homosexuality": "none",
"sex-nudity": "none",
"sex-prostitution": "none",
"sex-themes": "none",
"social-audio": "none",
"social-chat": "intense",
"social-contacts": "none",
"social-info": "none",
"social-location": "none",
"type": "oars-1.1",
"violence-bloodshed": "none",
"violence-cartoon": "none",
"violence-desecration": "none",
"violence-fantasy": "none",
"violence-realistic": "none",
"violence-sexual": "none",
"violence-slavery": "none",
"violence-worship": "none"
},
"urls": {
"bugtracker": "https://github.com/flathub/com.anydesk.Anydesk/issues",
"homepage": "https://www.anydesk.com"
},
"icon": "https://lh3.googleusercontent.com/bpm79oQCS4VMwIG-jajHfpsIhsUodP5fHDa3V2cMXLiwkSscAAviezm9YlmSxgjkB-A=w128",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.anydesk.Anydesk.png",
"id": "com.anydesk.Anydesk",
"translation": {
"value": "com.anydesk.Anydesk",
"type": "gettext"
},
"name": "AnyDesk",
"summary": "Connect to a computer remotely",
"developer_name": "AnyDesk Software GmbH",
"categories": ["Network"],
"kudos": ["HiDpiIcon"],
"categories": [
"Network"
],
"kudos": [
"HiDpiIcon"
],
"project_license": "LicenseRef-proprietary",
"launchable": {
"value": "com.anydesk.Anydesk.desktop",
Expand All @@ -107,6 +134,9 @@
"type": "flatpak",
"runtime": "org.freedesktop.Platform/x86_64/20.08",
"sdk": "org.freedesktop.Sdk/x86_64/20.08"
},
"metadata": {
"X-Flatpak-Tags": "proprietary"
}
}
}
}
2 changes: 1 addition & 1 deletion tests/results/test_feed_by_new.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Flathub &#226;&#8364;&#8220; recently added applications</title><link>https://flathub.org/apps/collection/new</link><description>Applications recently published on Flathub</description><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><language>en</language><lastBuildDate>Wed, 27 Jan 2021 16:25:03 +0000</lastBuildDate><item><title>AnyDesk</title><link>https://flathub.org/apps/details/com.anydesk.Anydesk</link><description>&lt;img src="https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.anydesk.Anydesk.png"&gt;&lt;p&gt;Connect to a computer remotely&lt;/p&gt;&lt;p&gt;&lt;p&gt;AnyDesk ensures secure and reliable remote desktop connections for IT professionals and on-the-go individuals alike.&lt;/p&gt;&lt;p&gt;NOTE: This wrapper is not verified by, affiliated with, or supported by AnyDesk.&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: AnyDesk Software GmbH&lt;/li&gt;&lt;li&gt;Version: 6.0.1&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.anydesk.Anydesk-stable/624x351/com.anydesk.Anydesk-b8f4a58c33a1e1603bad8a835f244173.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:43:10 +0000</pubDate></item><item><title>WPS Office</title><link>https://flathub.org/apps/details/com.wps.Office</link><description>&lt;img src="https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png"&gt;&lt;p&gt;WPS Office Suite&lt;/p&gt;&lt;p&gt;&lt;p&gt;WPS Office including Writer, Presentation and Spreadsheets, is a powerful office suite, which is able to process word file, produce wonderful slides, and analyze data as well. It is deeply compatible with all of the latest Microsoft Office file formats. It can easily open and read the documents created with Microsoft Office.&lt;/p&gt;&lt;p&gt;NOTE: This wrapper is not verified by, affiliated with, or supported by Kingsoft Office Corporation&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: Kingsoft Office Corporation&lt;/li&gt;&lt;li&gt;Version: 11.1.0.9719&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-3f78a399034d6606d866e875e6938d51.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-32f9654272b966cb0be4a4cd14e8d072.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-f25c528d533cf5a62d3093a0d4656007.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:42:48 +0000</pubDate></item><item><title>Maze</title><link>https://flathub.org/apps/details/org.sugarlabs.Maze</link><description>&lt;img src="https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png"&gt;&lt;p&gt;A simple maze game&lt;/p&gt;&lt;p&gt;&lt;p&gt;Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: Sugar Labs Community&lt;/li&gt;&lt;li&gt;Version: 30&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-4308958995b5f213eac85c7053e01a33.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-0cf71487936dec29c5b092662909f125.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-5d288daae5069cde2ffe86ab4a9285a7.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:41:20 +0000</pubDate></item></channel></rss>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Flathub &#226;&#8364;&#8220; recently added applications</title><link>https://flathub.org/apps/collection/new</link><description>Applications recently published on Flathub</description><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><language>en</language><lastBuildDate>Wed, 27 Jan 2021 16:25:03 +0000</lastBuildDate><item><title>AnyDesk</title><link>https://flathub.org/apps/details/com.anydesk.Anydesk</link><description>&lt;img src="https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.anydesk.Anydesk.png"&gt;&lt;p&gt;Connect to a computer remotely&lt;/p&gt;&lt;p&gt;&lt;p&gt;AnyDesk ensures secure and reliable remote desktop connections for IT professionals and on-the-go individuals alike.&lt;/p&gt;&lt;p&gt;NOTE: This wrapper is not verified by, affiliated with, or supported by AnyDesk.&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: AnyDesk Software GmbH&lt;/li&gt;&lt;li&gt;Version: 6.0.1&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.anydesk.Anydesk-stable/624x351/com.anydesk.Anydesk-b8f4a58c33a1e1603bad8a835f244173.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:43:10 +0000</pubDate></item><item><title>WPS Office</title><link>https://flathub.org/apps/details/com.wps.Office</link><description>&lt;img src="https://www.wps.com/assets/mediahub/WPS-Office-Mobile.png"&gt;&lt;p&gt;WPS Office Suite&lt;/p&gt;&lt;p&gt;&lt;p&gt;WPS Office including Writer, Presentation and Spreadsheets, is a powerful office suite, which is able to process word file, produce wonderful slides, and analyze data as well. It is deeply compatible with all of the latest Microsoft Office file formats. It can easily open and read the documents created with Microsoft Office.&lt;/p&gt;&lt;p&gt;NOTE: This wrapper is not verified by, affiliated with, or supported by Kingsoft Office Corporation&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: Kingsoft Office Corporation&lt;/li&gt;&lt;li&gt;Version: 11.1.0.9719&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-3f78a399034d6606d866e875e6938d51.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-32f9654272b966cb0be4a4cd14e8d072.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/com.wps.Office-stable/624x351/com.wps.Office-f25c528d533cf5a62d3093a0d4656007.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:42:48 +0000</pubDate></item><item><title>Maze</title><link>https://flathub.org/apps/details/org.sugarlabs.Maze</link><description>&lt;img src="https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png"&gt;&lt;p&gt;A simple maze game&lt;/p&gt;&lt;p&gt;&lt;p&gt;Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.&lt;/p&gt;&lt;/p&gt;&lt;h3&gt;Additional information:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Developer: Sugar Labs Community&lt;/li&gt;&lt;li&gt;Version: 30&lt;/ul&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-4308958995b5f213eac85c7053e01a33.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-0cf71487936dec29c5b092662909f125.png"&gt;&lt;img src="https://dl.flathub.org/repo/screenshots/org.sugarlabs.Maze-stable/624x351/org.sugarlabs.Maze-5d288daae5069cde2ffe86ab4a9285a7.png"&gt;</description><pubDate>Mon, 18 Jan 2021 12:41:20 +0000</pubDate></item></channel></rss>
Loading

0 comments on commit 567665c

Please sign in to comment.