Added unittest for publisher

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

View File

@ -12,6 +12,7 @@
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/src/tests/old" />
<excludeFolder url="file://$MODULE_DIR$/.vscode" />
<excludeFolder url="file://$MODULE_DIR$/build_test" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />

View File

@ -22,8 +22,30 @@
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Bugfixes and improved tests">
<list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Removed unused packages">
<change afterPath="$PROJECT_DIR$/src/tests/publish_test/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/tests/publish_test/publisher_test.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/tests/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sh_common_py_lib.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sh_common_py_lib.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/commands/build/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/commands/build/app.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/commands/publish/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/commands/publish/app.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/base/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/base/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/base/publisher_base.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/base/publisher_base.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/model/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/model/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/model/publish_settings_model.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/model/publish_settings_model.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/model/publish_settings_name.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/model/publish_settings_name.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/model/template.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/model/template.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/model/template_enum.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/model/template_enum.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/sh_edraft/publishing/publisher.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/sh_edraft/publish/publisher.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/appsettings.edrafts-lapi.json" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/appsettings.edrafts-lapi.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/appsettings.edrafts-pc.json" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/appsettings.edrafts-pc.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/build.json" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/build.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/service_test/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/service_test/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/time_test/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/time_test/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tests/utils_test/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/tests/utils_test/__init__.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -33,8 +55,8 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Unit Test" />
<option value="Python Script" />
<option value="Python Unit Test" />
</list>
</option>
</component>
@ -62,7 +84,7 @@
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../sh_dobby" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/tests" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
@ -75,10 +97,10 @@
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/tests" />
<recent name="$PROJECT_DIR$/src/tests/publish_test" />
<recent name="$PROJECT_DIR$/src/tests/old" />
<recent name="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/commands/build" />
<recent name="$PROJECT_DIR$/src" />
<recent name="$PROJECT_DIR$/src/sh_edraft/cli/cpl_cli/model" />
</key>
</component>
<component name="RunManager" selected="Python tests.Unittests">
@ -446,13 +468,6 @@
<option name="presentableId" value="Default" />
<updated>1605881914521</updated>
</task>
<task id="LOCAL-00030" summary="Improved database connection">
<created>1606682897559</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1606682897559</updated>
</task>
<task id="LOCAL-00031" summary="Improved database module structure">
<created>1607285697331</created>
<option name="number" value="00031" />
@ -789,7 +804,14 @@
<option name="project" value="LOCAL" />
<updated>1608986131755</updated>
</task>
<option name="localTasksCounter" value="79" />
<task id="LOCAL-00079" summary="Removed unused packages">
<created>1611431001647</created>
<option name="number" value="00079" />
<option name="presentableId" value="LOCAL-00079" />
<option name="project" value="LOCAL" />
<updated>1611431001649</updated>
</task>
<option name="localTasksCounter" value="80" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -805,7 +827,6 @@
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Removed module template" />
<MESSAGE value="Added build command to cli" />
<MESSAGE value="Improved publish process" />
<MESSAGE value="Added publish command to cli" />
@ -830,6 +851,18 @@
<MESSAGE value="Bugfixes" />
<MESSAGE value="Improved tests" />
<MESSAGE value="Bugfixes and improved tests" />
<option name="LAST_COMMIT_MESSAGE" value="Bugfixes and improved tests" />
<MESSAGE value="Removed unused packages" />
<option name="LAST_COMMIT_MESSAGE" value="Removed unused packages" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/tests/publish_test/publisher_test.py</url>
<line>50</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

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'
]
)