-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from S3-Platform-Inc/feature/55-the-badge-test
- Loading branch information
1 parent
6e6f029
commit c052a0b
Showing
4 changed files
with
97 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pathlib import Path | ||
|
||
import xml.etree.ElementTree as ET | ||
from s3p_sdk.types.manifest import Manifest | ||
|
||
import pytest | ||
|
||
|
||
ROOT_TAG: str = "project" | ||
PROJECT_NAME_TAG: str = "name" | ||
PROJECT_VERSION_TAG: str = "version" | ||
XML_FILENAME: str = "plugin.xml" | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def fix_plugin_root_config_path() -> Path: | ||
return Path(__file__).parent.parent.parent / XML_FILENAME | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def fix_plugin_manifest(fix_plugin_root_config_path) -> Manifest: | ||
tree = ET.parse(str(fix_plugin_root_config_path)) | ||
_version = tree.getroot().find(PROJECT_VERSION_TAG).text | ||
_name = tree.getroot().attrib.get(PROJECT_NAME_TAG) | ||
return Manifest( | ||
version=_version, | ||
plugin_name=_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
from tests.fixtures.plugin_manifest import fix_plugin_manifest, fix_plugin_root_config_path | ||
import pytest | ||
|
||
|
||
@pytest.mark.pre_set | ||
class TestPluginREADME: | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def readme_content(self) -> str: | ||
with open(Path(__file__).parent.parent / 'readme.md', 'r') as file: | ||
readme_content = file.read() | ||
return readme_content | ||
|
||
def test_badges_name(self, fix_plugin_manifest, readme_content): | ||
"""Проверка соответствие имен репозитория в ссылках на шильдики GitHub""" | ||
|
||
print(fix_plugin_manifest.plugin_name) | ||
badge_pattern = rf'\[\!\[.*?\]\(https://github\.com/S3-Platform-Inc/{fix_plugin_manifest.plugin_name.replace("_", "-")}/actions/workflows/.*?\.yml/badge\.svg\)\]' | ||
|
||
found_lines = re.findall(badge_pattern, readme_content, re.MULTILINE) | ||
assert len(found_lines) == 3, "Обновите readme.md файл. Укажите валидный url для GitHub Badges" | ||
|
||
def test_title(self, fix_plugin_manifest, readme_content): | ||
title_pattern = r'^# S3 Platform Plugin Template' | ||
|
||
matched = re.match(title_pattern, readme_content) | ||
|
||
if fix_plugin_manifest.plugin_name == "s3_platform_plugin_template": | ||
assert matched | ||
else: | ||
assert not matched, "Измените название плагина в readme.md файле" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import re | ||
|
||
import xml.etree.ElementTree as ET | ||
from tests.fixtures.plugin_manifest import fix_plugin_root_config_path, XML_FILENAME, ROOT_TAG, PROJECT_NAME_TAG, \ | ||
PROJECT_VERSION_TAG | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.pre_set | ||
class TestPluginRootFile: | ||
|
||
def test_check_plugin_xml_file(self, fix_plugin_root_config_path): | ||
"""Наличие главного файла плагина""" | ||
assert os.path.exists(str(fix_plugin_root_config_path)), f"S3P plugin должен содержать файл `{XML_FILENAME}` в корне репозитория" | ||
|
||
def test_check_plugin_xml_structure(self, fix_plugin_root_config_path): | ||
"""Проверяет структуру плагина""" | ||
tree = ET.parse(str(fix_plugin_root_config_path)) | ||
assert tree.getroot().tag == ROOT_TAG,\ | ||
f"Не найден тег `{ROOT_TAG}` в корне `{XML_FILENAME}`" | ||
assert tree.getroot().attrib.get(PROJECT_NAME_TAG), \ | ||
f"Не найдено поле `{PROJECT_NAME_TAG}` в теги `{ROOT_TAG}`" | ||
assert tree.getroot().find(PROJECT_VERSION_TAG).tag == PROJECT_VERSION_TAG,\ | ||
f"Не найден тег `{PROJECT_VERSION_TAG}` в теги `{ROOT_TAG}`" | ||
|
||
def test_format_version_check(self, fix_plugin_root_config_path): | ||
"""Проверяет формат версии плагина""" | ||
pattern = r'^(0*[1-9]\d*|0*\d+\.\d+)$' | ||
|
||
tree = ET.parse(str(fix_plugin_root_config_path)) | ||
_version = tree.getroot().find(PROJECT_VERSION_TAG).text | ||
assert re.match(pattern, _version), \ | ||
f"{_version} не соответствует шаблону версий. см. в документации" |
This file was deleted.
Oops, something went wrong.