Commit 5f43805a authored by Anton Palgunov's avatar Anton Palgunov

Add tests

parent 49388b80
......@@ -12,4 +12,5 @@
# meson
_build
subprojects/
\ No newline at end of file
subprojects/
__pycache__/
\ No newline at end of file
[pytest]
testpaths = src
markers =
smoke: mark test as smoke test
regression: mark test as regression test
\ No newline at end of file
......@@ -408,6 +408,8 @@ def load_data(split_view, force_refresh=False, page=1):
start_idx = (page - 1) * split_view._per_page
end_idx = start_idx + split_view._per_page
page_data = repos[start_idx:end_idx]
print(f"Page {page}: {len(page_data)} items")
# Если page_data меньше per_page, значит всё
if len(page_data) < split_view._per_page:
......
import pytest
import time
import sys
import os
from unittest.mock import patch, MagicMock
# Ensure the shop module is in the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from shop.main import retrieve_modules_full_list, load_from_cache, save_to_cache, fetch_repos_from_github, fetch_repos_from_gitlab
@patch("shop.main.load_from_cache")
@patch("shop.main.save_to_cache")
@patch("shop.main.fetch_repos_from_github")
@patch("shop.main.fetch_repos_from_gitlab")
@patch("time.time", return_value=1609459200) # Mock time to a fixed timestamp
def test_retrieve_modules_full_list(mock_time, mock_fetch_gitlab, mock_fetch_github, mock_save_cache, mock_load_cache):
# Mock cache data
mock_load_cache.return_value = (None, 0)
# Mock GitHub response
mock_fetch_github.return_value = [
{
"name": "tuneit-mod-example",
"owner": {"login": "example"},
"default_branch": "main",
"stargazers_count": 10,
"description": "Example description",
"html_url": "https://github.com/example/tuneit-mod-example",
"full_name": "example/tuneit-mod-example"
}
]
# Mock GitLab response
mock_fetch_gitlab.return_value = [
{
"name": "tuneit-mod-example",
"path_with_namespace": "example/tuneit-mod-example",
"default_branch": "main",
"star_count": 5,
"description": "Example description",
"web_url": "https://gitlab.com/example/tuneit-mod-example"
}
]
# Mock parse_module_yaml to return a dummy module info
with patch("shop.main.parse_module_yaml", return_value=[{"name": "Example Module", "description": "Example module description"}]):
repos = retrieve_modules_full_list(force_refresh=True, initial_page=1, per_page=30)
assert len(repos) == 2
assert repos[0]["source"] == "github"
assert repos[0]["repo_name"] == "tuneit-mod-example"
assert repos[0]["stars"] == 10
assert repos[0]["module_yaml"]["name"] == "Example Module"
assert repos[1]["source"] == "gitlab"
assert repos[1]["repo_name"] == "tuneit-mod-example"
assert repos[1]["stars"] == 5
assert repos[1]["module_yaml"]["name"] == "Example Module"
mock_save_cache.assert_called_once()
@patch("shop.main.load_from_cache")
@patch("time.time", return_value=1609459200) # Mock time to a fixed timestamp
def test_retrieve_modules_full_list_cache(mock_time, mock_load_cache):
# Mock cache data
mock_load_cache.return_value = ([{"repo_name": "cached-repo"}], 1609455600)
repos = retrieve_modules_full_list(force_refresh=False, initial_page=1, per_page=30)
assert len(repos) == 1
assert repos[0]["repo_name"] == "cached-repo"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment