Added unittest for publisher

This commit is contained in:
2021-01-23 21:23:51 +01:00
parent 4720eb5f09
commit 337365587a
16 changed files with 139 additions and 115 deletions

View File

@@ -5,8 +5,8 @@ from sh_edraft.hosting.application_host import ApplicationHost
from sh_edraft.hosting.base.application_base import ApplicationBase
from sh_edraft.logging.logger import Logger
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publishing.publisher import Publisher
from sh_edraft.publishing.base.publisher_base import PublisherBase
from sh_edraft.publish.publisher import Publisher
from sh_edraft.publish.base.publisher_base import PublisherBase
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase

View File

@@ -5,8 +5,8 @@ from sh_edraft.hosting.application_host import ApplicationHost
from sh_edraft.hosting.base.application_base import ApplicationBase
from sh_edraft.logging.logger import Logger
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publishing.publisher import Publisher
from sh_edraft.publishing.base.publisher_base import PublisherBase
from sh_edraft.publish.publisher import Publisher
from sh_edraft.publish.base.publisher_base import PublisherBase
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase

View File

@@ -2,8 +2,8 @@ import traceback
from typing import Optional
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.publishing.model.template import Template
from sh_edraft.publishing.model.publish_settings_name import PublishSettingsName
from sh_edraft.publish.model.template import Template
from sh_edraft.publish.model.publish_settings_name import PublishSettingsName
from sh_edraft.console.console import Console
from sh_edraft.console.model.foreground_color import ForegroundColor

View File

@@ -2,7 +2,7 @@ from typing import Optional
from sh_edraft.coding.model.version import Version
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
from sh_edraft.publishing.model.template_enum import TemplateEnum
from sh_edraft.publish.model.template_enum import TemplateEnum
class Template(ConfigurationModelBase):

View File

@@ -5,9 +5,9 @@ from string import Template as stringTemplate
from setuptools import sandbox
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publishing.base.publisher_base import PublisherBase
from sh_edraft.publishing.model.publish_settings_model import PublishSettings
from sh_edraft.publishing.model.template import Template
from sh_edraft.publish.base.publisher_base import PublisherBase
from sh_edraft.publish.model.publish_settings_model import PublishSettings
from sh_edraft.publish.model.template import Template
class Publisher(PublisherBase):
@@ -229,7 +229,7 @@ class Publisher(PublisherBase):
try:
if not os.path.isdir(output_path):
os.makedirs(output_path)
os.makedirs(output_path, exist_ok=True)
except Exception as e:
self._logger.error(__name__, f'Cannot create directories: {output_path}', e)

View File

@@ -16,48 +16,5 @@
"Port": "587",
"UserName": "dev-srv@sh-edraft.de",
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
},
"PublishSettings": {
"SourcePath": "../",
"DistPath": "../../dist",
"Templates": [
{
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "all",
"Description": "",
"LongDescription": "",
"CopyrightDate": "2020",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": ", see LICENSE for more details.",
"Title": "",
"Author": "Sven Heidemann",
"Version": {
"Major": 2020,
"Minor": 12,
"Micro": 9
}
},
{
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "sh_edraft",
"Description": "common python library",
"LongDescription": "Library to share common classes and models used at sh-edraft.de",
"CopyrightDate": "2020",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": ", see LICENSE for more details.",
"Title": "",
"Author": "Sven Heidemann",
"Version": {
"Major": 2020,
"Minor": 12,
"Micro": 9
}
}
],
"IncludedFiles": [],
"ExcludedFiles": [],
"TemplateEnding": "_template.txt"
}
}

View File

@@ -16,48 +16,5 @@
"Port": "587",
"UserName": "dev-srv@sh-edraft.de",
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
},
"PublishSettings": {
"SourcePath": "../",
"DistPath": "../../dist",
"Templates": [
{
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "all",
"Description": "",
"LongDescription": "",
"CopyrightDate": "2020",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": ", see LICENSE for more details.",
"Title": "",
"Author": "Sven Heidemann",
"Version": {
"Major": 2020,
"Minor": 12,
"Micro": 9
}
},
{
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "sh_edraft",
"Description": "common python library",
"LongDescription": "Library to share common classes and models used at sh-edraft.de",
"CopyrightDate": "2020",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": ", see LICENSE for more details.",
"Title": "",
"Author": "Sven Heidemann",
"Version": {
"Major": 2020,
"Minor": 12,
"Micro": 9
}
}
],
"IncludedFiles": [],
"ExcludedFiles": [],
"TemplateEnding": "_template.txt"
}
}

View File

@@ -6,17 +6,17 @@
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
},
"LoggingSettings": {
"Path": "../build/logs/",
"Path": "../../build_test/logs/",
"Filename": "log_$start_time.log",
"ConsoleLogLevel": "INFO",
"FileLogLevel": "TRACE"
},
"PublishSettings": {
"SourcePath": "./",
"DistPath": "../build/dist",
"DistPath": "../../build_test/dist",
"Templates": [
{
"TemplatePath": "../publish_templates/all_template.txt",
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "all",
"Description": "",
"LongDescription": "",
@@ -33,7 +33,7 @@
}
},
{
"TemplatePath": "../publish_templates/all_template.txt",
"TemplatePath": "../../publish_templates/all_template.txt",
"Name": "sh_edraft",
"Description": "common python library",
"LongDescription": "Library to share common classes and models used at sh-edraft.de",

View File

View File

@@ -0,0 +1,52 @@
import os
import unittest
from sh_edraft.console import Console
from sh_edraft.hosting import ApplicationHost
from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase
from sh_edraft.publish import Publisher
from sh_edraft.publish.base import PublisherBase
from sh_edraft.publish.model import PublishSettings
class PublisherTest(unittest.TestCase):
def setUp(self):
Console.disable()
self._app_host = ApplicationHost()
self._configuration = self._app_host.configuration
self._services = self._app_host.services
self._configuration.add_environment_variables('CPL_')
self._configuration.add_argument_variables()
self._configuration.add_json_file(f'build.json')
self._services.add_singleton(LoggerBase, Logger)
self._services.add_singleton(PublisherBase, Publisher)
self._publisher: Publisher = self._services.get_service(PublisherBase)
def test_include(self):
value = './test.py'
self._publisher.include(value)
self.assertTrue(value in self._publisher._publish_settings.included_files)
def test_exclude(self):
value = './test.py'
self._publisher.exclude(value)
self.assertTrue(value in self._publisher._publish_settings.excluded_files)
def test_create(self):
self._publisher.create()
self.assertTrue(os.path.isdir(self._configuration.get_configuration(PublishSettings).dist_path))
def test_build(self):
self._publisher.create()
self._publisher.build()
self.assertTrue(os.path.isdir(self._configuration.get_configuration(PublishSettings).dist_path))
def test_publish(self):
self._publisher.create()
self._publisher.build()
self._publisher.publish()
self.assertTrue(os.path.isdir(self._configuration.get_configuration(PublishSettings).dist_path))

24
src/tests/setup.py Normal file
View File

@@ -0,0 +1,24 @@
import setuptools
setuptools.setup(
name='sh_edraft_unittests',
version='2020.0.1',
packages=setuptools.find_packages(exclude=["tests*"]),
url='https://www.sh-edraft.de',
license='MIT',
author='Sven Heidemann',
author_email='edraft.sh@gmail.com',
include_package_data=True,
description='sh-edraft python common lib unittest',
python_requires='>=3.8',
install_requires=[
'discord.py',
'flask',
'mysql-connector',
'SQLAlchemy',
'termcolor',
'pyfiglet',
'tabulate',
'smtplib'
]
)