Skip to content

Commit

Permalink
Add catalog reader unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Oct 5, 2024
1 parent 99ab1cf commit 72b72b3
Show file tree
Hide file tree
Showing 4 changed files with 808 additions and 0 deletions.
127 changes: 127 additions & 0 deletions catalog_reader/pytest/unit/test_app_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import pytest

from catalog_reader.app import get_app_details, get_app_details_impl


QUESTION_CONTEXT = {
'nic_choices': [],
'gpus': {},
'timezones': {'Asia/Saigon': 'Asia/Saigon', 'Asia/Damascus': 'Asia/Damascus'},
'node_ip': '192.168.0.10',
'certificates': [],
'certificate_authorities': [],
'system.general.config': {'timezone': 'America/Los_Angeles'},
'schema': {'questions': []}
}


@pytest.mark.parametrize('item_path, options, items_data', [
(
'/mnt/mypool/ix-applications/catalogs/github_com_truenas_charts_git_master/charts/chia',
{'retrieve_versions': True},
{
'name': 'chia',
'categories': [],
'app_readme': None,
'location': '/mnt/mypool/ix-applications/catalogs/github_com_truenas_charts_git_master/charts/chia',
'healthy': True,
'healthy_error': None,
'home': None,
'last_update': None,
'versions': {},
'maintainers': [],
'latest_version': None,
'latest_app_version': None,
'latest_human_version': None,
'recommended': False,
'title': 'Chia',
'description': None,
'tags': [],
'screenshots': [],
'sources': [],
}
),
(
'/mnt/mypool/ix-applications/catalogs/github_com_truenas_charts_git_master/charts/chia',
{'retrieve_versions': False},
{
'name': 'chia',
'categories': [],
'app_readme': None,
'location': '/mnt/mypool/ix-applications/catalogs/github_com_truenas_charts_git_master/charts/chia',
'healthy': True,
'healthy_error': None,
'home': None,
'last_update': None,
'maintainers': [],
'latest_version': None,
'latest_app_version': None,
'latest_human_version': None,
'recommended': False,
'title': 'Chia',
'description': None,
'tags': [],
'screenshots': [],
'sources': [],
}
)
])
def test_get_app_details(mocker, item_path, options, items_data):
mocker.patch('catalog_reader.app.validate_catalog_item', return_value=None)
mocker.patch('catalog_reader.app.get_app_details_impl', return_value={})
assert get_app_details(item_path, QUESTION_CONTEXT, options) == items_data


@pytest.mark.parametrize('item_path,schema,options,expected_data,open_yaml', [
(
'/mnt/mypool/ix-applications/catalogs/github_com_truenas_charts_git_master/charts/chia',
'charts.chia',
{'retrieve_latest_version': True},
{
'categories': ['storage', 'crypto'],
'icon_url': 'https://www.chia.net/wp-content/uploads/2022/09/chia-logo.svg',
'screenshots': ['https://www.chia.net/wp-content/uploads/2022/09/chia-logo.svg'],
'tags': ['finance'],
'versions': {
'1.3.37': {
'healthy': True,
'supported': True,
'healthy_error': None,
'location': '/mnt/mypool/ix-applications/catalogs/'
'github_com_truenas_charts_git_master/charts/chia/1.3.37',
'last_update': None,
'required_features': [],
'human_version': '1.3.37',
'version': '1.3.37',
'app_metadata': None,
'schema': None,
'readme': None,
'changelog': None
}
},
'sources': ['https://hub.docker.com/r/emby/embyserver']
},
'''
screenshots:
- 'https://www.chia.net/wp-content/uploads/2022/09/chia-logo.svg'
tags:
- finance
categories:
- storage
- crypto
icon_url: https://www.chia.net/wp-content/uploads/2022/09/chia-logo.svg
sources:
- https://hub.docker.com/r/emby/embyserver
'''
),
])
def test_get_item_details_impl(
mocker, item_path, schema, options, expected_data, open_yaml,
):
open_file_data = mocker.mock_open(read_data=open_yaml)
mocker.patch('builtins.open', open_file_data)
mocker.patch('os.path.isdir', return_value=True)
mocker.patch('os.listdir', return_value=['1.3.37'])
mocker.patch('catalog_reader.app.validate_catalog_item_version', return_value=None)
mocker.patch('catalog_reader.app.validate_catalog_item', return_value={})
assert get_app_details_impl(item_path, schema, QUESTION_CONTEXT, options) == expected_data
Loading

0 comments on commit 72b72b3

Please sign in to comment.