Skip to content

Commit

Permalink
Merge pull request #56 from S3-Platform-Inc/feature/55-the-badge-test
Browse files Browse the repository at this point in the history
closes #55 feature(tests): added test for GitHub Badges in readme.md (#55)
  • Loading branch information
CuberHuber authored Jan 24, 2025
1 parent 6e6f029 commit c052a0b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 43 deletions.
28 changes: 28 additions & 0 deletions tests/fixtures/plugin_manifest.py
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,
)
34 changes: 34 additions & 0 deletions tests/test_plugin_readme.py
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 файле"
35 changes: 35 additions & 0 deletions tests/test_plugin_root_file.py
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} не соответствует шаблону версий. см. в документации"
43 changes: 0 additions & 43 deletions tests/test_plugin_root_files.py

This file was deleted.

0 comments on commit c052a0b

Please sign in to comment.